View Full Version : Trying to extract 2 minutes at the beginning of an mkv
mikeggsm
11th September 2013, 16:25
ffmpeg -i input.mkv -ss 0:0:0 -to 0:2:0 -c copy -map 0 output.mkv
It works, but the video is static for the first 8 seconds, what's on the screen with MPC-HC is a keyframe from the 5 second mark, as if the keyframe at 00:00 was lost...
Any help?
Thanks.
Reino
11th September 2013, 22:11
No idea why FFMpeg is causing static video at the beginning, but why not use mkvmerge for such a thing?
mkvmerge.exe -o "output.mkv" "input.mkv" --split parts:00:00:00-00:02:00
mikeggsm
11th September 2013, 23:35
I've just downloaded mkvmerge and it works. Thanks !
But to do it with files in other containers, I'd like to know why ffmpeg produces this problem: the rest of the video that ffmpeg creates is fine, it's just the first 8 seconds, which is just one static image. That image is from 00:05, it seems to be the second keyframe: ffmpeg appears to discard the first keyframe at 00:00...
juGGaKNot
12th September 2013, 18:03
I use virtual dub with aac/ac3/mp4/mkv plugins + some crappy free programs with virtual dub like interface :
1.Free Video Dub ( stil beta, buggy ) - great for most files.
2.SolveigMM AVI Trimmer + MKV - great for mkv.
+ Free Video to MP3 Converter for the files that come out without audio.
That covers all files, Free Video Dub will most likely handle any file when done, love their programs.
Reino
12th September 2013, 20:39
Mkvmerge by default splits on key-frames (segment starts with a key-frame and ends before a key-frame), while ffmpeg splits on exact specified time, which is causing this issue. Apart from -force_key_frames, which is for generating key-frames when you encode the video, I haven't found any options to mimic mkvmerge's behaviour.
mikeggsm
13th September 2013, 05:13
juGGaKNot: thanks, mkvmerge does the job for now but if I need to split videos in other containers, I'll look at these programs.
CoRoNe: if I remove the start time (-ss 0:0:0) from the command line, ffmpeg starts at the beginning and the video is correct. But if I include -ss 0:0:0, which should mean exactly the same thing, the keyframe is lost and the first 8 seconds is a static image.
Really strange quirk (bug?) of ffmpeg... if you specify a start time, ffmpeg seems to only take into account the content immediately AFTER the given timestamp, but not the content AT the timestamp.
This is apparently in direct contradiction to what the documentation says: http://trac.ffmpeg.org/wiki/Seeking%20with%20FFmpeg
This will be done very slowly, frame by frame. The advantage is that you'll get the frame at the third minute
juGGaKNot
10th October 2013, 17:35
Mkvmerge by default splits on key-frames (segment starts with a key-frame and ends before a key-frame), while ffmpeg splits on exact specified time, which is causing this issue.
Also hit this problem
Doing a bitstream copy gives me a broken file?
If you use -ss with -c:v copy, the resulting bitstream might end up being choppy, not playable, or out of sync with the audio stream, since ffmpeg is forced to only use/split on i-frames.
My video has keyframes at 00:17 and 00:27
ffmpeg -ss 20 -t 50 -i -codec copy out.mp4~7 seconds corupted ( freeze screen, artefacts ), once it reaches the frame at 00:27 looks ok
ffmpeg -i -ss 20 -t 50 -codec copy out.mp4~7 seconds corupted ( black screen, only audio ), starts with the frame at 00:27
I think this is consistent with what i've read in the docs :
-ss before input = extra frames preserved ( but corupted in my case )
-ss after input = extra frames discarded ( black screen )
Is the problem that it cuts the video at the keyframe ( 00:27 ) but the audio gets cut at 00:20 ( so it shows those 7 seconds of audio with bad/no video ) ?
When i use mkvmerge 6.2.0 to cut the mp4 it goes to 00:27 and cuts 50 seconds starting from that point ( no artefacts, freaze frames etc )
ffmpeg starts at 00.20 but has video problems until it reaches the first keyrame at 00:27.
It's not a problem for me, i always edit the files in vegas before the final render but if someone just wanted to make some quick cuts the resulting file looks bad.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.