Log in

View Full Version : Appending two VFR videos with Avisynth


Eretria-chan
25th June 2014, 17:28
I want to take several files, do some filters on them and append them into one video. So I took a small sample of what I try to do below. The problem is desync between video and audio. I presume that the videos are VFR since their FPS as reported by Info differs.

Sample avisynth:
Part1 = FFMpegSource2("...", atrack = -1)
Part2 = FFMpegSource2("...", atrack = -1)
Dissolve(Part1, Part2, 60)

I'd rather not force it to constant framerate if possible since it may cause jerkiness and whatnot. Though I am going to force 60 -> 30 fps later, with hopes that the result is as smooth as possible.

Any ideas?
Thanks.

TheFluff
25th June 2014, 20:31
You're going to have to convert everything to the same constant framerate or edit the timecodes manually (or use a different tool). Avisynth isn't VFR-aware at all.

Eretria-chan
25th June 2014, 20:42
I'm familiar with extracting and re-encoding with the timecodes later to get everything to sync, but I'm not sure how to adjust the timecodes manually. If video 1 has its last frame at time X, and the first frame in video 2 is on frame Y, then where should that frame be placed in the resulting merged video? I cannot seem to find an answer on how to merge two timecode files. Obviously it should be at least X + Y + some k, but what is k? If Y is 0, then k > 0 or the resulting frames will overwrite each other!

TheFluff
25th June 2014, 21:54
You get to choose k for yourself, pretty much. The Matroska timecode format only stores the start time of the frame, not its duration, so when splicing two videos you get to choose the duration of the last frame in the first video for yourself. I'd just choose the same duration as the second to last frame had.

Example: the two last frames of the first video have the timestamps 960 and 1000, respectively (using millisecond timestamps here, so we have a one second long video clip at 25 fps - 40 ms per frame). The first frame of the second video would thus start at time 1040 (i.e. you'd add 1040 to all timestamps in the second video's timecode file).

Eretria-chan
25th June 2014, 22:32
I see! Upon closer inspection, the source files seem to be 60 FPS VFR, where every frame seems to vary between 16 ms and 17 ms, so that should not be a problem.
Interestingly enough, I retried mkvextract which seems to add an extra "dummy frame" at the end of the timecode files, so it should be to just append them.

foxyshadis
26th June 2014, 10:38
In this case it's simple, but more complicated editing usually benefits from expanding everything to 120fps (119.88) -- or even 600 fps if you expect PAL and film together -- and akupenguin's dedup (http://akuvian.org/src/avisynth/dedup/) at the end to reduce it back to normal. Notably, that's the only way to merge streams with different framerates.

Since blending with Dissolve changes every frame and therefore won't dup out, you'd probably want something like JDL_ApplyRange(FrameCount(Part1-distance),FrameCount(Part1),"TDecimate(2,rate=59.94).ChangeFPS("+FrameRate+")") after the merge. (Using stickboy's ApplyRange and TIVTC.) 59.94 is just one possibility.

Eretria-chan
26th June 2014, 14:10
Thanks. I will keep that in mind. But for now, I'll focus on 60 fps VFR computer generated videos and not evil DVDs and Blu-rays. I'll cross that hurdle when I come to it.