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. |
![]() |
#1 | Link |
Movie buff & shine
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
|
Lossless YV12-YUY2-YV12
Hi,
Just finished with a filter that some people might find useful. It's a filter that allows YV12 video to be converted to YUY2 (to meet input requirements for a filter like ConvertFPS, or a program like Premiere Pro), and then back to YV12 without loss. It works by storing YV12 chroma in YUY2 and filling the remaining chroma with a BlankClip. It then converts back by cropping the BlankClip out and restoring the original chroma. Code:
Function YV12toYUY2 (clip Last) { Y = Tweak (sat = 0, coring = false).ConvertToYUY2 () U = StackVertical (UtoY (), BlankClip (UtoY ())).ConvertToYUY2 () V = StackVertical (VtoY (), BlankClip (VtoY ())).ConvertToYUY2 () Return YtoUV (U, V, Y) } Function YUY2toYV12 (clip Last) { Y = Tweak (sat = 0, coring = false).ConvertToYV12 () U = UtoY ().Crop (0, 0, Y.Width / 2, Y.Height / 2).ConvertToYV12 () V = VtoY ().Crop (0, 0, Y.Width / 2, Y.Height / 2).ConvertToYV12 () Return YtoUV (U, V, Y) } Code:
#YV12 source YV12toYUY2 () ConvertFPS (25) YUY2toYV12 () Code:
Subtract (clip, clip.YV12toYUY2 ().YUY2toYV12 ())
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone (). |
![]() |
![]() |
![]() |
#2 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Bah, just when I thought I had some grasp on the colorspace stuff.
Doesn't YV12 use 4:2:0 subsampling and YUY2 4:2:2? Isn't everything with 4:2:0 representable with 4:2:2, and if so, why is there loss going from YV12->YUY2->YV12? (I can see that there is loss with AviSynth's built-in conversion routines, but I don't understand where that loss comes from.) Last edited by stickboy; 8th January 2006 at 23:49. |
![]() |
![]() |
![]() |
#3 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
BTW, your approach will leave the frames looking very wrong, which would be bad if you ran any filters on the video between colorspace conversions.
A better approach might be something like: Code:
function YV12toYUY2(clip last) { y = Tweak(sat=0, coring=false).ConvertToYUY2() uy = UtoY() vy = VtoY() u = Interleave(uy, uy).AssumeFieldBased().Weave().ConvertToYUY2() v = Interleave(vy, vy).AssumeFieldBased().Weave().ConvertToYUY2() return YtoUV(u, v, y) } function YUY2toYV12(clip last) { y = Tweak(sat=0, coring=false).ConvertToYV12() u = UtoY().AssumeFrameBased().SeparateFields().SelectEven().ConvertToYV12() v = VtoY().AssumeFrameBased().SeparateFields().SelectEven().ConvertToYV12() return YtoUV(u, v, y) } Last edited by stickboy; 8th January 2006 at 23:55. |
![]() |
![]() |
![]() |
#4 | Link | |
Moderator
![]() Join Date: Nov 2001
Location: Netherlands
Posts: 6,354
|
Quote:
http://www.avisynth.org/Sampling |
|
![]() |
![]() |
![]() |
#5 | Link | |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Quote:
Should there be an option to ConvertToYUY2() and ConvertToYV12() to allow point-sampling? |
|
![]() |
![]() |
![]() |
#6 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
In 2.6 we are using the resizer core to resample the chroma size between different subsampling regimes. Currently it is fixed to only use the bicubic method, but there an intention to make this user selectable.
|
![]() |
![]() |
![]() |
#8 | Link |
Movie buff & shine
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
|
Just made me think... Can we expect a ConvertBackToYV12 () for material that's undergone YV12->RGB32 conversions in the next release?
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone (). |
![]() |
![]() |
![]() |
#9 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
@actionman133,
The 2.6 core has direct RGB<->YV24 (4:4:4) routines (prior versions stuffed around going via YUY2 (Also 2.6 has direct YUY2<->YV16 (4:2:2))). As mentions above, the conversion between various planar formats uses the resizer core, currently this is only bicubic but there is an intention to make it user selectable. Almost certainly there will not be an explicit ConvertBackToYV12() verb but the functionality will be very easy to achieve. ConvertBackToYUY2() works by only sampling chroma from the left pixel of a RGB pair which on the ConvertToRGB() pass was directly calculated, the ignored right pixel of the pair was interpolated from the chroma on either side of it. Thus on repeated conversions there is no successive blurring. For ConvertBackToYV12() functionality, horizontally the same left only logic can be used but vertically you must always take the average of the top and bottom pixel otherwise you introduce a 0.5 pixel chroma positional shift. Thus for lossless RGB<->YV12 conversions it is the forward conversion (RGB->YV12) that must not vertically interpolate, so you really need a ConvertToRGBBack() as well. IanB |
![]() |
![]() |
![]() |
#10 | Link | |
Squeeze it!
Join Date: Oct 2003
Location: Germany
Posts: 472
|
Quote:
http://forum.doom9.org/showthread.ph...787#post762787 ? |
|
![]() |
![]() |
![]() |
#11 | Link |
Movie buff & shine
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
|
Any chance we'll be seeing Y-only format for black and white and dealing with UtoY () and VtoY ()? I find it a little frustrating that my YV12 video needs height to be a multiple of 4 to get the chroma channels.
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone (). |
![]() |
![]() |
![]() |
#12 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
@incredible, Internally yes.
@actionman133, Yes Y8 format is supported in version 2.6 see this thread Proposal for AviSynth 2.6 |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|