View Full Version : Blurring moving face?
SamKook
4th November 2011, 03:27
I'm trying to blur someones face in a video using avisynth and after a couple of hours of searching and trying stuff, I can't seem to find something that would permit me to move and rotate a blur(I want to make something like a rectangularish blur over the eyes) using something like the ConditionalReader function(or if there's an eye tracking plugin out there it would be even better).
All I can find are logo removal plugins but they all seem to require a picture mask and I don't see how I could move that.
If someone could point me in the right direction to achieve what I want to do, it would be very much appreciated.
Gavino
4th November 2011, 10:33
You can blur a part of the frame by overlaying a cropped portion of the blurred video onto the original.
To vary the position, use ConditionalReader along with Overlay's conditional variables (http://avisynth.org/mediawiki/Overlay#Conditional_Variables).
SamKook
4th November 2011, 17:27
I did tests with a black bar overlay using conditionalreader, but the problem is that I can't rotate the overlay(put it at a 30 degree angle for example), only what's inside it, so that would look weird. The cropped portion of the frame would suffer from the same problem.
I'm also having trouble getting the cropped portion of the frame to follow the overlay movement since I'm not sure how to use conditionalreader without predefined variables. I either get "I don't know what var_name means" or "invalid arguments to function "LanczosResize". I tried the vars between "" or without them and also by naming all parameters, but LanczosResize didn't like that.
Here's what that portion of my script looks like(Mov is the main clip):
Blr = LanczosResize(Mov, 200, 40, s_left, 180, 200, 40)
ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
_xfoffset.txt contains(first tried with int to match the overlay move):
Type float
Default 200
I 0 99 200 400
Gavino
4th November 2011, 18:48
I did tests with a black bar overlay using conditionalreader, but the problem is that I can't rotate the overlay(put it at a 30 degree angle for example), only what's inside it, so that would look weird. The cropped portion of the frame would suffer from the same problem.
Are you saying you want the overlay to be not necessarily vertically/horizontally aligned? In that case, it's a bit more difficult - you need to construct a mask which rotates in the same way as the overlay.
Blr = LanczosResize(Mov, 200, 40, s_left, 180, 200, 40)
ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
Since s_left only exists at 'run-time', and varies from frame to frame, you need to put the call to LanczosResize inside ScriptClip:
Blr = ScriptClip(Mov, "LanczosResize(200, 40, s_left, 180, 200, 40)")
ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
Zarxrax
4th November 2011, 22:39
Seems like a very time consuming process via avisynth. Of course avisynth is a free method of achieving this, but if you are working with a long clip, you might want to look into something more appropriate like Adobe After Effects.
SamKook
5th November 2011, 03:44
Are you saying you want the overlay to be not necessarily vertically/horizontally aligned?
That's exactly what I want since I want to be able to more or less follow the head movement.
I'll have to look more into mask because for now, I only know how to apply a picture with some transparency in it, but that won't work in this case.
Blr = ScriptClip(Mov, "LanczosResize(200, 40, s_left, 180, 200, 40)")
I still get the same errors with this, but it's written on the top of the overlay(which doesn't get cropped) now instead of a popup.
Seems like a very time consuming process via avisynth.
Indeed, but I want to do it more out of curiosity and to perfect my knowledge of avisynth than a real necessity.
Gavino
5th November 2011, 09:17
I still get the same errors with this, but it's written on the top of the overlay(which doesn't get cropped) now instead of a popup.
Please post your complete script, or at least a cut-down version which still gives the error.
SamKook
5th November 2011, 16:14
The error I get is "I don't know what s_left means ([ScriptClip], line 1)"
Here's the script:
SetMemoryMax(1024)
SetMTMode(5, 7)
Vid = DGDecode_mpeg2source("D:\_1enc_\SMA-481\sma481.d2v")
Aud = NicAC3Source("D:\_1enc_\SMA-481\sma481 T80 2_0ch 192Kbps DELAY 0ms.ac3")
Mov = AudioDub(Vid, Aud)
SetMTMode(2)
horizCrop = Mov.Width() % 2
vertCrop = Mov.Height() % 2
Mov = Mov.Crop(0, 0, -horizCrop, -vertCrop)
Mov = Mov.QTGMC(Preset="Slow", TR2=1, EdiThreads=4, ShowSettings=false, NoiseProcess=2, Denoiser="dfttest", DenoiseMC=true, NoiseTR=2, Sigma=2, ShowNoise=0, GrainRestore=0.6, NoiseRestore=0.2, NoiseDeint="Generate", StabilizeNoise=true)
#2768-438200
Mov = Mov.Trim(2768,2867)
Blr = ScriptClip(Mov, "LanczosResize(200, 40, s_left, 180, 200, 40)")
ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
#ConditionalReader(Blr, "_yfoffset.txt", "s_top", false)
#25 Blurs
#Blr = Blur(Blr,1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58).Blur(1.58)
#Img = Rotate(Img, start=0, angle=0, end=99, endangle=45)
#ConditionalReader("_rotate.txt", "ol_angle_offset", false)
Overlay(Mov, Blr, x=0, y=0, opacity=1.0, mode="Blend")
ConditionalReader("_xoffset.txt", "ol_x_offset", false)
ConditionalReader("_yoffset.txt", "ol_y_offset", false)
Gavino
5th November 2011, 17:09
...
Blr = ScriptClip(Mov, "LanczosResize(200, 40, s_left, 180, 200, 40)")
ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
...
Overlay(Mov, Blr, x=0, y=0, opacity=1.0, mode="Blend")
ConditionalReader("_xoffset.txt", "ol_x_offset", false)
ConditionalReader("_yoffset.txt", "ol_y_offset", false)
The ConditionalReader call that would set s_left is not used at run-time, since its result does not contribute to the rest of the script (it is set temporarily in 'last', but not used again).
Change it to
Blr = ConditionalReader(Blr, "_xfoffset.txt", "s_left", false)
SamKook
5th November 2011, 17:53
That what I did at first, but if I do that, I get the error: "ScriptClip: Function did not return a video clip with the same width as the source clip!"
Gavino
5th November 2011, 18:08
Ah yes, I see, to get around that you also need to change the ScriptClip line to:
Blr = ScriptClip(Mov.Crop(0,0,200,40), "LanczosResize(Mov, 200, 40, s_left, 180, 200, 40)")
SamKook
5th November 2011, 19:11
Now I get the error "I don't know what "Mov" means ([ScriptClip], line 1)" and If I don't put the Mov in LanczosResize, there's no errors, but the overlay is filled with the color of the pixel specified in the coord of the Crop function(in this case 0,0)
Gavino
5th November 2011, 19:26
Hmm, it should work - I assume nothing else has changed in your script, in particular ScriptClip is still being called in the main script (not inside a function)?
To eliminate them as possible suspects, try removing the SetMTMode calls.
SamKook
5th November 2011, 19:33
Ah, it finally works if I remove the "SetMTMode(2)". If I leave it in mode 5 it also still works.
Gavino
5th November 2011, 19:42
Phew, at last!
It's never been clear to me whether ScriptClip, etc, work properly under MT (and if so, how).
Now there's evidence that, at least in some cases, it doesn't.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.