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. |
19th October 2008, 03:41 | #1 | Link |
Registered User
Join Date: Dec 2007
Posts: 117
|
Trying to crop YV12 source
Hello all,
I've been trying to trim letterbox borders from a 720x480 progressive YV12 Huffyuv AVI (encoded w/ ffdshow). The problem is that the image falls into an area where I can't trim directly. Ideally I'd use: crop = source.crop(0,79,-0,-101) return crop but I get the error "Crop: YV12 images can only be cropped by even numbers (top)." My next idea was to do this: crop = source.addborders(0,1,0,1).crop(0,80,-0,-102) return crop This opened without error, and "addborders" did resize the source to 720x482 as expected... but instead of adding one line to the top and one line to the bottom, it added two lines to the bottom. The source image was not shifted down by 1 line as I was expecting. So I still can't crop the borders because their edges still fall on odd numbered lines. Avisynth is so amazing, and I have used it to do what seemed impossible in processing digital video... so I'm surprised that this simple task can't be done in a straightforward fashion. Or maybe it's a PEBKAC error, so I thought I'd ping on the Doom9 experts before I try anything else. |
19th October 2008, 05:33 | #3 | Link |
x264aholic
Join Date: Jul 2007
Location: New York
Posts: 1,752
|
Figured out the problem. It turns out since you're working in YV12, AddBorders() will only pad if you use a mod2 padding in either direction: AddBorders(0,1,0,1) does nothing.
Code:
s = ColorBars(720,300) bd = s.AddBorders(0,79,0,101).ConvertToYV12() s = s.ConvertToYV12() a = bd.Spline16Resize(720,300,0,79,0,-101) b = bd.AddBorders(0,1,0,1).Crop(0,80,0,-102) Interleave(s,a,b)
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame. Last edited by Sagekilla; 19th October 2008 at 05:39. |
19th October 2008, 08:12 | #5 | Link |
Registered User
Join Date: Dec 2007
Posts: 117
|
Thanks for the responses. So my cropping problem is due to the source being YV12. Peviously the source was in YUY2 (which can be cropped by odd numbers on the top and bottom), but was converted to YV12 in order to use a chroma derainbowing script.
I should also add that I'm planning on doing the following operations on the derainbowed YV12 source (but I'm not sure yet in what order, suggestions on that would be most appreciated): 1. cropping (720x480 -> 720x300), 2. antialiasing, 3. sharpening, 4. upscaling (720x300 -> 720x380), (Question: could 3 & 4 be combined into a single step using LimitedSharpen?) 5. addborders(0,50,0,50) As you can probably guess, my goal is to produce an avi suitable for encoding anamorphic 16:9 MPEG2 for NTSC DVD. I suppose that I have two choices at this point... (1). Go back a step in my project and crop my YUY2 source before converting to YV12 then derainbowing. (2). Continue working with the derainbowed YV12 source, but, in the 5-step workflow described above, skip over the initial cropping step and, instead, crop the image during the upscaling step. So that's a rough sketch of where I'm at. Thanks to all for reading and especially for responding |
16th August 2013, 11:29 | #6 | Link |
Registered User
Join Date: Feb 2008
Location: Finland
Posts: 141
|
Just to answer this thread altho it is old because I had similar issues:
Instead of Crop(left,top,-right,-bottom) and then resize function because crop does not support YV12 if any of left, top, right or bottom are an odd number, so use: Lanczos4Resize(720, 576, left, top, -right, -bottom) This will work with YV12 and no need to convert to rgb32. The filter will crop and then use target resolution to resize the image. I also suggest that you use this line as last filter on your skript, otherways interlacing will be blend at resize time and make deinterlacing poorer image. Still tho I hope that someone would update crop() to support YV12 odd lines also. Last edited by Jeroi; 17th August 2013 at 11:36. |
16th August 2013, 11:43 | #7 | Link |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
__________________
Groucho's Avisynth Stuff |
16th August 2013, 23:58 | #9 | Link |
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
|
Of course. Yet that condition was left out of the previous post.
__________________
Groucho's Avisynth Stuff |
17th August 2013, 00:59 | #10 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
To me, it seems clearer to say that Crop does not support left, right, top or bottom being an odd number when the input is YV12 (and that's more or less what the error message says if you try to do it). |
|
17th August 2013, 02:20 | #11 | Link |
Registered User
Join Date: Sep 2011
Posts: 86
|
What about something like this?
Code:
s = ColorBars(720,300) bd = s.AddBorders(0,79,0,101).ConvertToYV12() s = s.ConvertToYV12() a = bd.Spline16Resize(720,300,0,79,0,-101) l = bd.converttoy8.crop(0,79,0,-101).ConvertToYV12() c1 = bd.Crop(0,80,0,-102).Spline16Resize(720,300,0,-1,0,299) b1 = mergeChroma(l,c1) c2 = bd.Crop(0,80,0,-102).Spline16Resize(720,300,0,-.5,0,299.5) b2 = mergeChroma(l,c2) Interleave(s,a,b2) #.crop(0,180,0,0) |
17th August 2013, 02:56 | #12 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
In my humble opinion, it is not eg crop that does not support YV12, it that YV12 does not support
cropping in the middle of chroma samples. Two half persons, rarely perform as well as a single whole person (No matter how clean the cut).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 17th August 2013 at 03:18. |
19th August 2013, 14:52 | #13 | Link | ||
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
As Avery Lee wrote back in 2004: Quote:
|
||
19th August 2013, 16:35 | #14 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
I stand corrected - perhaps two half persons do frequently perform as well as a whole person.
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? |
25th August 2013, 09:57 | #15 | Link |
Registered User
Join Date: Dec 2011
Posts: 354
|
According to this thread, this will work without loss(?) on Avisynth 2.6, if source is YV12.
Code:
ConvertToYV24(chromaresample = "point") MergeChroma(PointResize(width, height, 0, 1)) Crop(0, 79, 0, -101) ConverttoYV12(chromaresample = "point") Last edited by bxyhxyh; 25th August 2013 at 10:13. |
25th August 2013, 12:59 | #16 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
For cropping at odd boundaries, chroma resampling is required, since the chroma sampling positions are different from the original. This can be done using a resizer (eg as in post #6), or by conversion to and from YV24 with chromaresample defaulted or set to something other than "point". The 'lossless' aspect in the other thread only applies when you remove the Crop() from the script. |
|
|
|