How to split and demux a file with FFmpeg

If you have a large video or audio file and want to split it into several smaller files, you can use ffmpeg to obtain that goal. What you need are the start timecodes and the length of the segments you want to cut. You can tell ffmpeg the start position of a segment with the -ss option and the length of a segment with the -t option. Timecodes are of the form, i.e. 2:03:05.07. If no start position is given, the segment will start at the beginning of the original file, if no length option is given, the segment will end at the end of the original file. Use the -c copy option to make sure that all streams from the original files will be passed through to the segments.

In this example it is assumed you have a large video file called longmovie.mp4 which you want to split in segments from the beginning to 0:05:00, from 1:00:00 to 1:05:00 and from 1:30:00 to the end with all streams passed through. Here is the command that does it for you:

$ ffmpeg -i longmovie.mp4 -c copy -t 0:05:00 beginning.mp4 -c copy -ss 1:00:00 -t 0:05:00 middle.mp4 -c copy -ss 1:30:00 end.mp4

To extract a certain stream from a file, you also use the -c[:v|a|s] copy and additionally the -map <fileindex>:<streamindex> option for file and stream selection. In this example it is assumed you want to demultiplex the video file muxed.mp4 that contains a video stream, two audio streams and two subtitles which you want to store in separate files. You can use

$ ffmpeg -i muxed.mp4

to find out which stream has which index. After that, use the -map <fileindex>:<streamindex> option to address individual streams.

$ ffmpeg -i muxed.mp4 -c:v copy -map 0:0 video.m4v -c:a copy -map 0:1 audio1.m4a -c:a copy -map 0:2 audio2.m4a -c:s copy -map 0:3 -c:s copy -map 0:4

About h0nk3ym0nk3y

h0nk3ym0nk3y is one of the three LinuxM0nk3ys from Linux M0nk3ys @ WordPress Linux M0nk3ys @ YouTube Linux M0nk3ys @ Twitter

Posted on September 27, 2012, in Audio / Video and tagged , , , , . Bookmark the permalink. 1 Comment.

  1. aimkeepachieve

    You may also try iDealshare VideoGo which can split video or audio files without re-encoding and with the original video and audio quality.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: