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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th March 2016, 17:48   #181  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Cretindesalpes:

You stated in your message that the RGB input/output for matrix is "full range" by default. I ran some tests with Big Buck Bunny clip (link below).
http://distribution.bbb3d.renderfarm...fps_normal.mp4

When I use the transfer function (even with only the input clip option), I can not get accurate colors from the output clip unless I manually define clip range conversion from "limited to full" or "limited to limited" either in transfer or matrix functions. I wrote the test scripts below along with their results. Let me know if this is an indication of a bug in fmtconv.

Code:
Script 1 (Input and Output look different.  Output colors are slightly dull.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)


Script 2 (Input and Output look different.  Output colors are slightly dull.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=True, fulld=True)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)



Script 3 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=False, fulld=False)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)


Script 4 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=False, fulld=True)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)



Script 5 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709",fulls=False, fulld=True)
clip = core.fmtc.transfer (clip)
clip = core.fmtc.matrix (clip, mat="709", fulls=True, fulld=False)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)
J1Man is offline   Reply With Quote
Old 21st March 2016, 09:50   #182  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
Only Script 4 gave me a different output with a regular TV-range video sample, which was expected. However the Big Buck Bunny clip you linked seems to be BT.601 and not BT.709 (the stream is not even tagged and some red colors are clipped when using a 709 matrix), which would explain why converting back and forth to R’G’B’ generates some differences.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 21st March 2016, 20:45   #183  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Thanks for getting back to me.

How did you understand that the original clip uses BT601 matrix? Does it use BT601-525 primaries? I got BT709 matrix and primaries from MadVR's OSD but it seems like MadVR automatically assumes BT709 matrix/primaries for all HD size clips. Does fmtconv display the original matrix/primaries/transfer_function info for the clip? Or did you use another program?

In order to prevent color clipping, is it safe to use BT2020 matrix for back and forth conversion between RGB and YUV (without primaries gamut conversion), when I am not sure about the source matrix?


I am still getting some unexpected behavior in the output even with BT601 matrix. I generated screenshots for the unprocessed original clip, output for scripts 1-5 with BT601 matrix and output for scripts 1-5 with BT709 matrix. All screenshots are from the same frame that is located approximately at time code 06:22/10:35 of the clip. I used 64bit fmtconv r19, 64bit ffms2 ver 2.20 and 64bit vapoursynth r31 via 64bit Staxrip 1.3.2 to generate these screenshots. The link for the screenshots zip file is shown below:

https://github.com/EleonoreMizo/fmtc...creenshots.zip

I noticed that Script 4 gives different output in my tests as well. Color of the Bunny is incorrect in the screenshots for Script 4 both with BT601 and BT709 matrices. There is a very small difference in output of Script 4 that I did not notice before I posted my previous message.

When you look at my screenshots, you will see that Scripts 1, 2 and 4 with BT601 matrix give different outputs that are not identical to input. Only Scripts 3 and 5 with BT601 matrix give outputs that are identical to input. (Note: In this particular test frame, BT601 and BT709 did not make a noticeable difference in the screenshots for any of the scripts. That's why it is very difficult to visually notice the incorrect usage of BT709 matrix by looking at the screenshots of this test frame.)

Were you able to replicate my results by using Scripts 1 and 2 with BT601 matrix on the Big Buck Bunny clip near the same frame/scene that I used in my screenshots? What might be the reason for input/output differences caused by Scripts 1 and 2? The results might not be noticeable at some other scenes of the same clip.



Is this Big Buck Bunny clip limited range based on your analysis? Is there a way to tell if a source clip is full range or limited range? MediaInfo does not always show this information. I probably should have asked this question before doing all the work for generating screenshots.

Last edited by J1Man; 21st March 2016 at 20:57.
J1Man is offline   Reply With Quote
Old 21st March 2016, 21:21   #184  |  Link
kolak
Registered User
 
Join Date: Nov 2004
Location: Poland
Posts: 2,843
Quote:
Originally Posted by J1Man View Post
Cretindesalpes:

You stated in your message that the RGB input/output for matrix is "full range" by default. I ran some tests with Big Buck Bunny clip (link below).
http://distribution.bbb3d.renderfarm...fps_normal.mp4

When I use the transfer function (even with only the input clip option), I can not get accurate colors from the output clip unless I manually define clip range conversion from "limited to full" or "limited to limited" either in transfer or matrix functions. I wrote the test scripts below along with their results. Let me know if this is an indication of a bug in fmtconv.

Code:
Script 1 (Input and Output look different.  Output colors are slightly dull.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)


Script 2 (Input and Output look different.  Output colors are slightly dull.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=True, fulld=True)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)



