Log in

View Full Version : What is causing a glitch at frame 294 in my script?


rkr1958
10th December 2006, 03:22
I wrote the following script to illustrate to someone on videohelp.com how he might (I could) scroll text across a video using AVISynth.

# Deshook, DeNoised Video
a = AVISource("G:\MUMC_Preschool_Christmas_Show_2005\Song-1.avi",audio = false).ConvertToYUY2()
nf = Framecount(a)
fr = Framerate(a)

# Segment video to add in scrolling ribbon, which will contain the scrolling text
f1 = 288 # first frame when text extends full width of the screen
f2 = 1972 # first frame when text begins to exit the right part of the screen
a1 = a.trim(0,f1) # for scrolling ribbon
a2 = a.trim(f1+1,f2) # for fixed ribbon
a3 = a.trim(f2+1,nf) # for scrolling ribbon
n1 = Framecount(a1)
n2 = Framecount(a2)
n3 = Framecount(a3)

# Create the ribbons (1 & 3 scoll)
rib1 = blankclip(length=n1, width=720, height=40, fps=fr, color=color_black, audio_rate=0).ConvertToYUY2()
rib2 = blankclip(length=n2, width=720, height=40, fps=fr, color=color_black, audio_rate=0).ConvertToYUY2()
rib3 = blankclip(length=n3, width=720, height=40, fps=fr, color=color_black, audio_rate=0).ConvertToYUY2()

# Add ribbons to the bottom of the video to house the scrolling text
# Layer (clip, layer_clip, string "op", int "level", int "x", int "y", int "threshold", bool "use_chroma")
a1 = Animate(0,n1-1,"Layer",a1,rib1,"add",255,720,408,0,true, \
a1,rib1,"add",255, 0,408,0,true)
a2 = Layer(a2,rib2,x=0,y=408)
a3 = Animate(0,n3,"Layer",a3,rib1,"add",255, 0,408,0,true, \
a3,rib1,"add",255,-720,408,0,true)
clip = a1 + a2 + a3

# Create the Scrolling Text
scrolling_text = \
"This is an example of adding scrolling text to a video. " + \
"This text was added using AVISynth and the functions antimate and subtitle. " + \
"The running time of this video is approximately 1-minute & 15-seconds. " + \
"This video is from a source that was shot without a tripod and is very shakey. " + \
"Gunnar Thalin's Deshaker v2.0 plugin to virtualdub was used to stabilize this video. " + \
"Also, AVISynth filters pre and post deshook were used to prep and denoise this video. " + \
"I hope you have enjoyed this demostration."

# Antimate the scrolling text StrLen
clip = clip.Animate(8,nf-8, "Subtitle", \
Scrolling_text, 720, 414, 0, nf, "Arial", 24, color_yellow, \
Scrolling_text, -round(9.87*StrLen(scrolling_text)), 414, 0, nf, "Arial", 24, color_yellow)

# Add Audio
audio = WAVSource("G:\MUMC_Preschool_Christmas_Show_2005\RAW-Song-1.wav")
clip = AudioDub(clip, audio)

return clip Here's the glitch I got,

http://www.knology.net/~benrunyan/Frame_294_off.jpg

Note that the text just up several pixels and that the text from Scolling_Text line 4 versus line 1 is displayed. This glitch goes away if I change,

clip = clip.Animate(8,nf-8, "Subtitle", ... to
clip = clip.Animate(6,nf-8, "Subtitle", \

Any insights why my script cause this glitch and why it went away when I made the above change?

IanB
11th December 2006, 03:21
The Animate target value become -1 at that frame.... The parameters x and y can be set to -1 to automatically calculate and use the horizontal or vertical center coordinate.Ahhhgggg magic values :devil:

Performance Hint: To avoid unnecessary colour space conversions, use the Pixel_type="YUY2" on AviSource() and BlankClip() where appropriate.

Alternate approach: Declare an appropriatly wide, 40 high ribbon clip. Write all text onto the ribbon in 1 go. Use Animate of Layer of the ribbon to do the scroll.

rkr1958
11th December 2006, 23:49
The Animate target value become -1 at that frame.Ahhhgggg magic values :devil:

Performance Hint: To avoid unnecessary colour space conversions, use the Pixel_type="YUY2" on AviSource() and BlankClip() where appropriate.

Alternate approach: Declare an appropriatly wide, 40 high ribbon clip. Write all text onto the ribbon in 1 go. Use Animate of Layer of the ribbon to do the scroll.Thanks. The magic value -1 must be it. I guess it's just the luck of the draw on whether or not that value gets used in subtitle when using animate. That would explain why I would sometimes, but not all the time, see the glitch. I think I'll give the alternate approach a try.

Also, thanks for your performance hint. A couple of questions. So would the command,

a = AVISource("G:\MUMC_Preschool_Christmas_Show_2005\Song-1.avi",Pixel_type = "YUY2", audio = false)

produce the same result (but only faster) as

# Deshook, DeNoised Video
a = AVISource("G:\MUMC_Preschool_Christmas_Show_2005\Song-1.avi",audio = false).ConvertToYUY2() ?

Are there also quality differences between these two?

IanB
14th December 2006, 04:53
The main point was not to convert the BlankClips. Generate them as YUY2 directly.

In the the 1st case you are explicitly asking the codec to decode to YUY2 pixel type ONLY!

In the second case, the codec will be asked for in turn YV12, YUY2, RGB32 then RGB24, The first type the codec can deliver will be used. If YUY2 is returned anyway the ConvertToYUY2 will be a noop.

There are many scenarios I will mention a few.

1. The codec cannot do YUY2 - Script Error.
2. The codec can do YV12 but does YUY2 better - Better Quality.
3. The internal data is natively YV12, the codec has inferior or slow YV12 -> YUY2 code - Worse quality or slower.
4. The internal data is natively YV12, the codec knows the data is interlaced and can correctly deinterlace the chroma to YUY2 - Correct chroma sampling.
5. The internal data is natively YV12, the codec does not knows the data is interlaced and incorrectly deinterlaces the chroma to YUY2 - Chroma Sampling Error.
6. The internal data is RGB, the codec has inferior or slow RGB -> YUY2 code - Worse quality or slower.

It pays to know a little about your codec. At a minimum test with pixel_type="YV12" and "YUY2" and compare the results.



Also one catch with layer and YUY2 is mod 2 horizontal pixel alignment, this means the text will scroll 2 pixels at a time.

In your original approach you could add a number of spaces to the start of your message so you can skip around the 720 -> -1 animate cases and start directly at -2.