PDA

View Full Version : Avisynth gone wrong


Kraise
8th February 2009, 11:35
Dunno, I want to see how much you can mess up a source with Avisynth, I mean create halos, scratches, holes, butcher the film unrecognizable, then post your scripts so the world can use them and their glory of greatness

Sagekilla
8th February 2009, 21:35
There a point in that? Usually we try to -improve- videos. Not muck them up. That's the studio's job (read: Cowboy Bebop on Blu-ray.)


Easy way to make it look horrendous:

AddGrain(10).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).blur(1.58)
Sharpen(1).Sharpen(1).Sharpen(1).Sharpen(1).Sharpen(1).Sharpen(1).Sharpen(1).Sharpen(1)

thetoof
9th February 2009, 16:36
Actually, I'd also be interested in such a script to give a *very* old look to the image by screwing it up, but in a bit more refined fashion
-Sepia
-vertical lines (scratches)
-dirt + cigarette burns (I guess a blurred circular mask)
-shaky (inverse of depanstabilize)

That'd be a bit trickier that an addgrain.blur.sharpen chain, but it'd be some nice butchering :p

Jumpyshoes
9th February 2009, 18:15
HaloMaker3000Deluxe()

That's all I have to say.

Edit: Here's an example of HaloMaker3000Deluxe... almost. It renders really slowly so I did some magic. WATCH THIS AT YOUR OWN RISK: http://www.youtube.com/watch?v=SeWGyH2-dQY&fmt=22

Sagekilla
9th February 2009, 21:56
Sepia itself would be very easy. Tweak() could get that done. Then, vertical lines could be added with AddGrain(50, 0, 1) (replace str with your choice -- It's going to make huge vertical streaks regardless.)

Cigarette burns would be pretty easy IMO. if you play around with making a mask similar to the script I posted above, you can get a fairly nice random pattern of spots you can use to mask in something:

blank = BlankClip()
noise = blank.AddGrain(5,0,0).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58)
diff = mt_makediff(blank,noise,U=3,V=3)


You'd just need to find a way to create a "burnt" look (Perhaps play around with tweak()?) and mask it in based on the diff. I'm about 90% sure you could do that. But I'd have to play around and get back to you.

Wilbert
10th February 2009, 22:01
Sepia itself would be very easy. Tweak() could get that done.
You can't create a sepia look with Tweak. Have a look at Colorlooks.

Reuf Toc
11th February 2009, 19:17
To stay in the old look theme, is anybody have an idea to create luma flickering ? Same question for shaking video.

Thanks in advance.

J_Darnley
11th February 2009, 23:03
Flicker:
src = last
flicker = BlankClip(src, width=64, height=64, color_yuv=$808080).AddGrain(100).PointResize(width(src), height(src), 32,32,1,1)
src.mt_adddiff(flicker)

Shake:
ScriptClip("""
randcrop_w=rand(32)
randcrop_h=rand(32)
LanczosResize(width(src), height(src), randcrop_w, randcrop_h, -32+randcrop_w, -32+randcrop_h)
""")

Reuf Toc
12th February 2009, 21:34
Thank you J_Darnley, especially for luma flickering, I shall not have been able to find it by myself. I was closer for shaking, I just didn't find a way to generate random number for each frame.

I've made a function to give an old look to your movies. It's far from perfect but I'm open to any suggestion. Here it is :

Function OldLook ( clip clp, bool "sepia", bool "vertscratch", bool "stain", bool "lumaflick", bool "shake")

