Printable Version of Topic
Click here to view this topic in its original format
Unofficial VirtualDub Support Forums > Advanced Video Processing > Cutting Movies Not In Keyframes


Posted by: itayf Nov 6 2010, 11:37 AM
Hello!

I have some videos encoded in XviD+MP3 that I would to cut part of them. I've heard that it is recommeded to cut only at keyframes.

* When I try to set the beginning of the cutting range NOT at a keyframe, VirtualDub does not allow it (it cuts at the nearset keyframe).
* When I try to set the end of the cuting range NOT at a keyframe, VirtualDub does allow it (it cuts where I decided).

1. Does it mean that cutting not at a keyframe is fine when it is the end of the cutting range (and the recommendation is only for the beginning of the cutting range)?
2. What can go wrong when not cutting at a key frame? (and is there a difference between beginning and end of the cutting range?)
3. I've already cut a few videos not at a keyframe, how can I check that nothing went wrong in them?

Thanks a lot,
Itay.

Posted by: dloneranger Nov 6 2010, 01:25 PM
Simplified, the video codecs like xvid use a system like this

Frame 1 - Save the whole picture (this is called a keyframe)
Frame 2 - Save only the changes between frame 1 and 2
Frame 3 - Save only the changes between frame 2 and 3
etc until it decide to do a new keyframe
Frame 300 - Save a new keyframe with the whole picture
Frame 301 - Save only the changes between frame 300 and 301
Frame 302 - Save only the changes between frame 301 and 302
etc, etc


So, if virtualdub is in direct stream copy mode, the only place you can start a cut on is a keyframe, because if you start anywhere else, you only have the changes from that point on, but no full picture to start with

You can cut the end off without problems, as if you've stopped at frame 100, you don't need the changes after that

Virtualdub won't let you start a cut on a frame that isn't a keyframe - when you try, it will backtrack to find the nearest keyframe before the start point you wanted
You won't get a problem with the video, but the newly saved file will include some frames at the beginning that you probably didn't want

The only way to cut at exact frames is to recompress the video
You can set virtualdub to only recompress the frames between the cut start and the next keyframe, and just copy the rest by using the smart rendering option
This only works if you can match the compression codec's settings with the source file's settings
(easy if the source is something you made, but can be tricky if you don't know the source file's settings)

Posted by: itayf Nov 6 2010, 03:32 PM
Thanks you dloneranger for your detailed response!

So I don't have to worry about ending the cutting range not at a keyframe.

About choosing beginning point not at a keyframe:
I do know the compression settings for the source video (I captured it myself), so I chose the same settings and I succeeded to get everything right (VD recompressed only till the next keyframe using smart rendering mode, great! biggrin.gif ).
What if I don't know the codec's settings? I tried to use different settings (for example, I changed the bitrate to see what happens) and I just got different quality until the next keyframe.
So it seems that I can just choose my own settings for the recompressed frames, eventhough they are different from the rest of the movie.
So is it really important to know the source file codec's settings or it is just enough to know what codec was used? (and then choose my own settings)

Thanks,
Itay.

Posted by: dloneranger Nov 6 2010, 05:22 PM
It's hard to say, it all depends on the codec used
Virtualdub asks the codec to see if the two match up, and the codec says yes/no

Some codecs are forgiving, some are stricter......

If they don't match, then the smart rendering fails, and it falls back to compressing all the frames
That takes more time + any degradation from recompressing

Best advice is get close to what you want, and then fiddle with the settings if it doesn't work

Posted by: itayf Nov 6 2010, 06:38 PM
In case I don't know the settings and guessing doesn't work (The codec says no..) can I do the following:

Let's say we have keyframe every 100 frames (0, 100, 200, 300, ...) and I want to cut from 150 to 4550.
I cut from 100 to 199 (direct copy, and save it as 1.avi), and I cut from 200 to 4550 (direct copy, and save it as 2.avi)
Then I cut 1.avi from 150 to 199 (full processing, compress the way I like, and save it as 1_new.avi).
Then I join 1_new.avi + 2.avi.
Will it work or is it kind of doing the same (and the codec will have say yes/no about the join, and if no VD will have to process and recompress everything)?


In http://www.livingasian.com/2007/07/virtualdub-fast-and-easy-way-to-cut-an-avi-file/ (using an old version of VD), the writer writes:
"you should split the file at the key frames. Have you ever watched a video where the audio was out of sync? I’ve seen videos where the audio was out of sync and then got progressively worse throughout the video. This is most likely caused by editing and not cutting at the key frames."

Is it true? That's what would happen if VD would let me begin a cut not at a keyframe? Does using current version of VD ensures things like that never happen?


Thanks,
Itay.

Posted by: dloneranger Nov 6 2010, 08:00 PM
QUOTE

Let's say we have keyframe every 100 frames (0, 100, 200, 300, ...) and I want to cut from 150 to 4550.
I cut from 100 to 199 (direct copy, and save it as 1.avi), and I cut from 200 to 4550 (direct copy, and save it as 2.avi)
Then I cut 1.avi from 150 to 199 (full processing, compress the way I like, and save it as 1_new.avi).
Then I join 1_new.avi + 2.avi.
Will it work or is it kind of doing the same (and the codec will have say yes/no about the join, and if no VD will have to process and recompress everything)?

It's the same kind of problem, you can only join them if they're similar enough

QUOTE
In http://www.livingasian.com/2007/07/virtualdub-fast-and-easy-way-to-cut-an-avi-file/ (using an old version of VD), the writer writes:
"you should split the file at the key frames.  Have you ever watched a video where the audio was out of sync? I’ve seen videos where the audio was out of sync and then got progressively worse throughout the video.  This is most likely caused by editing and not cutting at the key frames."

Keyframes don't really have anything to do with it
Audio sync can be destroyed for a few reasons
1) Audio is in chucks, each chunk lasts 'x' amount of time, and these chunks are not the same length as a video frame
When you cut a video the chances of the cut matching up exactly with the audio chunks at those positions is small
That'll slightly move the audio when joining again, as the audio might have started a bit before/afer the first frame, and end slightly before/after the last frame
2) Variable bit rate audio can get horribly out of sync when cutting
The most reliable of keeping sync is to resave the video with the audio set to uncompressed before any editing
(The bad point with that is that you'll have to recompress the audio at the end, with any degradation that may cause)
I can't be more precise that as it depends on the audio's codec and settings

QUOTE
Does using current version of VD ensures things like that never happen?

Virtualdub won't let you do it, but this is what would happen
Say, you had a video of a ball bouncing on the grass
If you saved from frame 2 onwards you'd have bits of a ball, bouncing on nothing, leaving a grass trail behind it, until the next keyframe
You might have seen this effect in a broken video download - a garbage screen with moving bits that suddenly becomes normal again when it gets a new keyframe

Posted by: itayf Nov 7 2010, 11:01 AM
Thank you again dloneranger for all of your detailed responses!
You helped me a lot! smile.gif

Itay.

Powered by Invision Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)