Log in

View Full Version : Weird problem with combining filters


JohannesL
6th March 2009, 10:30
a = AVISource("Vid1.avi")
a = a.Crop(0,16,0,-16)
aC = a.Trim(0,6292)
b = AVISource("Vid2.avi")
b = b.Crop(0,16,0,-16)
bC = b.Trim(0,5010)
b = b.DelayAudio(-0.25)
bC = bC.DelayAudio(-0.25)
c = AVISource("Vid3.avi")
c = c.Crop(0,16,0,-16)
cC = c.Trim(0,4030)
d = AVISource("Vid4.avi")
d = d.Crop(0,16,0,-16)
dC = d.Trim(0,2908)
V1 = Dissolve(aC,bC,cC,dC,12)
V1 = V1.LanczosResize(1028,720)
V1 = V1.AddBorders(126,0,126,0)
S1 = StackHorizontal(a,b)
S2 = StackHorizontal(c,d)
V2 = StackVertical(S1,S2)
V2 = V2.LanczosResize(1028,720)
V2 = V2.AddBorders(126,0,126,0)
a1 = GetChannel(a, 1, 2)
a1 = a1.ConvertToMono
b1 = GetChannel(b, 1, 2)
b1 = b1.ConvertToMono
c1 = GetChannel(c, 1, 2)
c1 = c1.ConvertToMono
d1 = GetChannel(d, 1, 2)
d1 = d1.ConvertToMono
a1_c1 = MergeChannels(a1,c1)
b1_d1 = MergeChannels(b1,d1)
LC = ConvertToMono(a1_c1)
RC = ConvertToMono(b1_d1)
audio = MergeChannels(LC,RC)
Sp = AudioDub(V2,audio)
Dissolve(V1,Sp,12)

At the end of V1, a few frames before the dissolve to Sp starts, two random frames from Sp are shown, overlayed over V1, like at the beginning of a dissolve. But again, it's before the dissolve starts.
If I use AlignedSplice instead of Dissolve to comine V1 and Sp, the random frames from Sp are still shown at the end of V1, but instead of being overlayed over V1, they completely replace the V1 frames. What could be the cause of this weirdness? V1 and Sp work fine separately.

JohannesL
7th March 2009, 10:56
It should be noted that no problems occour if I don't trim.

Gavino
7th March 2009, 12:28
It does seem something strange is going on. Here are some ideas to try and home in on the problem,
- add ShowFrameNumber() to each source and check exactly which frames go wrong and where.
- try eliminating some/all of the audio processing to see if that is having some influence.

When you say 'random' frames from Sp are shown, are these different frames each time, or always the same unexpected frames?

stickboy
7th March 2009, 12:55
I tried replacing each of your AVISource calls with:
BlankClip(length=10000, width=320, height=240, color=$000000, pixel_type="yuy2", stereo=true).ShowFrameNumber()with different values of "color" for each call, but I'm not seeing anything obviously amiss around frame 18207 (which is where V1 ends) nor around frame 18240.

JohannesL
7th March 2009, 13:20
It should be noted that the weirdness does not occour when I don't trim. It still makes no sense to me.

I made a test video (sm64.org/test.mkv) using a simple script:
a = AVISource("Vid1.avi").Crop(0,16,0,-16)
aC = a.Trim(0,500)
V1 = Dissolve(aC,aC,12).AddBorders(320,0,320,0)
S1 = StackHorizontal(aC,aC)
AlignedSplice(V1,S1)
The weirdness is slightly different from that of the first script, but it's present. Look at frames 496 and 497. The weirdness occours a few frames from the end of the total number of frames kept with Trim(). (In the first script, 6292 + 5010 + 4030 + 2908 = 18240. The weirdness occours a few frames before 18240.)
I have a temporary workaround; using a large dissolve. But I still want to know what causes this weirdness.

Gavino
7th March 2009, 17:45
Replacing AviSource by ColorBars in your latest example script, it worked fine for me with no unexpected results.

Perhaps there is something odd about your source, in particular maybe it is not seeking properly when it has to redisplay the starting frames again after the splice. Have you tried other sources?

JohannesL
9th March 2009, 18:25
I've tried hard to solve the problem with no luck.
My source videos are captured using Mupen64's in-built AVI capture feature, and I capture with the x264vfw at QP10. Except for this weird problem with trimming in AviSynth, I've never experienced any problems with it.
MediaInfo:


Format : AVI
Format/Info : Audio Video Interleave
File size : 1.59 MiB
Duration : 1s 967ms
Overall bit rate : 6 790 Kbps

Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Main@L5.1
Format settings, CABAC : Yes
Format settings, ReFrames : 2 frames
Codec ID : H264
Duration : 1s 966ms
Bit rate : 5 319 Kbps
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4/3
Frame rate : 60.000 fps
Resolution : 24 bits
Colorimetry : 4:2:0
Scan type : Progressive
Bits/(Pixel*Frame) : 0.289
Stream size : 1.25 MiB (78%)
Writing library : x264 core 66 r1115bm 11863ac
Encoding settings : cabac=1 / ref=2 / deblock=1:0:0 / analyse=0x3:0x13 / me=dia / subme=4 / psy_rd=0.0:0.0 / mixed_ref=0 / me_range=10 / chroma_me=0 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chroma_qp_offset=0 / threads=3 / thread_queue=3 / nr=0 / decimate=0 / mbaff=0 / bframes=0 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=cqp / qp=10 / ip_ratio=1.40 / aq=0