Script 3 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=False, fulld=False)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)


Script 4 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.transfer (clip, fulls=False, fulld=True)
clip = core.fmtc.matrix (clip, mat="709")
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)



Script 5 (Input and Output look identical.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709",fulls=False, fulld=True)
clip = core.fmtc.transfer (clip)
clip = core.fmtc.matrix (clip, mat="709", fulls=True, fulld=False)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)
Your source file has no full range flag, so by the default nothing will expect full range.

These files are full range and have proper flagging, so you can try:
http://www.dpreview.com/reviews/canoneos5dmarkii/19

Last edited by kolak; 21st March 2016 at 21:24.
kolak is offline   Reply With Quote
Old 21st March 2016, 23:34   #185  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
Quote:
Originally Posted by J1Man View Post
How did you understand that the original clip uses BT601 matrix?
By trying to display it with a BT.601 matrix and suddenly seeing flat colors turning into gradients. Look at the fruit hanging on the tree at around 1:45.

Quote:
Does it use BT601-525 primaries?
No idea. As I said, the stream isn’t tagged at all with color specifications. To be sure, you should ask the people that encoded this movie.

Quote:
In order to prevent color clipping, is it safe to use BT2020 matrix for back and forth conversion between RGB and YUV (without primaries gamut conversion), when I am not sure about the source matrix?
There is no safe way. If you assume a certain colorspace and if your stream has Y’Cb’Cr’ component out of its legal range, you’ll have a loss when going back to Y’Cb’Cr’. In any case the R’G’B’ representations will be wrong so I can’t see why you would do this.

Quote:
When you look at my screenshots, you will see that Scripts 1, 2 and 4 with BT601 matrix give different outputs that are not identical to input.
You’re assuming the source is full range whereas it is TV-range.

Quote:
Is this Big Buck Bunny clip limited range based on your analysis? Is there a way to tell if a source clip is full range or limited range?
Unless specified explicitly in the stream, you can assume TV-range for most Y’Cb’Cr’ signals. To make sure (some streams are wrongly tagged), you can use an histogram. However this is not trivial, a lot of cameras generate TV-range streams but uses levels over 235 to store HDR data. But the black level should be located around 16 anyway.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 22nd March 2016, 00:44   #186  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Kolak:

Thanks for the full range test cases. I ran the tests using the following video from the page that you sent me:
http://download.dpreview.com/canon_e...2_Portrait.MOV

This video has Full Range color, BT.601 matrix coefficients, BT.709 primaries and BT.709 transfer function tagged in the stream. No guess work this time. Everything is tagged.

Since this video is full range, I added script 6 shown below.

Code:
Script 6 (Input and Output look identical for a full range source video.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="601",fulls=True, fulld=True)
clip = core.fmtc.transfer (clip)
clip = core.fmtc.matrix (clip, mat="601", fulls=True, fulld=True)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)
I only ran test scripts 1,2 and 6 all with BT.601 matrix on this full range video. It does not make sense to run scripts 3,4 and 5 on this full range video (but in case anybody is wondering, outputs in test scripts 3, 4 and 5 do not look like the input, as expected). Screenshots can be downloaded from the link below. All screenshots are taken from the first frame of the video.

