nemo_curator.stages.video.clipping.clip_extraction_stages

View as Markdown

Module Contents

Classes

NameDescription
ClipTranscodingStageStage that transcodes video clips into a standardized format.
FixedStrideExtractorStageStage that extracts video clips using fixed-length intervals.

API

class nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage(
num_cpus_per_worker: float = 6.0,
encoder: str = 'libx264',
encoder_threads: int = 1,
encode_batch_size: int = 16,
nb_streams_per_gpu: int = 3,
use_hwaccel: bool = False,
use_input_bit_rate: bool = False,
num_clips_per_chunk: int = 32,
ffmpeg_verbose: bool = False,
verbose: bool = False,
name: str = 'clip_transcoding'
)
Dataclass

Bases: ProcessingStage[VideoTask, VideoTask]

Stage that transcodes video clips into a standardized format.

This stage handles the conversion of video clips using FFmpeg, supporting both software (libx264, libopenh264) and hardware (NVENC) encoding with configurable parameters.

Parameters:

num_cpus_per_worker
floatDefaults to 6.0

Number of CPUs per worker.

encoder
strDefaults to 'libx264'

Video encoder to use.

encoder_threads
intDefaults to 1

Number of threads per encoder.

encode_batch_size
intDefaults to 16

Number of clips to encode in parallel.

nb_streams_per_gpu
intDefaults to 3

Number of streams per GPU.

use_hwaccel
boolDefaults to False

Whether to use hardware acceleration.

use_input_bit_rate
boolDefaults to False

Whether to use input video bit rate.

num_clips_per_chunk
intDefaults to 32

Number of clips per chunk. If the number of clips is larger than this, the clips will be split into chunks, and created VideoTasks for each chunk.

verbose
boolDefaults to False

Whether to print verbose logs.

ffmpeg_verbose
boolDefaults to False

Whether to print FFmpeg verbose logs.

encode_batch_size
int = 16
encoder
str = 'libx264'
encoder_threads
int = 1
ffmpeg_verbose
bool = False
name
str = 'clip_transcoding'
nb_streams_per_gpu
int = 3
num_clips_per_chunk
int = 32
num_cpus_per_worker
float = 6.0
use_hwaccel
bool = False
use_input_bit_rate
bool = False
verbose
bool = False
nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.__post_init__() -> None

Post-initialization method called after all fields are set.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_decoder_threads(
command: list[str]
) -> None

Add decoder thread options to command.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_hwaccel_options(
command: list[str]
) -> None

Add hardware acceleration options to command.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_input_options(
command: list[str],
clip: nemo_curator.tasks.video.Clip,
video_filename: str,
index: int
) -> None

Add input options to command.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_nvenc_options(
command: list[str],
force_pix_fmt: bool
) -> None

Add NVENC-specific encoding options.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_output_options(
command: list[str],
clip: nemo_curator.tasks.video.Clip,
index: int
) -> None

Add output options to command.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._add_video_encoding_options(
command: list[str],
use_bit_rate: str | None,
force_pix_fmt: bool
) -> None

Add video encoding options to command.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._build_ffmpeg_command(
video_filename: str,
clips: list[nemo_curator.tasks.video.Clip],
force_pix_fmt: bool,
use_bit_rate: str | None
) -> list[str]

Build the FFmpeg command for extracting clips.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._extract_clips(
working_dir: pathlib.Path,
video_filename: str,
force_pix_fmt: bool,
use_bit_rate: str | None,
clips: list[nemo_curator.tasks.video.Clip]
) -> None

Extract clips using FFmpeg.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._handle_ffmpeg_error(
error: subprocess.CalledProcessError,
command: list[str],
clips: list[nemo_curator.tasks.video.Clip]
) -> None

Handle FFmpeg command errors.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._read_clips_to_memory(
working_dir: pathlib.Path,
clips: list[nemo_curator.tasks.video.Clip]
) -> None

Read extracted clips back into memory.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage._run_ffmpeg_command(
command: list[str],
working_dir: pathlib.Path,
clips: list[nemo_curator.tasks.video.Clip]
) -> None

Run the FFmpeg command and handle errors.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.process(
task: nemo_curator.tasks.video.VideoTask
) -> nemo_curator.tasks.video.VideoTask
nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.ray_stage_spec() -> dict[str, typing.Any]

Ray stage specification for this stage.

nemo_curator.stages.video.clipping.clip_extraction_stages.ClipTranscodingStage.setup(
worker_metadata: nemo_curator.backends.base.WorkerMetadata | None = None
) -> None

Setup method called once before processing begins. Override this method to perform any initialization that should happen once per worker. Args: worker_metadata (WorkerMetadata, optional): Information about the worker (provided by some backends)

class nemo_curator.stages.video.clipping.clip_extraction_stages.FixedStrideExtractorStage(
clip_len_s: float,
clip_stride_s: float,
min_clip_length_s: float,
limit_clips: int,
verbose: bool = False,
name: str = 'fixed_stride_extractor'
)
Dataclass

Bases: ProcessingStage[VideoTask, VideoTask]

Stage that extracts video clips using fixed-length intervals.

This stage splits videos into clips of specified length and stride, ensuring each clip meets minimum length requirements and optionally limiting total clips.

clip_len_s
float
clip_stride_s
float
limit_clips
int
min_clip_length_s
float
name
str = 'fixed_stride_extractor'
verbose
bool = False
nemo_curator.stages.video.clipping.clip_extraction_stages.FixedStrideExtractorStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.video.clipping.clip_extraction_stages.FixedStrideExtractorStage.outputs() -> tuple[list[str], list[str]]
nemo_curator.stages.video.clipping.clip_extraction_stages.FixedStrideExtractorStage.process(
task: nemo_curator.tasks.video.VideoTask
) -> nemo_curator.tasks.video.VideoTask