Log in

View Full Version : cutting at non keyframes?


yawnmoth
18th November 2002, 06:25
In Virtual Dub, if you want to cut in between two keyframes, you can't, unless you recompress that portion between the keyframes, and add more keyframes to that spot...

But couldn't Virtual Dub instead load the previous keyframe, and apply the changes each frame after that described, until you got to frame you wanted to cut at? Virtual Dub could then insert this "altered" frame into the point you wanted to cut at as a keyframe. The next frames up until the next keyframe would still work, I would think, because they only contain changes from the previous frame - not the previous keyframe. So as far as they're concerned, one key frame followed by no other frames would be the same as a key frame followed by two hundred frames.

ErMaC
27th November 2002, 11:36
The problem is much more complicated, actually.
First off, each codec would have to be handled totally differently. Second, the entire GOP would become unusable until you reencoded it with most codecs. Add in the possibility of b-frames and then things get REALLY ugly.
If you want to do something like this, export the whole segment starting at a keyframe to huffyuv, then reencode it as whatever codec you want, and use Append Segment to reattach it to the start of the rest of the video. That's what VDub would have to do internally to get it right, and that's probably way too complicated to do automatically (since you would need to select matching codecs and their options and such).

yawnmoth
29th November 2002, 01:28
Oh... so I guess if this suggestion were to be implemented, it would have to be done in the codec itself, then?

Also, I don't think b-frames would be such a problem... if you want to cut in between two keyframes, you could just build the image up frame by frame after the first keyframe until you get to the frame that you cut, and just replace that frame with a new keyframe. If the next frame after that was a b-frame, then how would it be any different than the next frame after a p-frame being a keyframe? If you're going foward, it would just be like a p-frame that makes changes to a keyframe, and if you're going back, that would simply be the last change before the frame was created from scratch, again, so to speak...

And yeah - I was aware you could do it the way you described, but... i think this way could be better :)

The Edge
29th November 2002, 11:19
Hey.
I was able to get around your problem somewhat.
AviUtl (download page)has an option to make a frame a keyframe without re-encoding the whole movie. A bit messy, but I was able to cut no problem.
As a downside, the audio just would not say in synch.

Edge

cweb
2nd December 2002, 10:53
I had a video-only clip (no sound) (avs file pointing to
an MPEG2 clip opened with dvd2avi) and I found that
you can cut at non-keyframes without problems. It helps that the source is an avs file (NOT an AVI file).

Zhnujm
2nd December 2002, 17:20
@cweb:
opening the file via avisynth would be the same as a complete recompress. try a direct stream copy with it. ;)

yawnmoth
2nd December 2002, 17:21
The way avs files seem to work, every frame is treated as a keyframe ;)

?¿öM¿?
3rd December 2002, 06:13
I'm reasonably sure that avisynth passes the video to the output as uncompressed video. As yawnmouth observed, this is similar to every frame being a key frame(or bitmap?). It means that it is not a good idea to use an avs file just to cut at the absolute perfect place in your movie as you will have to recompress again(like Zhnujm said). Basically your encoding the same movie twice with a lossy codec which will result in degradation of quality for the sake of a better split.
:)

Also, read the thread in the DivX5 forum at the top of page1 about GOPs, I, P, B frames, it will help you see why you can't simply cut compressed video with b-frames anywhere you want even if you do add keyframes. I am to lazy to go and get the link:p , soz.

cweb
3rd December 2002, 22:19
Originally posted by Zhnujm
@cweb:
opening the file via avisynth would be the same as a complete recompress. try a direct stream copy with it. ;)

No it would not work since the file is in MPEG2 format which vdub does not read directly (I use avisynth2 to read such files without problems).

?¿öM¿?
4th December 2002, 20:54
The vDub mod apparently opens mpeg2 directly, though.:D

http://forum.doom9.org/showthread.php?threadid=38992
The vDub mod thread^^^^^^

Zhnujm
4th December 2002, 21:54
Originally posted by cweb
No it would not work since the file is in MPEG2 format which vdub does not read directly (I use avisynth2 to read such files without problems).

what i wanted to say was that you will end up with an uncompressed avi file if you use avisynth + vdub + direct stream copy and so it would not be useful for only cutting the file.

?¿öM¿?
5th December 2002, 18:42
Yeh, you would end up with 2 2GB+ files or something silly like that with direct stream copy.
:)

cweb
11th December 2002, 09:47
Originally posted by Zhnujm
what i wanted to say was that you will end up with an uncompressed avi file if you use avisynth + vdub + direct stream copy and so it would not be useful for only cutting the file.

My source is always a satellite recording which is in MPEG2. Ok so I could read it directly in Virtualdub but since I want to produce an XviD encoded file this is not as useful to me (basically my XviD encodes are always: DVD2AVI / avisynth for deinterlacing and smoothing using Convolution3d because some transmissions really need it / virtualdub) - I don't want an MPEG2 (or uncompressed) clip basically. The only case when I 'split' the avisynth file up through virtualdub (video only) was to extract a part of a recording for use to create a fan music video as an experiment to see whether I could do it with just open source tools. The result was that there was no perceived quality loss in doing this, compared to encoding the whole recording. As somebody said, with an AVS file all frames are keyframes and this must be very useful. IMHO we should use these tools including vdub in the ways we find most useful and this might differ from person to person (especially since we are all doing different things etc). But all the advice here is helpful in any case.

Zhnujm
11th December 2002, 13:25
you really get me wrong, cweb. it was not my intention to say that your method is wrong or useless. its perfect for the case you descibed, in fact im also using dvd2avi/avisynth for my mpeg-2 captures. (btw, vdubmod also uses avisynth to open mpeg-2 files)

but in case of the thread starter who wants to cut an already compressed avi file without recompressing, avisynth wouldnt be helpful. thats all i wanted to say, nothing more. :)

bennyd
5th April 2003, 18:10
i think i have got around this problem, what i am doing id doing a fast recompress on the section between the place i want to cut and the next keyframe, then using drect stream copy for the rest of the file.

codename_46
5th April 2004, 06:55
I'm still trying to get this to work. I need to cut off the first 80 frames of an .avi but after the first keyframe the second doesn't occur til #192. Some details about the avi: encoded it using GKnot .27 and DivX 5.02. I did not use b frames.
I first tried the AviUtl mentioned but that things in chinese (a language I can't read :( ) Second I tried to use the method of a fast reencode. But I have yet to be able to get nandub to fast reencode the first 80 frames then direct stream copy the rest. It does one or the other on the whole avi. If someone could please post some detailed instructions on this I'd really appreciate it.
And lastly... anyone know of another, possibly better, method for cutting a movie between keyframes?
:confused: