Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the fastest and least resource consuming method for splitting an MP4 file?

I tried ffmpeg but got an error:

$ ffmpeg -vcodec copy -ss 0 -t 00:10:00 -i /home/asafche/Videos/myVideos/MAH00124.MP4 /home/asafche/Videos/myVideos/eh.mp4
FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5.1-1ubuntu1.1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Mar 31 2011 18:53:20, gcc: 4.4.3

Seems stream 0 codec frame rate differs from container frame rate: 119.88 (120000/1001) -> 59.94 (60000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/asafche/Videos/myVideos/MAH00124.MP4':
  Duration: 00:15:35.96, start: 0.000000, bitrate: 5664 kb/s
    Stream #0.0(und): Video: h264, yuv420p, 1280x720, 59.94 tbr, 59.94 tbn, 119.88 tbc
    Stream #0.1(und): Audio: aac, 48000 Hz, stereo, s16
Output #0, mp4, to '/home/asafche/Videos/myVideos/eh.mp4':
    Stream #0.0(und): Video: libx264, yuv420p, 1280x720, q=2-31, 90k tbn, 59.94 tbc
    Stream #0.1(und): Audio: 0x0000, 48000 Hz, stereo, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Unsupported codec for output stream #0.1

What am I doing wrong and how do I properly split an mp4 file?

share|improve this question
could you please tell us the reason you need to split the file? Is it to share, or play parts of the file? Or any other reason? – theTuxRacer Apr 17 '11 at 15:12
It is for uploading to youtube, therefore your second suggestion - play parts of the file... – Asaf Chertkoff Apr 17 '11 at 17:22
up vote 33 down vote accepted

With ffmpeg you can split file using the following command:

ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss START -t LENGTH OUTFILE.mp4

where START is starting positing in seconds or in format hh:mm:ss LENGTH is the chunk length in seconds or in format hh:mm:ss

So you will need to run this command few times depending on how long your video. If let's say your video is 31 minutes long and you want so split into 15 min chunks here is how you run it:

ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 0 -t 00:15:00 OUTFILE-1.mp4
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 00:15:00 -t 00:15:00 OUTFILE-2.mp4
ffmpeg -i ORIGINALFILE.mp4 -acodec copy -vcodec copy -ss 00:30:00 -t 00:15:00 OUTFILE-3.mp4

There is a python script that you can use that does this automatically(i.e. takes video file, chunk size in seconds and generates individual playable video files):

share|improve this answer
Thanks, but i need further help with this. Look for the edit i did in my answer. – Asaf Chertkoff Apr 18 '11 at 3:34
This worked for me: ffmpeg -ss 00:05:00 -t 00:16:00 -i largfile.MP4 -acodec copy -vcodec copy smallfile.MP4 can someone explain why? – Asaf Chertkoff Apr 18 '11 at 4:22
I am going to speculate here a bit, but it looks like your source file is encoded with framerate that libx264 does not support, so it skips frames. I think this should work fine, but there might be some mishaps with audio because of this. – Alex Apr 18 '11 at 18:14
maybe. will see... – Asaf Chertkoff Apr 18 '11 at 21:27
Asaf's command worked for me too. It would seem that the codec options should come after the inputfile. – daithib8 Jul 30 '11 at 15:02

Use mkvmerge from the mkvtoolnix package. Use something like

mkvmerge -o outputprefix --split 1G origfile.mp4

This would split your file in 1 GB blocks. You can use time-indications as well.

share|improve this answer

If this is an MP4 part 2, then with a very meticulous approach, you can proceed the file without encoder/decoder. This answer is intended for people with a programming background and an hex editor that want to keep the file ""intact"".

The first part of the file is a mdat, the second is a moov, containing metadata used by the decoder to locate chunks, which contain samples (encoded images and sound, not important to know). Then there are STCO, STTS, STSC, etc. This is called "atoms". They indicate what are the offset, length, etc, of each of the chunks. If you do a clean job, you can make several instances of your video, and different version with different chunks. The file will then be playable in players, and digested on video websites. If you're a coder, then build an MP4 parser or use an existing one to keep track of the parts and their offsets. That will help you to know more about the format, and to rebuild files automatically.

share|improve this answer

If you prefer using a gui there is avidemux available in the repositories. Defining the cut points is much easier this way !

The selection markers define the part of the video that will be exported, using "copy" in audio and video avoids reencoding. You can also choose the container or change it (avi, mp4, mkv, etc).

I've done a bunch of cuts on some videos from a camera and it was instantaneous !

share|improve this answer

Not sure what your need is, but you can type this in a terminal: To open a terminal, press Ctrl + Alt + T

split -b 4M file.mp4 part_file

This will split the files into chunks of 4 megabytes. TO recreate the file again, type

cat part_file[a-c] > file.mp4

Notice that i have typed a-cin the bracket, because the split created 3 files. in your case you might have to see more. I will explain with an example.

$ ls -lh
-rwxr-xr-x 1 root        root        9.3M 2011-04-17 20:09 file.mp4

This shows that I have a single file, of 9.3 MB. To split, I type:

$ split -b 2M file.mp4 part_file

After splitting, I get the files as:

$ ls -lh
-rwxr-xr-x 1 root        root        9.3M 2011-04-17 20:09 file.mp4
-rw-r--r-- 1 thetuxracer thetuxracer 2.0M 2011-04-17 20:12 part_fileaa
-rw-r--r-- 1 thetuxracer thetuxracer 2.0M 2011-04-17 20:12 part_fileab
-rw-r--r-- 1 thetuxracer thetuxracer 2.0M 2011-04-17 20:12 part_fileac
-rw-r--r-- 1 thetuxracer thetuxracer 2.0M 2011-04-17 20:12 part_filead
-rw-r--r-- 1 thetuxracer thetuxracer 1.3M 2011-04-17 20:12 part_fileae

Notice the two characters appended to the filename.

To get the file back:

$ cat part_filename[start-end][start-end] > file.mp4
share|improve this answer
This method will be very quick but won't allow you to play the individual chunks. You can use ffmpeg to extract parts of a video file but to split it automatically into many small chunks which are all individually playable without reassembling them into a whole you'll probably need to write a script with an mp4 file. I can give you an example if you like, but if its just to move the file around then this answer is good. – Slipstream Apr 17 '11 at 15:11
@Slipstream - you got it right - i need to split it for youtube. my camera is producing MP4 but i need to split those cause they are longer then the 15 min allowed. – Asaf Chertkoff Apr 17 '11 at 17:24
then you want alex's answer below... – Slipstream Apr 17 '11 at 22:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.