Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
17th July 2006, 23:57 | #1 | Link |
Registered User
Join Date: Oct 2002
Posts: 96
|
Weird crop request
Ok here goes, I have a movie in TS format, that I would like to put on DVD, no big deal, it's already 16:9 MPEG2 & AC3 5.1 sound. Resize to 720x480, no problem right? Well during the movie there is a single scene I would like to zoom to a specific part on the left, cutting off say 1/2 the screen to the right, keeping the aspec ratio, 16:9, and slowly zoom back out to the full size again. Anyone know how I would create this effect with Avisynth and a filter? I suppose I could cut the small scene out, it has a nice black cut at the start and end and isn't terriblly important but I would like to keep it. Thanks for all the help.
|
19th July 2006, 01:03 | #2 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
Code:
Function TryThis(clip Clip, float f) { # Select an F% window from the centre of an image Clip Ox = (100-f) / 200.0 * Width() Oy = (100-f) / 200.0 * Height() Dx = f / 100.0 * Width() Dy = f / 100.0 * Height() Return LanczosResize(Width(), Height(), Ox, Oy, Dx, Dy) } ...Source(...) A=Trim(0, 999) # Bit before C=Trim(2000, 0) # Bit after Animate(1800, 1899, "TryThis", 50.0, 100.0) # Transition Trim(1000, 1999) # Bit fiddled with A + Last + C # Paste back together Adjust the crop parameter formulae of the resize to suit your needs, you probably want Ox = 0 for a left edge basis. |
19th July 2006, 09:31 | #3 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
@ IanB
On request, lately I tried to make a simple Zoom-around-in-a-big-frame function, posted >here<, which is quite similar to your function here. However, ZoomedTravel() at times bails out with "Crop: YUV images can only be cropped by even numbers". How can that be, when the cropping is done by a resizer? I think that function is scripted correctly, but perhaps I did overlook something?
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
19th July 2006, 10:45 | #4 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
Opps! Now heres a nasty bug
Code:
PClip CreateResizeH(PClip clip, double subrange_left, double subrange_width, int target_width, ResamplingFunction* func, IScriptEnvironment* env) { const VideoInfo& vi = clip->GetVideoInfo(); if (subrange_left == 0 && subrange_width == target_width && subrange_width == vi.width) { return clip; } else if (subrange_left == int(subrange_left) && subrange_width == target_width && subrange_left >= 0 && subrange_left + subrange_width <= vi.width) { return new Crop(int(subrange_left), 0, int(subrange_width), vi.height, 0, clip, env); } else { return new FilteredResizeH(clip, subrange_left, subrange_width, target_width, func, env); } } :EDIT: Fixed in 2.5.7 CVS Last edited by IanB; 19th July 2006 at 12:08. |
19th July 2006, 11:10 | #5 | Link |
Registered User
Join Date: Dec 2004
Location: Melbourne, AU
Posts: 1,963
|
The resizers check the cropping arguments and if the cropped video size matches the requested target size and the cropping arguments are ints, they skip resizing and call crop directly. Unfortunately it doesn't always work, e.g.
Code:
colorbars(pixel_type="yv12") bilinearresize(636,480,1,0,-3,0) # 640-1-3=636, no resizing necessary As a workaround I sometimes add a very small amount to one of the cropping arguments, for example change the line above to bilinearresize(636,480,1.00001,0,-3,0). Oh, IanB found it. nevermind. |
19th July 2006, 12:13 | #6 | Link |
Angel of Night
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
|
I don't know if you run Debug avisynth often, but I meant to tell you, I always get this error in resample_functions.cpp:
#ifdef DEBUG env->ThrowError("Resizer: [Internal Error] Got Zero Coefficient"); #endif Not sure what it means, it runs fine in release mode. (So I just called it X_DEBUG to kill the error.) EKG.avs seems to cause it, I'd have to play around to see what else does. |
19th July 2006, 12:30 | #7 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
@foxyshadis, Thanks, I had forgotten about that error. It means the resample pattern generator has produced a set of pixel coefficients that sum to zero. It usually happens at the left/top edge and causes a dark first row/column in the production version.
|
21st July 2006, 13:17 | #8 | Link |
Registered User
Join Date: Oct 2002
Posts: 96
|
Wow you know how to make a guys brain hurt First off, thanks guys for the initial info, here's some more to fill in some questions I have. First off a screen cap it's HD material @ 1280x1088, which means for a proper ratio it needs to be expanded to 1920x1088 and cropped 8 from the bottom to 1920x1080 then resized for dvd 720x480, but everyone knows that.
so would that be: BilinearResize(1920,1088).Crop(0,0,0,-8).BilinearResize(720,480) but then wouldn't the script from above be zooming into the 720x480 portion? Or would I have to do 3 trim funtions, the original resize, the zoom and then back to the original resize? And how would i go about to get the right frame numbers for the trims? Thanks again |
22nd July 2006, 17:48 | #10 | Link |
Registered User
Join Date: Oct 2002
Posts: 96
|
AWSOME IT WORKED, thank you IanB and all others, this worked like a charm, now my only other question is, does this function, the IanB one, zoom in on the original 1280x1088 image or is it zooming in on the resized 720x480 image? Anyway you guys made my day, thanks again.
|
23rd July 2006, 09:08 | #11 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
The optional 4 subpixel crop parameters of the resizers apply to the input image size. So for your 1280x1088 example you may need to apply some scaling into the Ox/Dx calculations depending on the effect you want to project.
It cost you nothing to tweak the script and examine the result. It is usually called trial and error. Make it your best friend |
26th July 2006, 00:45 | #12 | Link |
Registered User
Join Date: Oct 2002
Posts: 96
|
I don't think I phrased that right last time. I messed around with and was finally able to zoom in & then expand on the secion I needed, this is the .avs I used:
Code:
LoadPlugin("DGDecode.dll") Function TryThis(clip Clip, float f) { # Select an F% window from the centre of an image Clip Ox = 0 Oy = (145-f) / 290.0 * Height() Dx = f / 145.0 * Width() Dy = 0 Return LanczosResize(Width(), Height(), Ox, Oy, Dx, Dy) } mpeg2source("test.d2v") Loadplugin("decomb.dll") Telecide(order=1,guide=1,post=2,vthresh=30) Decimate() Crop(0,0,0,-32) AddBorders(0, 16, 0, 16, $000000) BilinearResize(720,480) A=Trim(0, 33629) # Bit before C=Trim(34001, 0) # Bit after Animate(33807, 33907, "TryThis", 50.0, 145.0) # Transition Trim(33630, 34000) # Bit fiddled with A + Last + C # Paste back together |
27th July 2006, 04:39 | #13 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
Watch setting Dy=0 some versions of Avisynth don't default this parameter correctly. From version 2.5.7 the behaviour is explicitly defined to be the same as crop() for Dx, Dy <= 0.0, i.e Dy = (Dy <= 0) ? Width()+Dy : Dy
Also with a bit more clever mathematics and script shuffling you could avoid resizing the zoomed part of your clip twice. Also consistant use of 1 resizer may help to maintain the look and feel of your encodes. Hint: global int TargetWidth = 720 global int TargetHeight = 480 |
Thread Tools | Search this Thread |
Display Modes | |
|
|