{

sepia = default (sepia , true)
vertscratch = default (vertscratch , true)
stain = default (stain , true)
lumaflick = default (lumaflick , true)
shake = default (shake , true)


x = width (clp)
y = height (clp)


# sepia

(sepia == true ) ? Eval("""
sepiaclip = blankclip (clp, color = $704214)
clp = overlay (clp, sepiaclip, mode="chroma", opacity=0.5) """) : nop


# vertical scratches

(vertscratch == true ) ? Eval("""

scratch = blankclip(clp,color=$ffffff).addgrain(7,0,vcorr=1,seed=1).mt_binarize(threshold=228)
clp = clp.overlay(scratch,mode="darken",opacity=0.2) """) : nop

# stains

(stain == true) ? Eval("""

blank = blankclip(clp,color=$808080)
noise = blank.spline36resize(32,32).AddGrain(25,0,0).blur(1.58).spline36resize(x,y)
clp = mt_adddiff(clp,noise) """) : nop

# luma flickering

(lumaflick == true ) ? Eval("""

flicker = BlankClip(clp, width=64, height=64, color_yuv=$808080).AddGrainc(10).PointResize(x, y, 32,32,1,1)
clp = clp.mt_adddiff(flicker) """) : nop


# shake

last = clp
(shake == true) ? Eval("""

ScriptClip("
x = width ()
y = height ()
randcrop_w =rand(2)
randcrop_h =rand(2)
spline36Resize(x, y, randcrop_w, randcrop_h, -2+randcrop_w, -2+randcrop_h)
")""") : nop



return last }
It's almost not tweakable but I can add parameters if requested.

smok3
12th February 2009, 21:40
# a function which improves smoothness and compressibility with hd video, smok3 (c) 2009, 2010, 2011
resize(16,16).resize(1920,1080)

J_Darnley
12th February 2009, 23:15
Thank you J_Darnley, especially for luma flickering, I shall not have been able to find it by myself. I was closer for shaking, I just didn't find a way to generate random number for each frame.

I've made a function to give an old look to your movies. It's far from perfect but I'm open to any suggestion. Here it is :

<snip>

