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 > General > Newbies

Reply
 
Thread Tools Search this Thread Display Modes
Old 21st February 2015, 02:47   #1  |  Link
Soulvomit
Registered User
 
Join Date: May 2012
Posts: 27
Is using Overlay to downscale technically sound?

Say I have a 720x240 YV12 clip I want to reduce horizontally by half and use the following script to do so.

Code:
A1=AVISource("1.avi").AssumeTFF.PointResize(360,240)
A2=AVISource("1.avi").AssumeTFF.FlipHorizontal.PointResize(360,240).FlipHorizontal

Overlay(a1,a2,x=0,y=0,opacity=0.5,mode="blend")

ConvertToYV24(interlaced=false,chromaresample="point")
MergeChroma(PointResize(width,height,0,1))
ConvertToRGB32
ConvertToRGB24
My rationale is with opacity=0.5 and mode="blend" I'm getting the exact average between two points and the result looks right to me, but is it really?

Last edited by Soulvomit; 23rd February 2015 at 22:15.
Soulvomit is offline   Reply With Quote
Old 21st February 2015, 10:45   #2  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 312
Quote:
Originally Posted by Soulvomit View Post
Say I have a 720x240 YV12 clip I want to reduce horizontally by half and use the following script to do so.

Code:
A1=AVISource("1.avi").AssumeTFF.PointResize(360,240)
A2=AVISource("1.avi").AssumeTFF.FlipHorizontal.PointResize(360,240).FlipHorizontal
# AssumeTFF is unnecessary

Overlay(a1,a2,x=0,y=0,opacity=0.5,mode="blend") # Merge is better here

ConvertToYV24(interlaced=false,chromaresample="point")
MergeChroma(PointResize(width,height,0,1)) # why would you shift the chroma by one pixel?
ConvertToRGB32 # this is redundant
ConvertToRGB24
Your script doesn't look wrong, but it's rather weird. What's your desired output format? RGB?

Also, is there a reason you can't just use, say, BicubicResize(360,240)?
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 23rd February 2015, 22:19   #3  |  Link
Soulvomit
Registered User
 
Join Date: May 2012
Posts: 27
Thank you for responding.

Quote:
Originally Posted by colours View Post
AssumeTFF is unnecessary
That's because that is what is assumed by default and the clip is only being processed horizontally anyway, right?

Quote:
Originally Posted by colours View Post
Merge is better here
I've compared Merge's output to that of Overlay and they look identical. Almost. I was expecting them to be exactly the same but they aren't. I've also noticed that Merge seems to be consistent, producing the same output in different colorspaces, be it YUY2 or YV24, unlike Overlay. I like this consistency and it seems it's doing its function correctly because of it but can you tell me why it's better and how it's correct?

Quote:
Originally Posted by colours View Post
why would you shift the chroma by one pixel?
this is redundant
The RGB conversion here is simply for viewing in VirtualDub with the chrominence resampled as indicated. However, if one were to do so directly with ConvertToRGB24(interlaced=false,chromaresample="point"), it would be shifted down by one, which is why the ConvertToYV24 and MergeChroma steps are required. ConvertToRGB32 then eliminates the possibility of any yellow edges one would otherwise experience if one were to ConvertToRGB24 thereafter instead. I don't know why it happens, just that it does, and it has to me. ConvertToRGB24 then just strips the alpha channel, although this isn't necessary for my purpose as 'Dub does read RGB32 but what the hey. Take a look at Gavino's post here and this thread for more. http://forum.doom9.org/showthread.ph...15#post1571315

Quote:
Originally Posted by colours View Post
Also, is there a reason you can't just use, say, BicubicResize(360,240)?
I've been thinking of and experimenting with this because I like the idea of finding the exact average between adjacent points and if they happen to be same, that point stays the same. Say if point B1 of clip 1 is the same as point A1 of clip 1, point A1 of output stays the same as 1 + 1 = 2 / 2 = 1. I don't know how to do that bicubically or bilinearly, nor do I believe they work this way either. Something like "PointResize(720,480).BicubicResize(720,240)" or "BilinearResize(720,240)" wouldn't return the original clip exactly, not the way my method with Overlay or Merge would.

Now to figure out how to make this work with something other than halves and go from 720 to 320 for example. >.> Any help here is more than welcomed.

