20

I'm completely lost with ffmpeg I got an mkv of 4:33 duration and I'd like to cut out the end from 4:20

I tried different ways:

1) Does not cut at all

~ > ffmpeg -t 00:04:20 -acodec copy -vcodec copy -i output3.mkv output3-cut.mkv
FFmpeg version SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.9-0ubuntu0.10.04.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 Jun 12 2012 16:27:34, gcc: 4.4.3

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 15.00 (15/1)
Input #0, matroska, from 'output3.mkv':
  Duration: 00:04:34.00, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: msmpeg4v2, yuv420p, 1808x944, PAR 1:1 DAR 113:59, 15 tbr, 1k tbn, 1k tbc
    Stream #0.1: Audio: mp3, 22050 Hz, mono, s16
File 'output3-cut.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'output3-cut.mkv':
    Stream #0.0: Video: msmpeg4v2, yuv420p, 1808x944 [PAR 1:1 DAR 113:59], q=2-31, 90k tbn, 1k tbc
    Stream #0.1: Audio: libmp3lame, 22050 Hz, mono, s16
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 4109 fps=3864 q=-1.0 Lsize=   36017kB time=272.48 bitrate=1082.8kbits/s    
video:33503kB audio:2344kB global headers:0kB muxing overhead 0.477241%

2) Cuts to 4:25 if I specify 4m15s 4m05s 4m and other seconds after 4m, with the same resulting file size. It cuts to 3:25 regardless of seconds value if I specify 3m50s or 30msome values

~ > ffmpeg -t 4m20s -acodec copy -vcodec copy -i output3.mkv oFFmpeg version SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.9-0ubuntu0.10.04.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 Jun 12 2012 16:27:34, gcc: 4.4.3

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 15.00 (15/1)
Input #0, matroska, from 'output3.mkv':
  Duration: 00:04:34.00, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: msmpeg4v2, yuv420p, 1808x944, PAR 1:1 DAR 113:59, 15 tbr, 1k tbn, 1k tbc
    Stream #0.1: Audio: mp3, 22050 Hz, mono, s16
File 'output3-cut.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'output3-cut.mkv':
    Stream #0.0: Video: msmpeg4v2, yuv420p, 1808x944 [PAR 1:1 DAR 113:59], q=2-31, 90k tbn, 1k tbc
    Stream #0.1: Audio: libmp3lame, 22050 Hz, mono, s16
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 4001 fps=3570 q=-1.0 Lsize=   35240kB time=266.71 bitrate=1082.4kbits/s    
video:32781kB audio:2292kB global headers:0kB muxing overhead 0.475784%
utput3-cut.mkv

3) Works hard and long time and cuts exactly to 4:20 but makes a huge file, changing file size from 35Mb to 113Mb!!!

ffmpeg -i output3.mkv -ss 00:00:00 -t 00:04:20 -sameq output3-cut.mkv

What is the right way to cut an mkv file?

ps

I also tried mencoder but it damages an audio track

2
  • 1
    By the way, sameq does not mean "same quality". Just forget that this option exists and never use it again, please :)
    – slhck
    Sep 20, 2012 at 22:56
  • 1
    yes, it sounds just like same quality )
    – zuba
    Sep 21, 2012 at 0:45

1 Answer 1

26

In theory, this is enough:

ffmpeg -i output3.mkv -t 00:04:20 -c:v copy -c:a copy output-cut.mkv

Read as: Input MKV video, encode 4:20 minutes, copy audio and video bitstream and save them to output file.

If you have problems with synchronization, try re-encoding audio and video:

ffmpeg -i output3.mkv -t 00:04:20 -c:v libx264 -c:a libfaac output-cut.mkv

Of course, you can specify the video quality with -crf 23 and the audio quality with -b:a 192k, varying those parameters. Read our FFmpeg blog post for more info.


Here's what was wrong about your commands:

  • You're using a terribly outdated version of FFmpeg. Please compile it from source or download a precompiled binary from the homepage. This will reduce the possibility of running into bugs.

  • -acodec copy -vcodec copy can not come before the -i option. Anything before -i tells FFmpeg to decode the input video. There is no "copy decoder" – that doesn't make sense. The order of options is important here. -c:a copy and -c:v copy come after the input option and before the output.

  • -t 4m20s is the wrong syntax: The duration may be a number in seconds, or in hh:mm:ss[.xxx].

  • -t can't come before -i either.

  • -ss 00:00:00 is irrelevant, it would just tell FFmpeg to start from the beginning, which it always does.

8
  • 1
    I tried ffmpeg -i output3.mkv -t 00:04:20 -c:v copy -c:a copy output3-cut.mkv and got ffmpeg: unrecognized option '-c:v' Then ffmpeg -i output3.mkv -t 00:04:20 -vcodec copy -acodec copy output3-cut.mkv with no luck. It produced the file of the same size and duration. Then I tryed ffmpeg -i output3.mkv -t 00:04:20 -vcodec libx264 -acodec libfaac output3-cut.mkv (cause -c:v is unknown) and got Unknown encoder 'libfaac' I use ffmpeg SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.1 from deb repo. I guess I'd better compile it from sources.
    – zuba
    Sep 20, 2012 at 23:17
  • 2
    Thank you for the url! - I'm going to dive in ffmpeg compilation right now
    – zuba
    Sep 20, 2012 at 23:19
  • 1
    The c:v syntax isn't supported in older versions. AAC should be available through libfaac or libvo_aacenc.
    – slhck
    Sep 21, 2012 at 7:03
  • 1
    @LordNeckbeard I just learned that the Zeranoe builds obviously don't bundle libfaac (anymore?)
    – slhck
    Sep 21, 2012 at 17:58
  • 1
    So, I compiled ffmpeg. Here is the verson: git-2012-09-21-7bc7093 ``` built on Sep 21 2012 20:09:06 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) libavutil 51. 73.101 / 51. 73.101 libavcodec 54. 57.100 / 54. 57.100 libavformat 54. 27.101 / 54. 27.101 libavdevice 54. 2.101 / 54. 2.101 libavfilter 3. 16.106 / 3. 16.106 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 15.100 / 0. 15.100 libpostproc 52. 0.100 / 52. 0.100 ```
    – zuba
    Sep 23, 2012 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .