Skip to content

Commit ed2b9c1

Browse files
thomasdhcclaude
andcommitted
fix(video): guard ffmpeg call sites with shutil.which check
Signed-off-by: Dong Hyuk Chang <9426164+thomasdhc@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 09e4697 commit ed2b9c1

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

nemo_curator/stages/video/clipping/clip_extraction_stages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import copy
1616
import pathlib
17+
import shutil
1718
import subprocess
1819
import uuid
1920
from dataclasses import dataclass
@@ -73,6 +74,9 @@ def setup(self, worker_metadata: WorkerMetadata | None = None) -> None: # noqa:
7374
Args:
7475
worker_metadata (WorkerMetadata, optional): Information about the worker (provided by some backends)
7576
"""
77+
if not shutil.which("ffmpeg"):
78+
msg = "ClipTranscodingStage requires 'ffmpeg'. Install with: sudo apt-get install -y ffmpeg"
79+
raise RuntimeError(msg)
7680
if self.encoder not in {"libopenh264", "libx264", "h264_nvenc"}:
7781
error_msg = f"Expected encoder of `libopenh264`, `libx264`, or `h264_nvenc`. Got {self.encoder}"
7882
raise ValueError(error_msg)

nemo_curator/stages/video/clipping/video_frame_extraction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import shutil
1516
import subprocess
1617
from dataclasses import dataclass
1718
from pathlib import Path
@@ -38,6 +39,9 @@ def get_frames_from_ffmpeg(
3839
use_gpu: bool = False,
3940
) -> npt.NDArray[np.uint8] | None:
4041
"""Fetch resized frames for video."""
42+
if not shutil.which("ffmpeg"):
43+
msg = "get_frames_from_ffmpeg requires 'ffmpeg'. Install with: sudo apt-get install -y ffmpeg"
44+
raise RuntimeError(msg)
4145
if use_gpu:
4246
command = [
4347
"ffmpeg",

nemo_curator/utils/windowing_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import math
16+
import shutil
1617
import subprocess
1718
from dataclasses import dataclass
1819

@@ -138,6 +139,9 @@ def split_video_into_windows( # noqa: PLR0913
138139
index += count
139140

140141
if return_bytes:
142+
if not shutil.which("ffmpeg"):
143+
msg = "split_video_into_windows with return_bytes=True requires 'ffmpeg'. Install with: sudo apt-get install -y ffmpeg"
144+
raise RuntimeError(msg)
141145
if len(windows) == 1:
142146
return [mp4_bytes], video_frames, windows
143147

0 commit comments

Comments
 (0)