Last edited by Soulvomit; 23rd February 2015 at 22:23.
Soulvomit is offline   Reply With Quote
Old 1st March 2015, 13:46   #4  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 312
I don't normally monitor subforums other than the two Avisynth ones so I missed this post earlier.

Quote:
Originally Posted by Soulvomit View Post
That's because that is what is assumed by default and the clip is only being processed horizontally anyway, right?
You're right, but more importantly, your source is not interlaced at all. (At least, I'm assuming so.) And the default is actually BFF, I think.

Quote:
Originally Posted by Soulvomit View Post
I've compared Merge's output to that of Overlay and they look identical. Almost. I was expecting them to be exactly the same but they aren't. I've also noticed that Merge seems to be consistent, producing the same output in different colorspaces, be it YUY2 or YV24, unlike Overlay. I like this consistency and it seems it's doing its function correctly because of it but can you tell me why it's better and how it's correct?
Merge doesn't do automatic colourspace conversions, unlike Overlay. As for accuracy, Merge and Overlay seem to both be exact for averaging two clips when both clips are YV12; I can't reproduce any differences. The main reason I said Merge was better is that it's less of a Swiss army knife than Overlay and is more optimised for the task.

Quote:
Originally Posted by Soulvomit View Post
ConvertToRGB32 then eliminates the possibility of any yellow edges one would otherwise experience if one were to ConvertToRGB24 thereafter instead. I don't know why it happens, just that it does, and it has to me. ConvertToRGB24 then just strips the alpha channel, although this isn't necessary for my purpose as 'Dub does read RGB32 but what the hey.
I don't use VirtualDub so I can't comment on what it's doing, but I'd assume VDub's author knows what he's doing and VDub can't possibly be this broken to require your strange ConvertToRGB32().ConvertToRGB24() workaround. But who knows?

Quote:
Originally Posted by Soulvomit View Post
Something like "PointResize(720,480).BicubicResize(720,240)" or "BilinearResize(720,240)" wouldn't return the original clip exactly, not the way my method with Overlay or Merge would.
This averaging method of downscaling is actually not desirable for various reasons on general images, the main one being aliasing. Sure, neither BicubicResize nor BilinearResize will reverse a nearest-neighbour upscale, but how often do you get a such a source anyway? It seems to me that you're trying to solve a problem that doesn't exist.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 14th March 2015, 04:05   #5  |  Link
Soulvomit
Registered User
 
Join Date: May 2012
Posts: 27
Quote:
Originally Posted by colours View Post
I don't normally monitor subforums other than the two Avisynth ones so I missed this post earlier.
No worries. It's probably my fault for not posting it there as this isn't really a newbie subject.

Quote:
Originally Posted by colours View Post
You're right, but more importantly, your source is not interlaced at all. (At least, I'm assuming so.) And the default is actually BFF, I think.
Yeah, they're just top fields, and you're right, the default is BFF.

Quote:
Originally Posted by colours View Post
Merge doesn't do automatic colourspace conversions, unlike Overlay. As for accuracy, Merge and Overlay seem to both be exact for averaging two clips when both clips are YV12; I can't reproduce any differences. The main reason I said Merge was better is that it's less of a Swiss army knife than Overlay and is more optimised for the task.
That's weird. How are you comparing them? I don't get bit-identical results in YV12. What I do is open two of the same frames in Photoshop, set the top layer's property to Difference, Merge Down and use the paint bucket tool (Anti-alias unchecked). If the area is filled completely, there are absolutely no differences, otherwise there are.

Quote:
Originally Posted by colours View Post
I don't use VirtualDub so I can't comment on what it's doing, but I'd assume VDub's author knows what he's doing and VDub can't possibly be this broken to require your strange ConvertToRGB32().ConvertToRGB24() workaround. But who knows?
No, the problem isn't with VirtualDub at all. The fault lies on AviSynth's ConvertToRGB24 on YV24, which is why ConvertToRGB32 is used first.

Quote:
Originally Posted by colours View Post
This averaging method of downscaling is actually not desirable for various reasons on general images, the main one being aliasing. Sure, neither BicubicResize nor BilinearResize will reverse a nearest-neighbour upscale, but how often do you get a such a source anyway? It seems to me that you're trying to solve a problem that doesn't exist.
Can you elaborate on aliasing? I don't experience any of it downscaling to half the resolution, neither vertically nor horizontally, unless of course when two points are exactly the same. Anyway, the point of that last script was just to illustrate how suggesting Bicubic wouldn't be useful for what I was trying to achieve. Now I see you knew that and you probably meant it as something more along the lines of "Why bother with that? Just use this instead.".

