PDA

View Full Version : Regenerating keyframes?


Velocity 7
30th July 2003, 20:59
I'm just wondering, is it possible to regenerate keyframes in a file that's already been encoded? I don't want to have to recompress the file just to get the same keyframes, but rather have a program that parses an AVI or OGM XviD file, searches out which frames are good keyframes, then makes them as such.

If at all possible, is there a modified VirtualDub or something I can use that can do this as well? Re-creating keyframes when saving the file rather than having to re-compress to do the keyframe generation...(this of course means discarding the old keyframes as well, if they even exist)

EDIT: Suddenly this thread looks like it fits more in the VDub forum than it it does here, even if it's an XviD file I'm working on. Please move the thread.

toraneko
31st July 2003, 09:23
that could indeed be a useful tool in order to split video files, as VirtualDub (with "direct stream copy") has to start clips on key-frames.

the question is : can a P-frame or a B-frame be "compressed" as a key-frame without any loss (as any difference will produce a "ghost" effect until next key-frame) ?

crusty
31st July 2003, 10:43
I think recreating keyframes might be possible but would produce quite some quality loss for the resulting clip. It would also mean a change to the codec used, because Vdub in itself can't reencode anything without the proper codec. And a rekeying like this, even if it is possible, HAS to be supported by the codec, which it isn't right now.

toraneko
31st July 2003, 10:56
DivX, XviD and others are all (more or less) MPEG-4 compliant codecs. which means XviD decoders can decode DivX material and vis versa.
in the worst case, quality loss will only occure from the "new inserted key-frame" to the next (regular) key-frame.
we are not talking about "re-encoding" anything. in fact, it would be simplier to use a new little software which will have to
1°) copy the video stream from the beginning to the frame before "the pre-key-frame"
2°) insert a "P-frame/B-frame transmuted into key-frame"
3°) copy the video stream from the next frame to the end

PS : sorry for my bad BAD english...

sysKin
31st July 2003, 13:27
Originally posted by toraneko
1°) copy the video stream from the beginning to the frame before "the pre-key-frame"
2°) insert a "P-frame/B-frame transmuted into key-frame"
3°) copy the video stream from the next frame to the end
In theory, it would work and would result in what crusty said - visible quality loss until next I-frame.
In practice, problems start with b-frames: not only picture information (which can be re-created using i-frame to some extend) but also motion information (which is absent in i-frames) is used to decode them.
All b-frames before the transcoded p-frame would be lost (or broken).

Only a P-frame could be changed this way: b-frame could not, because that would break entire decoding order (next p-frame would suddenly get a new, different reference).

In my humble opinion it's better to encode correctly to begin with ;) but dev-api-3 does not support forced keyframes, I know :(

Radek

toraneko
31st July 2003, 13:47
that means GK doesn't do anything when I edit the "1st pass stats" file (with the "graph" and stuff) ?

Velocity 7
31st July 2003, 23:28
Okay, so perhaps it isn't as simple then; how about a modification to VirtualDub (aka VirtualDubMOD) that analyzes the motion information in the entire video to have keyframes reconstructed, then strip all keyframe information from the video and re-insert? Basically it's using a new "Save to AVI" command, except it would be "Save to AVI with new keyframes" and would only be enabled if "Direct Stream Copy" is checked.

Of course, in a case like this, this means that the same codec that was used for encoding needs to be present and available in order to accomplish something like this; VirtualDubMOD needs to be able to analyze all the information correctly and use the proper codec (e.g., XviD) to re-create the same type of keyframes, though in different positions.

I have absolutely no knowledge in P, B, and I-frame stuff, so hear me out. >_>