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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th July 2006, 23:57   #1  |  Link
mrwhitethc
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.
mrwhitethc is offline   Reply With Quote
Old 19th July 2006, 01:03   #2  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
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
The function TryThis() will crop an F percent window from the centre of the image and resize it back to the original size. Calling it inside Animate allows for a smooth transition over a range of frames. In this case frames 0 to 999 and 2000 to the end are untouched. Frames 1000 to 1799 are windowed 50%, frames 1800 to 1899 smoothly transition from 50% to 100% windowing and frames 1900 to 1999 are the full 100% window.

Adjust the crop parameter formulae of the resize to suit your needs, you probably want Ox = 0 for a left edge basis.
IanB is offline   Reply With Quote
Old 19th July 2006, 09:31   #3  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
@ 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!)
Didée is offline   Reply With Quote
Old 19th July 2006, 10:45   #4  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
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);
  }
}
The optimization fails to test for YUV restrictions when substituing a crop. It will be fixed for the next release.

:EDIT: Fixed in 2.5.7 CVS

Last edited by IanB; 19th July 2006 at 12:08.
IanB is offline   Reply With Quote
Old 19th July 2006, 11:10   #5  |  Link
squid_80
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
..gives the error: "Crop: YUV images can only be cropped by even numbers (left side)."

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.
squid_80 is offline   Reply With Quote
Old 19th July 2006, 12:13   #6  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,563
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.
foxyshadis is offline   Reply With Quote
Old 19th July 2006, 12:30   #7  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
@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.
IanB is offline   Reply With Quote
Old 21st July 2006, 13:17   #8  |  Link
mrwhitethc
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
mrwhitethc is offline   Reply With Quote
Old 21st July 2006, 14:32   #9  |  Link
Mr_Odwin
FAVC Man
 
Mr_Odwin's Avatar
 
Join Date: Nov 2005
Posts: 411
There's no need to resize twice. Cropping the 8 pixels from the bottom and then resizing to 720x480 gives the same effect but saves quality and will be quicker.
Mr_Odwin is offline   Reply With Quote
Old 22nd July 2006, 17:48   #10  |  Link
mrwhitethc
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.
mrwhitethc is offline   Reply With Quote
Old 23rd July 2006, 09:08   #11  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
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
IanB is offline   Reply With Quote
Old 26th July 2006, 00:45   #12  |  Link
mrwhitethc
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
Because of the resize to DVD res; was that zooming in on the 1080 the 480 video? Thanks again.
mrwhitethc is offline   Reply With Quote
Old 27th July 2006, 04:39   #13  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
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
IanB is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:17.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.