Last edited by Soulvomit; 14th March 2015 at 04:08.
Soulvomit is offline   Reply With Quote
Old 14th March 2015, 11:37   #6  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 312
Quote:
Originally Posted by Soulvomit View Post
That's weird. How are you comparing them? I don't get bit-identical results in YV12. What I do is open two of the same frames in Photoshop, set the top layer's property to Difference, Merge Down and use the paint bucket tool (Anti-alias unchecked). If the area is filled completely, there are absolutely no differences, otherwise there are.
I don't have Photoshop, but I'm reasonably sure it can't open YCbCr images directly. There must be a conversion to RGB somewhere, and I'm guessing whatever is being used for this conversion is nondeterministic.

Also, I was using Avisynth+, which had rewritten versions of Merge and Overlay. It's quite possible that upstream Avisynth had slightly broken implementations of these core filters. Anyhow, there's still Average, mt_average, mt_lutxy, and very many other filters for the simple task of averaging two clips within Avisynth, so in case you don't trust the internal filters, there's something else to try!

Quote:
Originally Posted by Soulvomit View Post
No, the problem isn't with VirtualDub at all. The fault lies on AviSynth's ConvertToRGB24 on YV24, which is why ConvertToRGB32 is used first.
My statement was more like "I don't believe either VirtualDub or Avisynth could mess up something this basic"; in other words, I was suspecting the veracity of your claim. It's not that I think you're deliberately lying, but it's entirely possible that something's messed up on your end somehow.

Quote:
Originally Posted by Soulvomit View Post
Anyway, the point of that last script was just to illustrate how suggesting Bicubic wouldn't be useful for what I was trying to achieve. Now I see you knew that and you probably meant it as something more along the lines of "Why bother with that? Just use this instead.".
I'm still not sure what exactly you were trying to achieve! If your source is "just top fields", why not interpolate it to full height instead of halving the width? Besides, 3:2 is not a common display aspect ratio, which makes this even more questionable.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!

Last edited by colours; 14th March 2015 at 11:41.
colours is offline   Reply With Quote
Old 14th March 2015, 18:29   #7  |  Link
Soulvomit
Registered User
 
Join Date: May 2012
Posts: 27
Quote:
Originally Posted by colours View Post
I don't have Photoshop, but I'm reasonably sure it can't open YCbCr images directly. There must be a conversion to RGB somewhere, and I'm guessing whatever is being used for this conversion is nondeterministic.
That conversion was done the same way you see up there part of my initial script.
Quote:
Originally Posted by colours View Post
Also, I was using Avisynth+, which had rewritten versions of Merge and Overlay. It's quite possible that upstream Avisynth had slightly broken implementations of these core filters. Anyhow, there's still Average, mt_average, mt_lutxy, and very many other filters for the simple task of averaging two clips within Avisynth, so in case you don't trust the internal filters, there's something else to try!
Thanks for the homework, I'll look into AviSynth+ along with those other filters.
Quote:
Originally Posted by colours View Post
My statement was more like "I don't believe either VirtualDub or Avisynth could mess up something this basic"; in other words, I was suspecting the veracity of your claim. It's not that I think you're deliberately lying, but it's entirely possible that something's messed up on your end somehow.
There probably was something wrong with whatever version or build of AviSynth I had three years ago as I can't seem to reproduce the problem with the same clip I was working on at the time now but, believe me, it was there. Adding an unnecessary function to a script is absurd and it would only serve to slow things down and I wouldn't like that.
Quote:
Originally Posted by colours View Post
I'm still not sure what exactly you were trying to achieve! If your source is "just top fields", why not interpolate it to full height instead of halving the width? Besides, 3:2 is not a common display aspect ratio, which makes this even more questionable.
My goal is to downscale to any resolution with all points of a clip evenly considered but this only works with PointResize and Merge going down by 50%. Three to two isn't my target aspect ratio, no. That just happened to be the ratio after downscaling my clip.
Quote:
Originally Posted by Soulvomit View Post
Now to figure out how to make this work with something other than halves and go from 720 to 320 for example. >.> Any help here is more than welcomed.
That was an example of a target resolution, 320x240 for my iPod Video. Don't judge me.
Soulvomit is offline   Reply With Quote
Reply

Tags
blend, downscale, opacity, overlay, resize

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 13:04.


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