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 25th April 2014, 22:47   #41  |  Link
filler56789
SuperVirus
 
filler56789's Avatar
 
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,347
Hummm, would it be "worth the effort" to (somehow) force a conversion to YUY2 or YV**, for dealing with «uncommon» types of chroma subsampling?

Example: http://forum.videohelp.com/attachmen...2-2x1-2x1).jpg

OT: ImageSource() works fine with RGB JPEGs (even the weirdest ones )

Last edited by filler56789; 25th April 2014 at 23:10.
filler56789 is offline   Reply With Quote
Old 26th April 2014, 00:01   #42  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
I see nothing special in that JPEGs: usual YV12.
As for conversions – see second example in first post. For unsupported chroma just replace UToY8/VToY8 by calls to JpegSource for planes 1 and 2.

JpegSource also works fine with RGB JPEGs – no problems so far.
SEt is offline   Reply With Quote
Old 26th April 2014, 00:53   #43  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,646
Quote:
Originally Posted by SEt View Post
I see nothing special in that JPEGs: usual YV12.
Actually, filler56789 linked to a 4:4:0 encoded JPEG.

-----------

@filler56789

To convert 4:4:0 JPEGs to 4:4:4 (YV24) do something like this:
Code:
source = "image.jpg"

Y = JpegSource(source, channel=0)
U = JpegSource(source, channel=1).Spline36Resize(Y.width, Y.height)
V = JpegSource(source, channel=2).Spline36Resize(Y.width, Y.height)

YToUV(U,V,Y)

#ConvertToRGB24(matrix="PC.601") #Only needed if you want RGB output
Since Avisynth does not support 4:4:0 converting to YV24 is the better choice, with YV12 and YV16 you'll loose half the horizontal resolution in the chroma planes.
Reel.Deel is offline   Reply With Quote
Old 26th April 2014, 02:23   #44  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
Oh, indeed it's actually 440. My other tool looked only at maximum sampling (2x2) and incorrectly guessed that it's 420. JpegSource detects this correctly, but I guess it also can get some more intellect in next version in case someone decides to use such redundant sampling with evil numbers like 3.
SEt is offline   Reply With Quote
Old 26th April 2014, 02:40   #45  |  Link
filler56789
SuperVirus
 
filler56789's Avatar
 
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,347
@Reel.Deel — your recipe works ~ many thanks 4 that.

Code:
Spline36Resize()
In this particular case at least, shouldn't PointResize() be sufficient and adequate?

Last edited by filler56789; 26th April 2014 at 02:43.
filler56789 is offline   Reply With Quote
Old 26th April 2014, 02:46   #46  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
Quote:
Originally Posted by filler56789 View Post
Code:
Spline36Resize()
In this particular case at least, shouldn't PointResize() be sufficient and adequate?
It all depends on how much you treasure chroma. In case you don't care (like many JPEG decoders) – yes, PointResize is enough.
SEt is offline   Reply With Quote
Old 26th April 2014, 03:53   #47  |  Link
filler56789
SuperVirus
 
filler56789's Avatar
 
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,347
Quote:
Originally Posted by SEt View Post
It all depends on how much you treasure chroma. In case you don't care (like many JPEG decoders) – yes, PointResize is enough.
Thanks for the lesson, sir, I really need to drink more coffee

Regarding the Wiki...... I think it should include more "real-life examples" ---

--- based on the last script posted by Reel.Deel, here is what works for a "pathological" RGB file created w/ cjpeg.exe:

Code:
source = "zRGBsamplefile.jpg"

G = JpegSource(source, rec=0, channel=1)
R = JpegSource(source, rec=0, channel=0).Spline36Resize(G.width, G.height)
B = JpegSource(source, rec=0, channel=2).Spline36Resize(G.width, G.height)

MergeRGB(R, G, B, "RGB24")
As you can see, it's rather convoluted when compared to:

