74

I have one large MP4 file. I am attempting to split it into smaller files.

ffmpeg -i largefile.mp4 -sameq -ss 00:00:00 -t 00:50:00 smallfile.mp4

I thought using -sameq would keep the same quality settings. However, I must not understand what that does.

I'm looking to keep the same quality (audio/video) and compression with the split files. However, this setting makes the split files much larger.

What flag(s) do I need to set to keep the same quality and attributes in the split files while maintaining the same quality to size ratio?

For instance if my original file is about 12 GB and is 1920x1080 with a bitrate of 10617kbps and a framerate of 23 frames/sec and 6 channel audio with 317kbps, I would like the split files to be the same only a third of this size (if i split it into three pieces).

Hennes
  • 64,768
  • 7
  • 111
  • 168
Chris Weber
  • 1,235
  • 2
  • 12
  • 12
  • 3
    FYI for anyone reading this: Don't use [`-sameq`, it doesn't mean "same quality"](https://ffmpeg.org/faq.html#Why-was-the-ffmpeg-_002dsameq-option-removed_003f-What-to-use-instead_003f). – Zaz May 11 '15 at 00:05

3 Answers3

126

If you want to just split the video without re-encoding it, use the copy codec for audio and video. Try this:

ffmpeg -ss 00:00:00 -t 00:50:00 -i largefile.mp4 -acodec copy \
-vcodec copy smallfile.mp4

Note that this only creates the first split. The next one can be done with a command starting with ffmpeg -ss 00:50:00.

This can be done with a single command:

ffmpeg -i largefile.mp4 -t 00:50:00 -c copy smallfile1.mp4 \
-ss 00:50:00 -c copy smallfile2.mp4

This will create smallfile1.mp4, ending at 50 minutes into the video of largefile.mp4, and smallfile2.mp4, starting at 50 minutes in and ending at the end of largefile.mp4.

Alex
  • 166
  • 13
fideli
  • 14,636
  • 2
  • 35
  • 44
  • 7
    Using this method on an mp4 file, I get the first two seconds of every created file as a frozen frame (the audio plays normally). Any known reason for this? – Ron Harlev Nov 17 '15 at 18:31
  • Sounds like a bug. Update to latest ffmpeg. – Robert Mar 22 '16 at 11:41
  • 1
    @Robert I've updated many times since 2010. Thanks. – fideli Mar 22 '16 at 14:36
  • 3
    @RonHarlev This is the currently expected behavior. Without re-encoding, you can only cut videos at "key frames". Frames in between key frames don't carry enough information on their own to build a complete image. See: https://trac.ffmpeg.org/wiki/Seeking#Seekingwhiledoingacodeccopy – Philip Thrasher May 23 '17 at 19:52
  • thumb up for the `copy` argument. After applied it the time is reduced from 2 mins to under 5 seconds~! – Franva Jan 03 '21 at 04:30
  • Hi All - I realise this question is now very old, but I found it while looking for a solution to extracting a section from a video, avoiding the blank video with sound issue mentioned above, so figured this might help others who come here too: I ended up running a command first to find all the KeyFrame points, then used those exact times to extract the video section I wanted. I can't seem to post an actual reply, and only a little comment like this, so will post in two parts. – Alan May 17 '21 at 04:30
  • 1
    Find the KeyFrames: ffprobe -select_streams v -skip_frame nokey -show_frames -show_entries frame=pkt_pts_time,pict_type /PathTo/SourceVideoFilename Extract a 60 second from 1 min in to 2 mins in (the times are from the output to the above command - all in seconds): ffmpeg -i inputfilename -ss 60.345678 -to 120.123456 -vcodec copy -acodec copy -scodec copy outputfilename Hope that helps someone else. Alan. – Alan May 17 '21 at 04:32
  • Sorry for the crappy formatting - I can't seem to work out how to format well in these little comment boxes. – Alan May 17 '21 at 04:33
13

An Alternate way of doing it is:

Create a 2-min clip, starting after 10 minutes:

ffmpeg -i input.mp4 -ss 00:10:00 -to 00:12:00 -c copy output.mp4
  • -i input file
  • -ss start time in seconds or in hh:mm:ss
  • -to end time in seconds or in hh:mm:ss
  • -c codec to use

The quality of the file stays the same because we use -c copy to copy the original audio + video streams to the output.

Reference, List of commonly used FFmpeg commands: DigitalFortress

Volker Siegel
  • 1,504
  • 11
  • 21
Niket Pathak
  • 279
  • 2
  • 5
1

This is not bad, but not 100% right, it creates a 2-min clip, starting after 10 minutes, but it will only copy the best steams, so it will only copy the best video, audio and subtitle stream:

ffmpeg -i input.mp4 -ss 00:10:00 -to 00:12:00 -c copy output.mp4

If you want to copy all streams, then add "-map 0", it basically selects the entire first input file:

ffmpeg -ss 00:10:00 -to 00:12:00 -i input.mp4 -map 0 -c copy output.mp4

You also should put -ss and -to before the input file.

Hatibovics
  • 61
  • 7