ffmpegavisynthvirtualdub

Avisynth total frames does not equal VirtualDub total frames


It appears that Dissolve and/or Fade change the total number of frames in .avs scripts. When I add up the total number of frames in the avs script and then load the avs script in Vdub the total number of frames is different. My real world example below shows a difference of 822 frames vs 1368 frames for the same script. I have run some basic tests which appear to support this hypothesis. Of course I may be doing something stupid. Any guidance would be greatly appreciated. Please let me know if I can clarify anything. Ffmpeg also borks on the same script which leads me to think this is an Avisynth issue. Or my lack of avs coding skills.

System specs: Win7, FFmpeg version: 20170223-dcd3418 win32 shared, AVISynth version: 2.6

Test1.avs = 200 frames long = Expected behaviour

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24, start=1, end=100)
v2=ImageReader("2.png", fps=24, start=1, end=100)
video = v1 + v2
return video

Test2.avs with return Dissolve = 195 frames long = Unexpected behaviour

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24, start=1, end=100)
v2=ImageReader("2.png", fps=24, start=1, end=100)
return Dissolve(v1, v2, 5)

Test3.avs with fadeOut(fadeIn = 202 frames long = Unexpected behaviour

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24, start=1, end=100)
v2=ImageReader("2.png", fps=24, start=1, end=100)
fadeOut(fadeIn(v1 + v2, 60), 60)

Test4.avs with dissolve and fade = 197 frames long = Unexpected behaviour

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24, start=1, end=100)
v2=ImageReader("2.png", fps=24, start=1, end=100)
v3 = Dissolve(v1, v2, 5)
fadeOut(fadeIn(v3, 60), 60)

Test5.avs explicity specifying frame rates on dissolve and fade = 197 frames = Unexpected behaviour

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24, start=1, end=100)
v2=ImageReader("2.png", fps=24, start=1, end=100)
v3 = Dissolve(v1, v2, 5, 24)
fadeOut(fadeIn(v3, 60, $000000, 24), 60, $000000, 24)

realExample = 822 frames long = Expected behaviour (this is what I want)

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24).trim(1,106)
v3=ImageReader("3.png", fps=24).trim(1,471)
v9=ImageReader("9.png", fps=24).trim(1,58)
v10=ImageReader("10.png", fps=24).trim(1,35)
v11=ImageReader("11.png", fps=24).trim(1,152)
video = v1 + v3 + v9 + v10 + v11
return video

realExample = 1368 frames long

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\VSFilter.dll")
v1=ImageReader("1.png", fps=24).trim(1,106)
v3=ImageReader("3.png", fps=24).trim(1,471)
v9=ImageReader("9.png", fps=24).trim(1,58)
v10=ImageReader("10.png", fps=24).trim(1,35)
v11=ImageReader("11.png", fps=24).trim(1,152)
d1 = Dissolve(v1, v3, 5)
d3 = Dissolve(v3, v9, 5)
d9 = Dissolve(v9, v10, 5)
d10 = Dissolve(v10, v11, 5)
fadeOut(fadeIn(d1 + d3 + d9 + d10,60),60)

Solution

  • You stated that some of your results gave "unexpected behavior", but you didn't specify what you expected them to be, so it's unclear what you think is wrong and where your misunderstanding lies. (When discussing problems, you should always state what results you got and what results you expected instead.)

    In your Dissolve example (Test2.avs), you say that 195 frames is unexpected, but that sounds correct to me. "Dissolving" two clips together means that the end of one clip overlaps with the beginning of a second clip as one gradually fades into the other; this is not the same as fading out the first clip and then fading in the second clip. The overlap means that the result must be shorter than the sum of the clips' individual lengths. You combined two 100-frame clips and specified a 5-frame overlap, so 100 + 100 - 5 = 195.

    In your FadeOut example (Test3.avs), you say that 202 frames is unexpected, but that also sounds correct to me. The documentation for FadeIn/FadeOut state:

    An additional color frame is added at the start/end, thus increasing the total frame count by one (or for FadeIO, by two).

    Since you made one call to FadeIn and one call to FadeOut in test3.avs, two extra frames were added. If you do not want this, then you can use FadeIn0/FadeOut0 (or FadeIO0 since you're using both), although note that with those functions, the first/last frame will not exactly be exactly black. If you want exactness, then simply trim off the first and/or last frames before using the normal FadeIn/FadeOut/FadeIO functions.

    Your "real examples" are comparing apples to oranges. The version with Dissolve dramatically increases the frame count because it's combining the same clips multiple times:

    d1 = Dissolve(v1, v3, 5)
    d3 = Dissolve(v3, v9, 5)
    ...
    fadeOut(fadeIn(d1 + d3 + d9 + d10,60),60)
    

    d1 and d3 each include a copy of the v3 clip, and then you spliced d1 and d3 together at the end, meaning that v3 is included twice. (This is also true for v9 and v10.)

    You probably intended to do something like:

    video = Dissolve(v1, v3, 5)
    video = Dissolve(video, v9, 5)
    video = Dissolve(video, v10, 5)
    video = Dissolve(video, v11, 5)
    video = FadeOut(FadeIn(video, 60), 60)
    

    or more succinctly:

    video = FadeIO(Dissolve(v1, v3, v9, v10, v11, 5), 60)
    

    The result should be 804 frames long: (822 frames from the original clips) - (4 dissolve points) * (5 frames of overlap per dissolve) + (2 frames from FadeIO).

    If you actually wanted to combine the clips by fading out and then fading in, then you could preserve the original frame count by doing:

    video =   FadeIO0(v1, 60) \
            + FadeIO0(v3, 60) \
            + FadeIO0(v9, 60) \
            + FadeIO0(v10, 60) \
            + FadeIO0(v11, 60)