It's almost not tweakable but I can add parameters if requested.
Nice work. I once created a sepia tone with with an overlay and a blankclip of the colour Wikipedia (http://en.wikipedia.org/wiki/Sepia_(color)) said sepia was.

Also, I continued to work on the shake and flicker some more last night and got these two functions. Flicker:
function Flicker(clip src, float "flicker_scale")
{
# More is less, that is the bigger this scale, the less the flicker.
flicker_scale = default(flicker_scale, 100.0) * 10.0
Eval("""ScriptClip(src, "rand = 1.0 + float( rand(256)-64 ) / """+string(flicker_scale)+"""
Levels(0, rand, 255, 0, 255, coring=false)")""")
return last
}
Perhaps someone can offer the correct value for the random shift to that the min gamma is as dark as the max gamma is bright. Does that make sense? Isn't gamma=0.5 the same change as gamma=5.0?

Shake, it doesn't work as a function, but this is what I would like to to be as:
function Shake(clip src, int "shift_fraction", int "target_w", int "target_h", string "temporal_variation")
{
# Sets the maximum fraction of the image that it can move. 10 is one-tenth, 20 is one-twentieth, 100 is one one-hundredth.
# Means that the relative shaking on a 500px wide image is the same as on a 2000px wide image.
# Shaking is relative in both x and y.
shift_fraction = default(shift_fraction, 50)
# I wanted the output to be scaled down so I added this.
# Default is to make the output clip the same dimensions as the input.
target_w = default(target_w, width(src))
target_h = default(target_h, height(src))
# A string to alter the shaking in some way, not necessarily with time.
# To increase the shaking with time, perhaps use: "float(current_frame+1)/framecount"
temporal_variation = default(temporal_variation, "1.0")
src_w = width(src)
src_h = height(src)

Eval("""ScriptClip( BlankClip(src, width=target_w, height=target_h), "
shift_x=float( rand( """+string(src_w/shift_fraction)+""" ) - """+string(src_w/float(shift_fraction*2))+""" ) * """+temporal_variation+"""
shift_y=float( rand( """+string(src_h/shift_fraction)+""" ) - """+string(src_h/float(shift_fraction*2))+""" ) * """+temporal_variation+"""

crop_left = """+string(src_w/float(shift_fraction*2))+""" + shift_x
crop_top = """+string(src_h/float(shift_fraction*2))+""" + shift_y

crop_right = """+string(-src_w/float(shift_fraction*2))+""" + shift_x
crop_bottom = """+string(-src_h/float(shift_fraction*2))+""" + shift_y

LanczosResize(src, """+string(target_w)+""", """+string(target_h)+""", crop_left, crop_top, crop_right, crop_bottom)
")""")

return last
}
An addition to this would be to specify an absolute pixel shift. The default is quite a shift. Think "Why does the Enterprise not have seatbelts?" kind of shaking. Another addition would be to generate half as many random numbers and then interpolate between them so there is slower shaking.

Small demo: http://users.telenet.be/darnley/avisynth/flicker%20and%20shake.mkv
Made with:
SetMTMode(3,0)
LoadPlugin("D:\Avisynth\Plugins\AddGrainC.dll")
LoadPlugin("D:\Avisynth\Plugins\MT.dll")

ImageReader("D:\Images\4chan\w\bleach_1234314674285.jpg", use_devil=false)
ConvertToYV12()
src = last

(true)?Shake(100, 640, 400):LanczosResize(640,400)
Flicker(100.0)
AddGrain(200, 0.1, 0.9)
Trim(0,239)
AssumeFPS(24)

Gavino
13th February 2009, 12:11
function Flicker(clip src, float "flicker_scale") {
...
Eval("""ScriptClip(src, "rand = 1.0 + float( rand(256)-64 ) / """+string(flicker_scale)+"""
Levels(0, rand, 255, 0, 255, coring=false)")""")
There's no need to use Eval here - you can just write
ScriptClip(src, "rand = 1.0 + float( rand(256)-64 ) / "+string(flicker_scale)+"
Levels(0, rand, 255, 0, 255, coring=false)")
or, if you use GRunT,
ScriptClip(src, "rand = 1.0 + float( rand(256)-64 ) / flicker_scale
Levels(0, rand, 255, 0, 255, coring=false)", args="flicker_scale")
Shake, it doesn't work as a function...
To make it work, you are forced to set the variable src in your demo script before calling the function, making it impossible to use on two different clips. The real benefits of GRunT can be seen when applied to this function, solving the problem while also making the function simpler and more readable.
function GShake(clip src, int "shift_fraction", int "target_w", int "target_h", string "temporal_variation") {
shift_fraction = default(shift_fraction, 50)
target_w = default(target_w, width(src))
target_h = default(target_h, height(src))
temporal_variation = default(temporal_variation, "1.0")
ScriptClip( BlankClip(src, width=target_w, height=target_h), "
variation = Eval(temporal_variation)
shift_x=float(rand(src_w/shift_fraction) - src_w/float(shift_fraction*2)) * variation
shift_y=float(rand(src_h/shift_fraction) - src_h/float(shift_fraction*2)) * variation

crop_left = src_w/float(shift_fraction*2) + shift_x
crop_top = src_h/float(shift_fraction*2) + shift_y

crop_right = -src_w/float(shift_fraction*2) + shift_x
crop_bottom = -src_h/float(shift_fraction*2) + shift_y

LanczosResize(src, target_w, target_h, crop_left, crop_top, crop_right, crop_bottom)
", args="src, src_w=width(src), src_h=height(src), shift_fraction, target_w, target_h, temporal_variation")
}

J_Darnley
13th February 2009, 13:02
There's no need to use Eval here - you can just write
<snip>
or, if you use GRunT,
<snip>

To make it work, you are forced to set the variable src in your demo script before calling the function, making it impossible to use on two different clips. The real benefits of GRunT can be seen when applied to this function, solving the problem while also making the function simpler and more readable.
THANK YOU!

I forget why I was using Eval() in the flicker, perhaps copy-pasta syndrome.

I discovered that I had to set src in the main body of the script. What confuses me is that:
src = last
Shake()
worked as did:
src = last
<lots of text>
but when src was only a variable in the function it would complain. Is this some of what was mentioned in your thread? I haven't read it yet but I certainly intend to.

Gavino
13th February 2009, 13:34
I discovered that I had to set src in the main body of the script. What confuses me is that:
src = last
Shake()
worked as did:
src = last
<lots of text>
but when src was only a variable in the function it would complain.
The basic problem which bites you when using ScriptClip inside a function is that the function parameters and local variables do not exist at the time the run-time script is executed. See here (http://avisynth.org/mediawiki/The_script_execution_model/Scope_and_lifetime_of_variables).

The conventional solution has been to use the string() function and string concatenation, but this is cumbersome and can't be used for clip variables. GRunT provides a much more natural way of binding the variables at the place ScriptClip is called to values inside the run-time script.

sumawo13
15th February 2009, 15:17
This thread has been lingering in my head and I thought I would try an idea on the Reservoir Dogs DVD. I wanted to see if I could make it look as if it were being displayed on TV as best I could.

http://i44.tinypic.com/14nzmnk.png

Here is my script. The only external filter I used was ImageSequence.

vid1=audiodub(mpeg2source("VTS_01_1.d2v").crop(2,56,-0,-60).lanczosresize(848,352).crop(104,0,-104,-0).addborders(0,64,0,64).converttorgb32().generalconvolution(0, "
0 0 0
-1 -6 4
0 5 0 ", 1, false).converttoyv12(),directshowsource("VTS_01_1 T80 2_0ch 192Kbps DELAY 0ms.ac3"))
img1=coronasequence("C:\Documents and Settings\Bryant\Desktop\fuzz2\*.png",sort=1).assumefps(23.976).loop()
overlay(vid1,img1,mode="exclusion",opacity=.25)
trim(110276,119186)

If someone has any ideas, I liked to hear them.

shoopdabloop
13th April 2010, 01:57
# a function which improves smoothness and compressibility with hd video, smok3 (c) 2009, 2010, 2011
resize(16,16).resize(1920,1080)

works wonders!

@sumawo13: that actually looks more embossed than TV-like.

raffriff42
20th August 2015, 07:11
Bumping this old thread because it is awesome (I especially like Reuf Toc's "OldLook"), and because I've got a new (?) effect. It's kind of a "reverse TBC", because it modulates horizontal position line-by-line from any audio signal, to create that "analog breakup" effect.
https://www.dropbox.com/s/gemzvpyo5qdusph/jitter_05.07.jpg?raw=1

For the jitter source, use white noise, sine waves or whatever you like to get the look you want.

I believe this code is original, but if it was copied from somewhere, I apologize! LoadPlugin("Waveform\waveform.dll")

/*
## requires MaskTools2
## requires "Software TBC"
# http://forum.doom9.org/showthread.php?t=162726
# http://www.sendspace.com/file/s78pp4
# which requires:
# findpos 0.1 (EDIT included w/ tbc061.zip)
# dejitter 0.2 (EDIT included w/ tbc061.zip)
LoadPlugin("tbc\dejitter03\dejitter.dll")
LoadPlugin("tbc\findpos02\findpos.dll")
Import("tbc\dejitter03\dejitter.avs")
## requires MaskTools
*/
Import("tbc\tbc.avs")

##################################
### modulate horizontal position line-by-line
##
## jitter signal source = clip A's audio track (if missing, use clip C's audio)
##
#@version 1.1 Jul-2016 - in addition to YV12, add support for YV24, RGB24, RGB32
##
function JitterGenerator(clip C, clip "A")
{
Assert(C.IsYV12 || C.IsYV24 || C.IsRGB24 || C.IsRGB32,
\ "JitterGenerator: source must be YV12, YV24, RGB24 or RGB32")

A = Default(A, C)
A = IsClip(A) && HasAudio(A) ? A : C

## Last==
AudioDub(C, A.ConvertToMono)

## jitter source: add vertical waveform to left 48 pixels
TurnLeft
(!C.IsYV24)
\ ? Waveform(window=0, height=48, under=true, zoom=1)
\ : StackVertical(
\ Last,
\ ConvertToYV12
\ .Waveform(window=0, height=48, under=true, zoom=1)
\ .ConvertToYV24
\ .Crop(0, Height-48, 0, 0)
\ )
TurnRight

src = Last
thresh = 85

## Mark video edges:
## search for the first bright pixel in left 48 pixels
p = tbc_findpos_h(src.ConvertToYV12, x1=0, x2=48, thresh=thresh, leftonly=0>0)

## jitter the video
(C.IsYUV)
\ ? jitter_shift_yuv(src, p)
\ : jitter_shift_rgb(src, p)

Crop(48, 0, C.Width, C.Height)

## restore original audio
return Last.AudioDub(C)
}

#######################################
## (HACK) based on tbc_Rescale;
## shifts video position roughly according to 1st offset
##
function jitter_shift_yuv(clip C, clip offsets)
{
y = C.Greyscale
u = UtoY(C)

w1 = u.Width
h1 = u.Height

u = u.BicubicResize(y.Width, y.Height)
v = VtoY(C).BicubicResize(y.Width, y.Height)

## use 1st offset only
offsets = offsets.PointResize(4, offsets.Height).Crop(0, 0, 2, -0)

## (HACK) tweak offsets for approximately even shift
offsets = StackHorizontal(
\ offsets.mt_lut("255 x - 2 / 92 - ")
\ , offsets.mt_lut("x 16 - ")
\ ).PointResize(2, offsets.Height)

y1 = dejitter(y, offsets)
u1 = dejitter(u, offsets).BicubicResize(w1, h1)
v1 = dejitter(v, offsets).BicubicResize(w1, h1)

YtoUV(u1, v1, y1)
}

#######################################
## (HACK) based on tbc_Rescale;
## shifts video position roughly according to 1st offset
##
function jitter_shift_rgb(clip C, clip offsets)
{
r = C.ShowRed ("YV12")
g = C.ShowGreen ("YV12")
b = C.ShowBlue ("YV12")

## use 1st offset only
offsets = offsets.PointResize(4, offsets.Height).Crop(0, 0, 2, -0)

## (HACK) tweak offsets for approximately even shift
offsets = StackHorizontal(
\ offsets.mt_lut("255 x - 2 / 92 - ")
\ , offsets.mt_lut("x 16 - ")
\ ).PointResize(2, offsets.Height)

r = dejitter(r, offsets)
g = dejitter(g, offsets)
b = dejitter(b, offsets)

return (C.IsRGB24)
\ ? MergeRGB(r, g, b)
\ : MergeARGB(C.ShowAlpha, r, g, b)
}

Sparktank
20th August 2015, 08:04
# findpos 0.1 http://www.sendspace.com/file/fxzxr5
# dejitter 0.2 http://www.sendspace.com/file/upms1f

This looks fun, too, but the sendspace links are down.
Have a backup somewhere of the required plugins?
They're not up on the wiki anywhere (that I see in a search)

pandy
20th August 2015, 10:38
Use ffdshow for this things - Noise module is quite nice to add scratches and old movie look.

raffriff42
20th August 2015, 20:12
This looks fun, too, but the sendspace links are down.Luckily, dejitter and findpos are included with tbc061.zip.
http://www.sendspace.com/file/s78pp4

Reel.Deel
21st August 2015, 01:13
jmac's plugins (dejitter, findpos, and more) can be found here: http://forum.doom9.org/showthread.php?p=1690894#post1690894

Sparktank
21st August 2015, 01:44
Fun on a bun!
Thanks for the links+info.

jmac698
21st August 2015, 13:48
I thought that was a creative use of my jitter function! I'm glad also, I thought it would be more useful to modularize the functions. I think a lot of effects should be available on a line basis, at least relating to processing of analog based interlaced videos.

Here's my VHS degrader:
http://forum.doom9.org/showthread.php?p=1470667
note the coding is bad here, crops can be included in resize.

Here's someone's more sophisticated emulation:
https://www.youtube.com/watch?v=osUvH8PRk3g

Actually, I find your application really interesting, I was thinking of making a video modulated by audio. Did you know that if you do that, you can simply plug the video output into a speaker and hear the sound? Except for a loud 50/60Hz buzz from the vertical blanking. I used this technique to create digital sound from video on an old homecomputer without a DAC.

Extending that idea, with video patterns and connecting VGA output to an antenna, you can create a valid digital TV signal with almost only software.

What if you turned video into audio then used Rightmark Audio Analyzer to give stats on the video quality of a VHS like SNR, distortion etc.?