https://github.com/EleonoreMizo/fmtc...creenshots.zip

Only script 6 gives an output that is identical to the input. Scripts 1 and 2 have different outputs. I would have expected Scripts 1 and 2 to have identical inputs & outputs for this full range video, but they don't.


The reason why I am running these tests and bringing this issue to Cretindesalp's attention is because I am trying to figure out if there is a bug in fmtconv or not. Based on Cretindesalp's messages, test scripts 1 and 2 should have identical inputs and outputs. But my screenshots (both for limited range Big Buck Bunny and full range Portrait video) show that this is not the case.


Cretindesalps:

Based on your message, I understand that the tests that I did with Big Buck Bunny clip were not very useful because we do not know for sure what the original specifications of the clip are.

This Portrait clip generated by Canon EOS 5D Mark II camera is a better test case because all information is tagged in the stream. What is your opinion on these results? Shouldn't scripts 1 and 2 give outputs that are identical to the input for this full range clip?

The most important question is, is there any unexpected behavior in these test results that indicate the presence of a bug in fmtconv? If you think that there is no problem, I am good too. I can just use script 5 for limited range clips and script 6 for full range source clips.

If you are in doubt, I can re-run the same test with other clips that you specify. Just send me the links.

Last edited by J1Man; 22nd March 2016 at 00:50.
J1Man is offline   Reply With Quote
Old 22nd March 2016, 11:49   #187  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
If you use a full-range video, you have to indicate to fmtc.matrix that you are using full-range Y’Cb’Cr’. Default is TV-range. That’s why script 1 and 2 don’t give the right result, whereas script 6 works as expected.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 25th March 2016, 00:37   #188  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Cretindesalps:

I am also having trouble with primaries conversion. I ran the test using the same video:
http://download.dpreview.com/canon_e...2_Portrait.MOV

This video has Full Range color, BT.601 matrix coefficients, BT.709 primaries and BT.709 transfer function tagged in the stream.

I used the following script to convert it to a 10bit full range clip with BT2020 primaries, BT2020 matrix and BT2020-10 transfer function.

Code:
Script 7 (Input and Output look different for a full range source video.)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="601",fulls=True, fulld=True)
clip = core.fmtc.transfer (clip, transs="709", transd="linear")
clip = core.fmtc.primaries (clip, prims="709", primd="2020")
clip = core.fmtc.transfer (clip, transs="linear", transd="2020_10")
clip = core.fmtc.matrix (clip, mat="2020", fulls=True, fulld=True)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)
I encoded the video by 10bit build of x265 and tagged the stream properly with BT2020 info. Screenshots can be downloaded from the link below. I took the screenshots at the first frame using MadVR. The girl's face looks very red. I am getting similar results when I play the clip on my UHD TV.

https://github.com/EleonoreMizo/fmtc...ersionTest.zip


Am I doing something wrong? Is there a mistake in my script?
J1Man is offline   Reply With Quote
Old 25th March 2016, 10:27   #189  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
Indeed there is a problem in the primaries code. I’m going to check what’s wrong.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 25th March 2016, 16:14   #190  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
fmtconv r20:
  • primaries: fixed a bug preventing to set all primaries individually without specifying any preset.
  • primaries: fixed a bug in the color conversion, thanks to J1Man for having spotted it.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 26th March 2016, 02:02   #191  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Cretindesalpes:

Thanks for quickly releasing the new R20 version of fmtconv. I did more testing (using the same portrait clip) and it seems like the issue is not completely resolved. It seems like a big part of the problem is due to BT2020 matrix conversion. I ran the tests listed below using fmtconv r20. The screenshots can be downloaded from the link shown below.

https://github.com/EleonoreMizo/fmtc...rsionTest2.zip

I first ran Script 6 to test for regressions. Script 6 converts the clip to RGB and back to 10bit YUV without modifying the matrix, primaries and transfer function. I took screenshots with MadVR and confirmed that input and output look 100% identical. This also proves that there is no distortion introduced by x265 or MadVR.

