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 hh:mm:ss.ms, 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 subtitle1.srt -c:s copy -map 0:4 subtitle2.srt