pub(crate) fn split_into_segments(
path: impl AsRef<Path>,
segment_output_pattern: &str,
segmented_files_path: impl AsRef<Path>,
) -> Result<Vec<impl AsRef<Path>>>Expand description
Uses ffmpeg to split the source video file into several segments.
This function performs stream copying (not re-encoding) to split a large video into smaller time-based segments. It’s designed for parallel processing scenarios where multiple cores can work on different segments simultaneously. The segmentation preserves video quality while enabling parallel frame extraction.
§Arguments
path- Path to the source video file to be segmentedsegment_output_pattern- ffmpeg formatting pattern for output filenames (e.g., “output_%09d.mp4” createsoutput_000000001.mp4,output_000000002.mp4, etc.)segmented_files_pattern- glob pattern to find the created segment files
§Returns
Ok(Vec<PathBuf>)- Paths to all generated segment filesErr- If ffmpeg fails or file discovery encounters errors
§Examples
let segments = split_into_segments(
Path::new("input.mp4"),
"segments/output_%09d.mp4",
"segments/*.mp4",
)?;
assert!(!segments.is_empty());§ffmpeg Parameters Explained
-v quiet- Suppress most ffmpeg output-c copy- Stream copy (no re-encoding, very fast)-map 0- Copy all streams from input-segment_time- Target duration of each segment-f segment- Use segment muxer for splitting-reset_timestamps 1- Reset timestamps for each segment