I also ran a modified version of Script 6 that only changes the transfer function from BT709 to BT2020-10 (keeping Matrix and primaries the same). I confirmed that screenshots taken by MadVR were identical. This rules out transfer function related mistakes.

I ran Script 7, to convert everything to BT2020 colorspace, took screenshots with MadVR and saw that input and output were different. I also ran a modified version of Script 7 to convert everything to BT709. Again there was a noticeable difference. The surprising thing is BT709 and BT2020 conversion screenshots look very very similar. As a result, I decided to run other tests.

I created Script 8 (shown below) that only changes the matrix (keeping primaries and transfer function identical). The input and output were different. There is a very big and noticeable difference.

Code:
Script 8 (just changes the matrix, Input and Output look different)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="601",fulls=True, fulld=True)
clip = core.fmtc.matrix (clip, mat="2020", fulls=True, fulld=True)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)

There might be a problem with the matrix conversion function used by fmtconv. Since we are going from the smaller color space of BT601 to much larger color space BT2020, there should not be any clipping. There is a BT2020 matrix defined in the source code of x265. I wrote the links below in case they can be useful to you.

https://bitbucket.org/multicoreware/...16198feb696230
https://bitbucket.org/multicoreware/...e-view-default




I created Script 9 (shown below) that only changes the primaries (keeping matrix and transfer function identical). The input and output were different. There is a small (but still noticeable) difference visible on girl's face, lips and the ceiling.

Code:
script 9 (just change primaries, Input and Output look different)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="601",fulls=True, fulld=True)
clip = core.fmtc.transfer (clip, transs="709", transd="linear")
clip = core.fmtc.primaries (clip, prims="709", primd="2020")
clip = core.fmtc.transfer (clip, transs="linear", transd="709")
clip = core.fmtc.matrix (clip, mat="601", fulls=True, fulld=True)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)

I also ran script 9 using the previous primaries (from fmtconv r18) for BT2020 using the command (gd=[0.170, 0.797], bd=[0.131, 0.046], rd=[0.708, 0.292], wd=[0.3127, 0.3290]) and the results did not change.


Please let me know what you think. I ran all the tests that I could think of. I can run more tests if you have any other test ideas.
J1Man is offline   Reply With Quote
Old 30th March 2016, 14:27   #192  |  Link
J1Man
Registered User
 
Join Date: Mar 2016
Posts: 9
Cretindesalpes:

I stumbled on a more serious bug. When "1886a" (alternative approximation of 1886) transfer function is used before and after primaries conversion, it creates heavy pink artifacts on bright areas of the video. I attached screenshots from Tears of Steel movie. You can replicate the bug on any movie with a bright outdoor scene. Artifacts appear mostly on bright parts of the image.

https://github.com/EleonoreMizo/fmtc...erfunction.zip


I used script 10 shown below to generate the screenshots. Script 11 that changes transfer function from 1886a to pure 2.3 gamma curve (without primaries conversion) also creates artifacts that almost posterize the output.

Code:
Script 10 (Primaries conversion with 1886a transfer function creates pink artifacts)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709",fulls=False, fulld=True)
clip = core.fmtc.transfer (clip, transs="1886a", transd="linear")
clip = core.fmtc.primaries (clip, prims="709", primd="2020")
clip = core.fmtc.transfer (clip, transs="linear", transd="1886a")
clip = core.fmtc.matrix (clip, mat="2020", fulls=True, fulld=False)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)

Script 11 (changing transfer function from 1886a to pure 2.3 gamma curve creates artifacts)
clip = core.fmtc.resample (clip, css="444")
clip = core.fmtc.matrix (clip, mat="709",fulls=False, fulld=True)
clip = core.fmtc.transfer (clip, transs="1886a", transd="linear")
clip = core.fmtc.transfer (clip, transs="linear", transd="linear", gcor=1/2.3)
clip = core.fmtc.matrix (clip, mat="709", fulls=True, fulld=False)
clip = core.fmtc.resample (clip, css="420")
clip = core.fmtc.bitdepth (clip, bits=10)
Based on these two scripts, I think the bug is in 1886a transfer function code only.



