FFmpeg: Splitting media files into smaller segments

Splitting media files into smaller segments using FFmpeg can be incredibly useful for content creators across both video and audio formats. This functionality facilitates the creation of shorter clips for social media sharing, teaser trailers or podcasts. By breaking down lengthy recordings into manageable segments, it simplifies the editing process and facilitates seamless sharing.

This capability provided by FFmpeg grants users the flexibility to manipulate and distribute media content in a more tailored and manageable manner.

The command provided below efficiently divides media files into 10-second chunks:

ffmpeg -i input.mp3 -c copy -map 0 -segment_time 10 -f segment output_%03d.mp3

-i input.mp3 specifies the input file.

-c copy tells FFmpeg to copy all streams from the input file without re-encoding them. This is fast and preserves the original quality of the streams.

-map 0 selects all streams from the input file.

-segment_time 10 sets the duration for each segment to 10 seconds.

-f segment specifies the format for the output segments.

output_%03d.mp3 specifies the pattern for the output files. The %03d is a placeholder for sequential numbering.

For MP3 files, the time stamp of each chunk resets automatically. However, for video files like mp4 or mkv, the time stamp requires manual resetting as follows:

ffmpeg -i input.mkv -c copy -map 0 -segment_time 10 -f segment -reset_timestamps 1 output_%03d.mkv

Please note: Despite specifying a fixed segment length, variations in output length can occur due to each segment starting with a keyframe.

More FFmpeg commands

asterix Written by:

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *