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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th October 2008, 03:41   #1  |  Link
Avisynth_challenged
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.
Avisynth_challenged is offline   Reply With Quote
Old 19th October 2008, 03:49   #2  |  Link
JoeShrubbery
Registered User
 
Join Date: Jun 2002
Posts: 81
Push comes to shove, you can always ConvertToRGB32()
JoeShrubbery is offline   Reply With Quote
Old 19th October 2008, 05:33   #3  |  Link
Sagekilla
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)
Try using Spline16Resize(720,300,0,79,0,-101). It shouldn't do any resizing at all, but only do the cropping.
__________________
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.
Sagekilla is offline   Reply With Quote
Old 19th October 2008, 07:34   #4  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
@Sagekilla,

Yes, it won't resize the luma plane but will resample the chroma planes across the needed 1 pixel.
IanB is offline   Reply With Quote
Old 19th October 2008, 08:12   #5  |  Link
Avisynth_challenged
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
Avisynth_challenged is offline   Reply With Quote
Old 16th August 2013, 11:29   #6  |  Link
Jeroi
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.
Jeroi is offline   Reply With Quote
Old 16th August 2013, 11:43   #7  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by Jeroi View Post
crop does not support YV12
What are you smoking?
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 16th August 2013, 23:08   #8  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Crop does not support YV12 if any of left, top, right or bottom are an odd number.
IanB is offline   Reply With Quote
Old 16th August 2013, 23:58   #9  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Quote:
Originally Posted by IanB View Post
Crop does not support YV12 if any of left, top, right or bottom are an odd number.
Of course. Yet that condition was left out of the previous post.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 17th August 2013, 00:59   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by IanB View Post
Crop does not support YV12 if any of left, top, right or bottom are an odd number.
That's true, but it's a rather back-to-front way of putting it.
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).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 17th August 2013, 02:20   #11  |  Link
gyth
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)
Why doesn't b1 work?
gyth is offline   Reply With Quote
Old 17th August 2013, 02:56   #12  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
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.
StainlessS is offline   Reply With Quote
Old 19th August 2013, 14:52   #13  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
Quote:
Originally Posted by StainlessS View Post
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).
There's nothing that stops you from cropping an YV12 image in the middle of a chroma sample, you just have to decide what to do with the leftover "half" sample in a consistent way. Avisynth (and a lot of other software) avoids this decision by not letting you do that, but that doesn't mean there's some divine decree that states that Thou Shalt Not Create Odd-Dimensioned YV12 Images. If you want to handle it, you can, it's just easier not to.

As Avery Lee wrote back in 2004:
Quote:
I've been trying for some time to get YV12 support working perfectly, but at this point it looks like a wash. The problem is that different drivers and applications are inconsistent about how they treat or format odd-width and odd-height YV12 images. Some support it by truncating the chroma planes (dumb). Some do that and have unused space betweeen the Cr and Cb planes (weird). Many simply crash (very dumb). And a few simply don't support it (lame but pragmatic). YVU9 tends to be even more broken. Arrrgh.

Now, if people had sense, they would have handled this the way that MPEG and JPEG do, and simply require that the bitmap always be padded to the nearest even boundaries and that the extra pixels be ignored on decoding. Unfortunately, no one seems to have bothered to ever define the YV12 format properly in this regard, and thus we have massive confusion.
TheFluff is offline   Reply With Quote
Old 19th August 2013, 16:35   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
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 ???
StainlessS is offline   Reply With Quote
Old 25th August 2013, 09:57   #15  |  Link
bxyhxyh
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.
bxyhxyh is offline   Reply With Quote
Old 25th August 2013, 12:59   #16  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by bxyhxyh View Post
According to this thread, this will work without loss(?) on Avisynth 2.6, if source is YV12.
It 'works' to the extent of not producing an error message, but it introduces a chroma shift, since it retains the original chroma pixels without resampling.

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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Reply


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 00:32.


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