Audio
Format : PCM
Format settings, Endianness : Little
Format settings, Sign : Unsigned
Codec ID : 1
Codec ID/Hint : Microsoft
Duration : 1s 967ms
Bit rate mode : Constant
Bit rate : 1 411.2 Kbps
Channel(s) : 2 channels
Sampling rate : 44.1 KHz
Resolution : 16 bits
Stream size : 339 KiB (21%)
Interleave, duration : 22 ms (1.33 video frame)
Interleave, preload duration : 500 ms

Gavino
9th March 2009, 18:59
If you run the script you posted above (#5) using a different source (eg ColorBars().ShowFrameNumber()), do you still see something unexpected?

Do you see the problem running your script through a player or using VDub, or are you looking only at encoder output?

JohannesL
9th March 2009, 19:06
If you run the script you posted above (#5) using a different source (eg ColorBars().ShowFrameNumber()), do you still see something unexpected?

Do you see the problem running your script through a player or using VDub, or are you looking only at encoder output?
The problem is present in VDub, media players and encoder output.
I tried this:

a = ColorBars().ShowFrameNumber().Crop(0,16,0,-16).Trim(0,300)
ST = StackHorizontal(a,a)
b = StackVertical(ST,ST).BicubicResize(640,448)
AlignedSplice(a,b)
Looks fine, though that doesn't help me much.

Gavino
9th March 2009, 19:28
Could you maybe upload somewhere your source Vid1.avi from your post #5 ? - say the first 1000 frames. Then we can check it out directly and play around with your script.

JohannesL
9th March 2009, 20:06
www.sm64.org/Vid1.avi

Gavino
9th March 2009, 21:17
There seems to be something weird about your source which causes problems when rewinding to the beginning. Just stepping through it in VDub, the first time I see a fade-in at the start, but when I rewind to frame 0 I see a later frame instead.

stickboy
10th March 2009, 04:29
The problem is present in VDub, media players and encoder output.
I tried this:

a = ColorBars().ShowFrameNumber().Crop(0,16,0,-16).Trim(0,300)
ST = StackHorizontal(a,a)
b = StackVertical(ST,ST).BicubicResize(640,448)
AlignedSplice(a,b)
Looks fine, though that doesn't help me much.If you can't reproduce the problem with BlankClip/ColorBars, then it's a codec bug.

You're best off using VirtualDub to temporarily re-encode your source video with, say, Huffyuv.

Comatose
10th March 2009, 08:06
AVISource + anything that needs hacks to go in an AVI = weird behavior like this (green frames at the start, earlier frames suddenly show up)
I think if you reopened the clip and seeked manually somewhere else then to the same place you'd see that different frames show up in the strange areas.

What you should do right now is demux the video and use DGAVCDec to index and source it into Avisynth, and in the future you should encode into some lossless format or any other format which only has I-frames (DV? MJPG?)

I might be wrong about only I-frames being good for AVI, but that fits the "one frame in, one frame out" sayings I've seen about AVI. You can of course just keep demuxing and indexing, but x264 + VFW makes me cringe :(

JohannesL
10th March 2009, 08:35
AVISource + anything that needs hacks to go in an AVI = weird behavior like this (green frames at the start, earlier frames suddenly show up)
I tried using DirectShowSource instead, and that solved everything. Thanks!
Edit: Or maybe not. When a transition starts, it jumps back two frames, though AlignedSplice works fine. >_>
I guess I'll use HuffYUV from now on, though disk space can be a problem. x264vfw is faster and makes smaller files than anything else I've tried for capturing.
Edit2: I found a workaround:
a = DirectShowSource("Vid1.avi").Crop(0,16,0,-16).Trim(0,500)
a2 = DirectShowSource("Vid1.avi").Crop(0,16,0,-16)
ST = StackHorizontal(a2,a2)
b = StackVertical(ST,ST).BicubicResize(640,448)
Dissolve(a,b,30)
As opposed to:
a2 = DirectShowSource("Vid1.avi").Crop(0,16,0,-16)
a = a2.Trim(0,500)
ST = StackHorizontal(a2,a2)
b = StackVertical(ST,ST).BicubicResize(640,448)
Dissolve(a,b,30)
Strangely it avoids the problem completely..

Gavino
10th March 2009, 11:18
Strangely it avoids the problem completely..
Yes, using two independent source filters for clips a and b in this script avoids seeking back to frame 0 in the final Dissolve. (The StackHorizontal is no problem since both parts use the same frame and don't require a seek.)