Using ffmpeg to cut up mkv video
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
Solution 1:
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 inhh: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.