Most probably you already have it, but I found the latest 1886 standard (with formulas) on the following page:
http://www.itu.int/rec/R-REC-BT.1886-0-201103-I


In theory, Should an accurate implementation of BT.1886 transfer function standard (1886a in fmtconv) provide more accurate linearization before primaries conversion for the latest movies?

Last edited by J1Man; 30th March 2016 at 14:34.
J1Man is offline   Reply With Quote
Old 7th August 2016, 11:30   #193  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
'Small' feature request:
Would be nice/helpful if fmtconv would contain a 'helperfunction' which would convert the current color format&matrix to the target color format and matrix.
something like core.fmtc.convert(clip, srcmat, tarfor, tarmat)

so that when having to do a RGB to YUV420P10 conversion instead of having to call:
Code:
c = core.fmtc.matrix (clip=c, mat="601", col_fam=vs.YUV, bits=16)
c = core.fmtc.resample (clip=c, css="420")
c = core.fmtc.bitdepth (clip=c, bits=10)
one could simply call:
Code:
c = core.fmtc.bitdepth (clip=c, srcmat="601", tarfor="YUV420P10")
or when doing YUV420P10 601 to YUV420P8 709 instead of having to call:
Code:
c = core.fmtc.resample (clip=c, css="444")
c = core.fmtc.matrix (clip=c, mats="601", matd="709")
c = core.fmtc.resample (clip=c, css="420")
c = core.fmtc.bitdepth (clip=c, bits=8)
one could simply call:
Code:
c = core.fmtc.bitdepth (clip=c, srcmat="601", tarfor="YUV420P8", tarmar="709")
I understand that this would be some lengthy wrapper function to handle all the different possible conversions, but I think it would help the general pain of writing Vapoursynth scripts a bit and not everybody would have to write always those 3-X format conversion lines.

Cu Selur
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 7th August 2016, 12:11   #194  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by Selur View Post
'Small' feature request:
Would be nice/helpful if fmtconv would contain a 'helperfunction' which would convert the current color format&matrix to the target color format and matrix.
something like core.fmtc.convert(clip, srcmat, tarfor, tarmat)

so that when having to do a RGB to YUV420P10 conversion instead of having to call:
Code:
c = core.fmtc.matrix (clip=c, mat="601", col_fam=vs.YUV, bits=16)
c = core.fmtc.resample (clip=c, css="420")
c = core.fmtc.bitdepth (clip=c, bits=10)
one could simply call:
Code:
c = core.fmtc.bitdepth (clip=c, srcmat="601", tarfor="YUV420P10")
or when doing YUV420P10 601 to YUV420P8 709 instead of having to call:
Code:
c = core.fmtc.resample (clip=c, css="444")
c = core.fmtc.matrix (clip=c, mats="601", matd="709")
c = core.fmtc.resample (clip=c, css="420")
c = core.fmtc.bitdepth (clip=c, bits=8)
one could simply call:
Code:
c = core.fmtc.bitdepth (clip=c, srcmat="601", tarfor="YUV420P8", tarmar="709")
I understand that this would be some lengthy wrapper function to handle all the different possible conversions, but I think it would help the general pain of writing Vapoursynth scripts a bit and not everybody would have to write always those 3-X format conversion lines.

Cu Selur
The built-in resizers work the way you describe.
http://www.vapoursynth.com/doc/functions/resize.html
Swscale is not involved anymore, so you can use them without worries.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 7th August 2016, 13:09   #195  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,259
Nice! That helps! Thanks!
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 1st September 2016, 17:23   #196  |  Link
groucho86
Registered User
 
Join Date: Apr 2016
Posts: 85
Hi there,
I'm trying to (ultimately) create an MP4 with HDR metadata. My source is generated in Resolve in ACES with an ODT of P3D60 PQ (1000 nits) so it's HDR-Ready. I've outputted as both an OpenEXR image sequence and as a ProRes422HQ.