Code:
ImageSource("zRGBsamplefile.jpg", fps=25, end=249)
filler56789 is offline   Reply With Quote
Old 26th April 2014, 04:51   #48  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,646
Quote:
Originally Posted by filler56789 View Post
Regarding the Wiki...... I think it should include more "real-life examples"
When I get some time I'll gladly add some more examples. One good thing about the Wiki is that anyone can add useful information.


Quote:
Originally Posted by filler56789 View Post
--- based on the last script posted by Reel.Deel, here is what works for a "pathological" RGB file created w/ cjpeg.exe:

Code:
source = "zRGBsamplefile.jpg"

G = JpegSource(source, rec=0, channel=1)
R = JpegSource(source, rec=0, channel=0).Spline36Resize(G.width, G.height)
B = JpegSource(source, rec=0, channel=2).Spline36Resize(G.width, G.height)

MergeRGB(R, G, B, "RGB24")
That example is wrong. The following examples are correct (and identical).

Simple:
Code:
JpegSource("RGBimage.jpg")
MergeRGB(last, UToY8(), VToY8(), "RGB24")
Convoluted:
Code:
JpegSource("RGBimage.jpg")

R =  last
G = UToY8()
B = VToY8()

MergeRGB(R,G,B, pixel_type="RGB24")

Quote:
Originally Posted by filler56789 View Post
As you can see, it's rather convoluted when compared to:

Code:
ImageSource("zRGBsamplefile.jpg", fps=25, end=249)
You know you can always make a function and then autoload it.
Something like this:
Code:
function JpegSourceRGB(string file, int "rec", int "length", float "fps_num", int "fps_den")
{
JpegSource(file=file, rec=rec, length=length, fps_num=fps_num, fps_den)
MergeRGB(last, UToY8(), VToY8(), "RGB24")
}
Then use it like this and be done with it:
Code:
JpegSourceRGB("RGBimage.jpg")
Reel.Deel is offline   Reply With Quote
Old 26th April 2014, 05:46   #49  |  Link
filler56789
SuperVirus
 
filler56789's Avatar
 
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,347
Quote:
Originally Posted by Reel.Deel View Post
That example is wrong.
It does work for the file I have, so how on Earth can it "be wrong"?

Quote:
The following examples are correct (and identical).

Simple:
Code:
JpegSource("RGBimage.jpg")
MergeRGB(last, UToY8(), VToY8(), "RGB24")
OK, if I try to open the script above in VirtualDub,
I receive the following error message:

Code:
Avisynth open failure:
JpegSource: unsupported multi-channel configuration - use one channel mode
Conclusion: don't assume all RGB Jpeg files are "4:4:4".

More sample files:

http://forum.videohelp.com/attachmen...ene421-ycc.jpg

http://forum.videohelp.com/attachmen...ene421-rgb.jpg

http://forum.videohelp.com/attachmen.../Nene3xRGB.jpg

http://forum.videohelp.com/attachmen.../Nene3xYCC.jpg

Last edited by filler56789; 26th April 2014 at 10:20. Reason: add links, remove redundancy
filler56789 is offline   Reply With Quote
Old 26th April 2014, 16:25   #50  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
^ these are good examples of "evil" JPEGs.

While I might support passing 444 RGB JPEGs to Avisynth as RGB24, here you'd have to do the conversions yourself. The idea of this source filter is to provide the actual data encoded in image without any colorspace conversions or resizes (that are usually really poor quality in decoders), and Avisynth colorspace support is quite limited.

Reel.Deel's idea is correct: you can write script function that does required resizes automatically. Just get max width and height and resize all components to them. (Well, in reality it's a bit more complicated as you would also need to account for components cut in the middle of sampling block.) Is it RGB, YUV or some other colorspace file you's have to know yourself, as there is no way now for plugin to pass such metainformation to script.
SEt is offline   Reply With Quote
Old 26th April 2014, 16:30   #51  |  Link
wOxxOm
Oz of the zOo
 
