Log in

View Full Version : Joining two mkv's without re-encoding


skampy
13th February 2011, 14:07
I just discovered that after a 30 hour encode of a 1080p video, that there is a corrupt segment of video close to the beginning which last a few seconds. After that, there isn't a single thing wrong with the encode.

Without spending so much time re-encoding the whole thing, is there way I can just, say, re-encode the first few minutes of the whole video (obviously this time without the corrupt source file), then crop the original corrupt video at the point the newly encoded video ends?

I would obviously use the exact same x264 settings (with the same build) and the same resolution, so the keyframes were in the exact same positions as before. I assume keyframes would play a role in this..

Is there a way for mmg to splice/cut video at a precise frame/keyframe? I can't imagine using seconds or even milliseconds as a precise way to join two mkv's so that as the last frame of the new encode ends just before the next frame happens in a perfect sequence with perfect continuity. If I'm wrong on this count (bear in mind it's a 2h 34m video), please let me know why I am!

Just to summarise in a more technical and less verbose manner: Let's say I wanted to re-encode the first 5000 video frames with the same x264 settings as the original video, then cut the corrupt video at frame 5001, then join these two mkv's so the newly encoded video ends at frame 5000, and the split video then begins at frame 5001... is that possible?

Any help/advice on this would be very much appreciated... I don't particularly want to spend another 30+ hours encoding it again.

Cheers! :stupid::stupid:

sneaker_ger
13th February 2011, 15:45
Yes, mmg can do this. It will always cut at the nearest keyframe, so giving the time in milliseconds to cut offers sufficient precision.
You could first cut at the beginning, see were mmg decided to cut and then use x264's "--frames" option to make the new encode exactly as long as needed.

skampy
14th February 2011, 01:37
Thanks for your reply sneaker

OK, so now I have cut the corrupt beginning from the mkv at approx 2m 28s in, so now how do I find out exactly how many frames I need to encode? I need to be accurate to the exact frame, so the transition between the mkv's is seamless.. so to speak.

Obviously multiplying 148x23.976 would be inaccurate, and would like miss by a dozen or more frames. Is there any program out there that could tell me the exact number of frames in an mkv?

Cheers

sneaker_ger
14th February 2011, 03:02
mkvextract timecodes_v2 "input.mkv" 1:"output.txt"
then count the lines (that have a number in them)