Having read threads on both doom9 and Blackmagic forums, I think x265 is expecting a YUV 420 10bit y4m stream.

I was doing the following in FFMPEG but was not getting correct results:
Code:
ffmpeg -nostats -start_number 00086400 -framerate 24000/1001  -i "/Volumes/TEST/p3d60/p3d60-%08d.exr" -strict -1 -vf \\
scale=out_color_matrix=bt2020:out_h_chr_pos=0:out_v_chr_pos=0,format=yuv420p10 -f yuv4mpegpipe - | x265 - --y4m --crf 13 \\
--tune grain --colorprim bt2020 --transfer smpte-st-2084 --colormatrix bt2020nc --master-display \\
"G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)" --max-cll "1000,400" --output "/Volumes/TEST/hevc/test.hevc"
I'm now trying ffmtconv but I'm unable to create the YUV 420 10bit stream after creating an smpte-2084 version. This is what I have:
Code:
c = core.lsmas.LibavSMASHSource(source="/Volumes/Test/ test01.mov")

c = core.fmtc.resample(clip=c, css="444")
c = core.fmtc.bitdepth(clip=c, bits=10)
c = core.fmtc.matrix2020cl(clip=c, full=True )
c = core.fmtc.transfer(c, transs="2020", transd="2084", cont=1000.0/10000.0)

c.set_output()
I then try something like
Code:
c = core.fmtc.resample(clip=c, css='420')
But get the following error:
Code:
  File "src/cython/vapoursynth.pyx", line 1383, in vapoursynth.Function.__call__ (build/temp.macosx-10.9-x86_64-3.5/pyrex/vapoursynth.c:25204)
vapoursynth.Error: : couldn't get a pixel format identifier for the output clip.
Thank you in advance for your help.
groucho86 is offline   Reply With Quote
Old 2nd October 2016, 20:19   #197  |  Link
dipje
Registered User
 
Join Date: Oct 2014
Posts: 268
Another thing I noticed in r20. Am I doing something wrong, making wrong assumptions or is there something wrong in fmtconv somewhere?

I read a simple movie file (YUV420P8).

I resample to YUV444P16, use matrix to go RGB48 (from BT709), I transfer to linear, I use primaries to go from 709 to 2020, I transfer from linear to 2048 with a contrast value of 1000.0 / 10000.0 (0.1), then matrix to YUV with BT2020 (non-constant) matrix.

As a test, I do the reverse directly in the script. Matrix to RGB from BT2020nc, transfer to linear from 2084 with a contrast value of 10000.0 / 1000.0 (10.0), I use primaries to go from 2020 to 709, I transfer from linear to regular 709, and I use matrix to go to YUV with BT709 matrix.

The result should be pretty much exact the same as the input (with some rounding errors here and there or something), but what I get is a clear 'levels' difference. It seems as if somewhere in the process there is a 'limited range / full range' mix up. The colors seem right, it's just a little bit of levels / contrast that seems different.

I ended up added 'fulls' and 'fulld' everywhere to make sure it does what I expect it to but I still get the same.

Am I doing wrong? Fmtconv wrong? Or is this just the result from going from 709 to 2084 and back since it's not a pure 1-to-1 mapping or something?

My code copy & pasted to be clear:
Code:
orig = c
c = core.fmtc.resample(c, w = 1920, h = 1080, css = '444', kernel = 'spline36')
c = core.fmtc.matrix(c, fulls = False, fulld = True, mats = '709', col_fam = vs.RGB)
c = core.fmtc.transfer(c, fulls = True, fulld = True, transs = '61966-2-1', transd = 'linear')
c = core.fmtc.primaries(c, prims = '709', primd = '2020')
c = core.fmtc.transfer(c, fulls = True, fulld = True, transs = 'linear', transd = '2084', cont = 1000.0 / 10000.0)
c = core.fmtc.matrix(c, fulls = True, fulld = False, matd = '2020', col_fam = vs.YUV)
c = core.fmtc.resample(c, css = '420')
c = core.fmtc.bitdepth(c, fulls = False, fulld = False, bits = 10, dmode = 5)