Join Date: May 2005
Posts: 208
Quote:
Originally Posted by SEt View Post
there is no way now for plugin to pass such metainformation to script.
FFMS2 sets global variables for that. You can also make some auxiliary function(s) that return this metainfo.
wOxxOm is offline   Reply With Quote
Old 26th April 2014, 16:42   #52  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,646
Quote:
Originally Posted by filler56789 View Post
It does work for the file I have, so how on Earth can it "be wrong"?....
....Conclusion: don't assume all RGB Jpeg files are "4:4:4".
I did not understand what you meant with "pathological RGB" and you did not mention that it was not a 4:4:4 RGB encoded JPEG so I assumed it was a 4:4:4 RGB encoded JPEG.
Now that you uploaded some examples I can see they're not 4:4:4 and indeed the script you posted is correct.
Reel.Deel is offline   Reply With Quote
Old 26th April 2014, 17:16   #53  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
Global variables are not a solution (for example, there could be several sources with different properties). We need real clip metadata support.
SEt is offline   Reply With Quote
Old 26th April 2014, 17:47   #54  |  Link
wOxxOm
Oz of the zOo
 
Join Date: May 2005
Posts: 208
Quote:
Originally Posted by SEt View Post
Global variables are not a solution (for example, there could be several sources with different properties). We need real clip metadata support.
Even with global variables you can do it I think.
Code:
JpegSource("1.jpg")
csp1 = JPEG_SOURCE_CSP
.......
JpegSource("2.jpg")
csp2 = JPEG_SOURCE_CSP
.......
Of course an auxiliary function would be even better:
Code:
JpegSource("1.jpg")
csp1 = JpegSourceInfo("1.jpg",info=0)
dpiX = JpegSourceInfo("1.jpg",info=1)
dpiY = JpegSourceInfo("1.jpg",info=2)
......
wOxxOm is offline   Reply With Quote
Old 26th April 2014, 18:18   #55  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
I don't think there is any guaranteed ordering of execution in Avisynth language so you can you it in such imperative way. Also, global variables are evil.
Auxiliary functions would work, but it's still bad extremely redundant way of getting information.
SEt is offline   Reply With Quote
Old 26th April 2014, 18:27   #56  |  Link
wOxxOm
Oz of the zOo
 
Join Date: May 2005
Posts: 208
Welp, that's the reality of AviSynth.
wOxxOm is offline   Reply With Quote
Old 26th April 2014, 19:49   #57  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,812
Here some observations about order of execution in non MT versions of Avisynth (no idea about MT versions):
http://forum.doom9.org/showthread.ph...54#post1594454

Here some posts starting with Filker's post about extracting jpeg EXIF info
http://forum.doom9.org/showthread.ph...41#post1587641

EDIT: A couple of functions added to RT_Stats might assist if modifying linked scripts,

Code:
RT_FindStr(String S,string Substr,bool "Sig"=True,int "Pos"=1)
 Finds unnamed string Substr in unnamed string S.
 Optional bool Sig: Default=True, does case significant comparison, insignificant if false.
 Optional int Pos: Default=1, is start position in string S to find string Substr. If Pos smaller than 1 or greater than length of string s,
  then will return 0, Not Found.
 Returns position (1 relative) of found string within the FULL LENGTH string S, or 0 if not found.
 Differs from Avisynth FindStr in Sig and Pos args and in that if either string S or string Substr is "" then will ALWAYS return 0, 'Not Found',
 Avisynth FindStr always returns 1 if SubStr="" even if S is also "".