z = c
z = core.fmtc.resample(z, css = '444', kernel = 'spline36')
z = core.fmtc.matrix(z, fulls = False, fulld = True, mats = '2020', col_fam = vs.RGB)
z = core.fmtc.transfer(z, fulls = True, fulld = True, transs = '2084', transd = 'linear', cont = 10)
z = core.fmtc.primaries(z, prims = '2020', primd = '709')
z = core.fmtc.transfer(z, fulls = True, fulld = True, transs = 'linear', transd = '709')
z = core.fmtc.matrix(z, fulls = True, fulld = False, matd = '709', col_fam = vs.YUV)
z = core.fmtc.resample(z, css = '420', kernel = 'spline36')
z = core.fmtc.bitdepth(z, fulls = False, fulld = False, bits = 8, dmode = 5, ampo = 1, ampn = 1)

# At this moment 'orig' and 'z' look different although they should look pretty much the same I guess
dipje is offline   Reply With Quote
Old 4th October 2016, 18:30   #198  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
you have used different transfer values,probably you have to go in linear space using 709 transfer
or come back from linear space using "61966-2-1"

Code:
orig = c
c = core.fmtc.resample(c, w = 1920, h = 1080, css = '444', kernel = 'spline36')
c = core.fmtc.matrix(c, fulls = False, fulld = True, mats = '709', col_fam = vs.RGB)
c = core.fmtc.transfer(c, fulls = True, fulld = True, transs = '709', transd = 'linear')
#c = core.fmtc.transfer(c, fulls = True, fulld = True, transs = '61966-2-1', transd = 'linear')
c = core.fmtc.primaries(c, prims = '709', primd = '2020')
c = core.fmtc.transfer(c, fulls = True, fulld = True, transs = 'linear', transd = '2084', cont = 1000.0 / 10000.0)
c = core.fmtc.matrix(c, fulls = True, fulld = False, matd = '2020', col_fam = vs.YUV)
c = core.fmtc.resample(c, css = '420')
c = core.fmtc.bitdepth(c, fulls = False, fulld = False, bits = 10, dmode = 5)

z = c
z = core.fmtc.resample(z, css = '444', kernel = 'spline36')
z = core.fmtc.matrix(z, fulls = False, fulld = True, mats = '2020', col_fam = vs.RGB)
z = core.fmtc.transfer(z, fulls = True, fulld = True, transs = '2084', transd = 'linear', cont = 10)
z = core.fmtc.primaries(z, prims = '2020', primd = '709')
z = core.fmtc.transfer(z, fulls = True, fulld = True, transs = 'linear', transd = '709')
#z = core.fmtc.transfer(z, fulls = True, fulld = True, transs = 'linear', transd = '61966-2-1')
z = core.fmtc.matrix(z, fulls = True, fulld = False, matd = '709', col_fam = vs.YUV)
z = core.fmtc.resample(z, css = '420', kernel = 'spline36')
z = core.fmtc.bitdepth(z, fulls = False, fulld = False, bits = 8, dmode = 5, ampo = 1, ampn = 1)
age is offline   Reply With Quote
Old 4th October 2016, 22:07   #199  |  Link
dipje
Registered User
 
Join Date: Oct 2014
Posts: 268
D'oh.. stupid mistake on my part it seems. Will try it out, but srgb and 709 isn't always the same of course :S.
dipje is offline   Reply With Quote
Old 13th October 2016, 15:47   #200  |  Link
age
Registered User
 
Join Date: Oct 2015
Posts: 54
Is it possible to add/port some new resizer like ewa_lanczossharp (mpv player) ?
age is offline   Reply With Quote
Reply

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 14:24.


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