Code:
RT_TxtFindStr(String S,string FndS,bool "Sig"=True,int "Pos"=1,int "Start"=0,int "Lines"=0)
 Finds unnamed string FndS in unnamed multi-line text string S, starting at line 'Start' and searching 'Lines' number of string lines.
 S: is a multi-line text string, ie a newline [CHR(10)] separated list of strings.
 FndS: is a single string and will be considered terminated early at the first carriage return [Chr(13)] or newline [Chr(10)],
 carriage returns and newlines will not be findable using this function.
 Sig: Default=True, does case significant comparison, insignificant if false.
 Pos: Default=1, is the character start position in an individual line of the multi-line string S to start searching
   for the FndS string. Allows you to skip search on first Pos-1 characters within all single lines of multi-line string S.
   If Pos less than 1, then will return -ve number (usually -1), Not Found.
 Start: Default 0, is the 0 relative starting line where the searching begins within the multi-line string S.
 Lines: Default 0(all lines). Number of lines in multi-line string to seach, starting at line 'Start'.
 A -ve return is 'Not Found'. On success returns the line number of the first instance of a found string in the Start and Lines
  range of lines. An empty "" FndS will always return -ve result, ie Not Found (as will all errors).
 see RT_TxtQueryLines, to inquire number of single lines in a chr(10) separated multi-line string.
 see RT_TxtGetLine to extract a single line from a multi-line string [without trailing Chr(10) or Chr(13)].
 NOTE, Character position 'Pos' is 1 relative whereas multi-line line 'Start' index is 0 relative.
Code:
RT_FileFindStr(String FileName,string FndS,bool "Sig"=True,int "Pos"=1,int "Start"=0,int "Lines"=0)
 Finds unnamed string 'FndS' in 'FileName' text file, starting at line 'Start' and searching 'Lines' number of text lines.
 FileName: Name of a file containing text to search.
 FndS: is a string and will be considered terminated early at the first carriage return [Chr(13)] or newline [Chr(10)], carriage returns
 and newlines will not be findable using this function.
 Sig: Default=True, does case significant comparison, insignificant if false.
 Pos: Default=1, is the character start position in an individual line of text to start searching for the FndS string.
   Allows you to skip search on first Pos-1 characters within all lines of text.
   If Pos less than 1, then will return -ve number (usually -1), Not Found.
 Start: Default 0, is the 0 relative starting line where the searching begins in the text file.
 Lines: Default 0(all lines). Number of lines text to seach, starting at 'Start' line.
 A -ve return is 'Not Found'. On success returns the line number of the first instance of a found string in the Start and Lines
  range of lines. An empty "" FndS will always return -ve result, ie Not Found.
 see RT_FileQueryLines, to inquire number lines in a text file.
 see RT_ReadTxtFromFile to extract a range of lines from a text file.
 NOTE, Character position 'Pos' is 1 relative whereas multi-line line 'Start' index is 0 relative.
__________________
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; 26th April 2014 at 20:15.
StainlessS is offline   Reply With Quote
Old 11th February 2015, 01:23   #58  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,555
SEt, I know it's been a while, but would you consider releasing this as source+lib (32 & 64)? I'd like to make an edition that works with imagesequences, like ImageSource, and with MJPEG videos, and maybe a native VS binding as well.

As an aside, this reconstruction technique should work almost identically for DV, if it was tweaked for that, right? Or even the I-frames of MPEG-1 and -2, all basically the same tech. That'd be an interesting way of potentially improving old videos, because the difference is definitely visible.
foxyshadis is offline   Reply With Quote
Old 12th February 2015, 01:02   #59  |  Link
SEt
Registered User
 
Join Date: Aug 2007
Posts: 374
I'm not planning to release it as source or lib atm. No 64-bit version yet at all as there is plenty of x86 asm there. Will likely add sequence import later. MJPEG probably can be losslessly converted to JPEG sequence so unlikely to be implemented. The last thing I'd want is native VS bindings...

No idea about DV, but the technique can't be directly applied to MPEG-1/MPEG-2 (I would definitely like to have such MPEG decoder though).
SEt is offline   Reply With Quote
Old 3rd June 2016, 21:23   #60  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
Any plans on making a 64-bit version of this? Loading and transforming lots of big images needs more memory...
ajp_anton 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 15:52.


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