Here is a little script which converts full-range 0 - 255 video to limited-range 16 - 235. It uses ffmpeg's eq filter, giving you finer control than simply re-flagging to limited range.
I was experimenting with a camera that puts out 0 - 255 and DaVinci Resolve's "color match" feature with a DSC SMPTE One-Shot card. This script also adjusts the gamma. It's not perfect but close.
Code:ffmpeg -y -i inputVideo.mp4 -pix_fmt yuv420p -c:v libx265 -vf eq=brightness=.06:contrast=0.84:gamma=0.6,scale=out_color_matrix=bt709:out_range=limited -color_primaries bt709 -color_trc bt709 -colorspace bt709 -c:a copy outputVideo.mp4
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 30 of 43
Thread
-
-
"re-flagging" doesn't change the actual range. Flags are just metadata or "labels" - and that might affect how some programs interpret the data - but the actual underlying YUV data is unchanged.
eg. If you have actual full range data Y 0-255, flagged as full range, and then change the flag to "limited range" , it's still Y 0-255 full range data but flagged as limited
The option for more control is generally a good thing, but those eq values convert to Y=220 max . ie. Y 0-255 to 16-220 . (Excessive range compression) -
that might affect how some programs interpret the data - but the actual underlying YUV data is unchanged.
those eq values convert to Y=220 max . ie. Y 0-255 to 16-220 . (Excessive range compression)
The user is free to substitute different values if desired. -
To get ffmpeg cmd line into Vapoursynth, WITHOUT needing to encode it first and therefore use color pickers for value evaluation:
Code:import vapoursynth as vs from vapoursynth import core import subprocess, ctypes, shlex source_path=r'C:\inputVideo.mp4' clip = core.lsmas.LibavSMASHSource(source_path) ffmpeg = r'H:\tools\ffmpeg.exe' #no source loading , no formats out ffmpeg_args ='-y -pix_fmt yuv420p -vf eq=brightness=.06:contrast=0.84:gamma=0.6,scale=out_color_matrix=bt709:out_range=limited -color_primaries bt709 -color_trc bt709 -colorspace bt709' w = clip.width h = clip.height Ysize = w * h #for YUV420 Usize = w * h//4 #for YUV420 Vsize = w * h//4 #for YUV420 #------------------------- END of USER input ------------------------ ffmpeg_args = ffmpeg_args.strip() ffmpeg_args = shlex.split(ffmpeg_args) command = [ffmpeg, '-i', source_path] + ffmpeg_args + [ '-f', 'rawvideo', '-'] frame_len = Ysize + Usize + Vsize pipe = subprocess.Popen(command, stdout = subprocess.PIPE, bufsize=frame_len) def load_frame(n,f): try: vs_frame = f.copy() for i, size in enumerate([Ysize, Usize, Vsize]): ctypes.memmove(vs_frame.get_write_ptr(i), pipe.stdout.read(size), size) pipe.stdout.flush() except Exception as e: raise ValueError(repr(e)) return vs_frame try: clip = core.std.ModifyFrame(clip, clip, load_frame) except ValueError as e: pipe.terminate() print(e) clip.set_output()
vapoursyth reads from ffmpeg pipe and it is linear only during playback, only consequent frames can be viewedLast edited by _Al_; 9th Aug 2020 at 19:27.
-
-
Roughly +/- 2-3 , I used lossy compression for camera. But it's ~220 Max . Exactly 220 when testing synthetic
Did you test it with a DSC SMPTE One Shot card and Resolve's "color match" function?
Visually , results confirm what measurements and waveform show. Dynamic range is low, shadows compressed too. -
It's been months and I've never gotten Vapoursynth to run without errors, so I gave up.
At least ffmpeg runs and follows the commands. -
Another way is to pipe ffmpeg into ffplay for -vf waveform if you were looking at levels (e.g. some people can't get vapoursynth to run)
eg.
ffmpeg -i input.ext -vf <your filters here> -f yuv4mpegpipe - | ffplay -f yuv4mpegpipe - -vf waveform=g=green
So you can adjust some filter parameters, run it again, adjust , rinse/repeat -
-
I wouldn't use it at all. If you're using other programs like Resolve, why not just do it there? Almost every program has a configurable levels filter that you can see in real time with a GUI. FFmpeg is not ideal for that
I'm just pointing out it does not do what you claim . It's a heads up for people who don't check , they are going to get the wrong results -
If you're using other programs like Resolve, why not just do it there?
Almost every program has a configurable levels filter that you can see in real time with a GUI.
What did I say in my original post?
It's not perfect but close.
Now answer my question: what kind of test chart are you using with your camera and does it have an 18% reflectance patch? How about posting a screen shot?
[Attachment 54472 - Click to enlarge] -
I'm just pointing out it does not do what you claim . It's a heads up for people who don't check , they are going to get the wrong results
How many times must I repeat myself? If you don't get the levels you want then tweak the parameters! -
Someone recommend this link, I think it was on this site, https://www.blackmagicdesign.com/uk/products/davinciresolve/training
I just watched that link from "The Art of Color Grading". There are steps you should watch for, or maybe other videos are also that entertaining as that was. -
-
I wrote 16 - 235 to make clear what is meant by "limited range", not to set you up to take potshots at it.
There were several hours of back-and-forth tweaking before getting that far.
I'm pointing out it does not.
As usual, I don't see you posting an improved script, only criticizing.
Once again, what kind of test chart are you using with your camera? And how about posting a screen shot of your test?
No answer to my question and no screen shot. I'm starting to think B.S.Last edited by chris319; 9th Aug 2020 at 21:46.
-
Output Ymax is 220 when input Ymax is 255 . That's not right.
People will get messed up results with that.
If you think that works for your setup, great.
But it won't for full range cameras . Please double check your work before posting
How is it a "potshot" when it's a fact ? I'm only posting so people don't copy/paste and get incorrect results -
But it won't for full range cameras .
Where's your improved version?
Where are your answers to my questions?
Where's your screen shot?
All talk and no action.
Don't say that I don't check my work because I do and the screen shot proves it. It works for me.
Your lack of hands-on experience with professional video is showing.
Enough arguing. -
Look at the command line, it's not a full range file with yuv420p or out_range=limited
Where's your improved version?
A better starting point would be Y 0-255 to Y 16-235, instead of to Y16-220, don't you agree ?
Don't say that I don't check my work because I do and the screen shot proves it. It works for me.
It will not work for everyone else who has full range video 0-255
Take any random full range video with full range values (Y 0-255) , or synthetic full range test video (Y 0-255) . Ymax is 220 after you apply that script . Are you saying this is wrong ? (I can make mistakes too)
Maybe you're making a mistake or flawed assumption somewhere . It wouldn't be the first time...Think about it.
The slope can be changed nonlinearly (e.g. curves) in most editors to hit a 18% target(or any % target) - but it's absolutely essential to nail down black and white. That eq setting gets Y=16 correct, but Y=220 is not white by any standard . Sure, you can adjust it afterwards, but why bother with all this to make a mistake and then have to correct that mistake later ? -
I tested it on a window signal containing 255 and it puts 255 right at 235. See the first screen shot below.
The black and gamma in the camera footage are different from the test signal. It's doing what I need it to do, which is to correct the camera footage.
Below that is the output of Resolve color match and no ffmpeg script; whites to 255 and gamma way too high.
Look at the command line, it's not a full range file with yuv420p or out_range=limited
I don't use -vf eq . I can try to figure it out, but I don't see any need to do it this way.
You do have a test card with 18% reflectance, don't you? How many times have I asked and you haven't answered yet? And 90% reflectance for white?
https://www.bhphotovideo.com/c/product/1311293-REG/dsc_labs_posp_pocket_oneshot_plus_test.htmlLast edited by chris319; 10th Aug 2020 at 01:55.
-
To be clear, I'm talking about the 1st post, actual video files from the ffmpeg commandline. ie. The topic.
We differ there, Y 255 becomes Y 220 in the output file after the ffmpeg commandline
It's a problem when your brightest pixel is Y=220
I think there is a problem somewhere with how you are measuring /testing or your file, or maybe some other programs doing something funky. I'm measuring the actual levels, verified with several programs
The black and gamma in the camera footage are different from the test signal. It's doing what I need it to do, which is to correct the camera footage.
Below is the original camera footage; whites to 255 and gamma way too high.
Look at the command line, it's not a full range file with yuv420p or out_range=limited
To be clear, all I'm talking about is full range input video, the ffmpeg command line in the 1st post, and the resulting output file .
When the input file has Y=255, the output file has Y=220
That's the only reason I'm posting, there is a problem with that commandline
Fine. Let's see your way of accomplishing this even if it doesn't use -vf eq.Last edited by poisondeathray; 10th Aug 2020 at 02:07.
-
Below is the original camera footage; whites to 255 and gamma way too high.
I don't see how it can be
You know how to read a scope. And you do know where 18% reflectance should sit on a BT.709 waveform at 2.2 gamma, right? The screen shot clearly shows the white patch at 255 and the 18% patch way above 43% (digital 111). That is the output of DaVinci color match.
So where's the confusion? -
The problem is primarily the white level, but also the compressed dynamic range
I'm talking about the ffmpeg output file. When you use full range input Y 0-255, the output is Y 16-220 . A white Y=255 patch becomes Y=220. If you disagree, then we have to sort that out first
If you import that into resolve, you will see the problem
It has been converted to a normal range file , and if it was a "correct" conversion to normal range Y 16-235 you would see 0-1023 in resolve when the file is interpreted as video range (auto, since it's no longer flagged as full after conversion). Resolve retains data >1023 internally, you can bring those down (if you had them). But the Y=255 patch has levels well below 1023 (corresponding to Y=220 in 8bit). This corresponds with other tools as well
You should see compressed shadows too because of the range compression (but that will partially depend on the camera) -
If you disagree, then we have to sort that out first
As I have said before, a measurement device or measurement software shouldn't alter the signal it's measuring. Think about it. -
Yes, this suggest is wrong with your measurements or your video. If you stand by your measurements, then it could be your video. You posted an incorrect "window signal" video before, are you sure you're using a correct one ? Please upload your video
You can check with ffmpeg/ffplay -vf waveform, or confirm with other like vapoursynth, avisynth, or elementary bitstream YUV analysis
In the shotcut forum , Austin posted a correct Y 0,16,235,255 video, flagged as full range. I'll repost it here "FullValuesFullFlag.mp4"
I copy/pasted the ffmpeg eq settings in the first post, the output is vf_eq_outputVideo.mp4
Code:ffmpeg -y -i FullValuesFullFlag.mp4 -pix_fmt yuv420p -c:v libx265 -vf eq=brightness=.06:contrast=0.84:gamma=0.6,scale=out_color_matrix=bt709:out_range=limited -color_primaries bt709 -color_trc bt709 -colorspace bt709 -an vf_eq_outputVideo.mp4
Code:ffmpeg -i FullValuesFullFlag.mp4 -vf waveform=g=green:o=0.25 -frames:v 1 FullValuesFullFlag.png
[Attachment 54476 - Click to enlarge]
Code:ffmpeg -i vf_eq_outputVideo.mp4 -vf waveform=g=green:o=0.25 -frames:v 1 vf_eq_outputVideo.png
[Attachment 54481 - Click to enlarge]
I'll also include a Y 0-255 ramp, flagged as full range "greyscale_nd_fullrange_flagged.mp4" (and if you want I can upload one flagged as normal or not flagged . But if you recall , -vf waveform does not adjust it's digital reading according to presence of a full range flag , nor does it adjust when using IRE units) .
Code:ffmpeg -y -i greyscale_nd_fullrange_flagged.mp4 -pix_fmt yuv420p -c:v libx265 -vf eq=brightness=.06:contrast=0.84:gamma=0.6,scale=out_color_matrix=bt709:out_range=limited -color_primaries bt709 -color_trc bt709 -colorspace bt709 -c:a copy vf_eq_outputVideo_gradient.mp4
Code:ffmpeg -i greyscale_nd_fullrange_flagged.mp4 -vf waveform=g=green -frames:v 1 greyscale_nd_fullrange_flagged.png
[Attachment 54479 - Click to enlarge]
Code:ffmpeg -i vf_eq_outputVideo_gradient.mp4 -vf waveform=g=green -frames:v 1 vf_eq_outputVideo_gradient.png
[Attachment 54480 - Click to enlarge] -
Does this code look good to you for generating a full-level file?
yuvj pixels intentionally omitted, so it will be flagged as "limited"
What changes would you make if it looks wrong to you?
Code:bin\ffmpeg -y -loop 1 -t 10 -i WindowSignalFull.bmp -pix_fmt yuv420p -c:v libx265 -vf scale=out_color_matrix=bt709:out_range=full -color_primaries bt709 -color_trc bt709 -colorspace bt709 -crf 0 -r 59.94 -an Window_full.mp4
-
How do these files look to you?
http://www.chrisnology.info/video/Window_full.mp4
http://www.chrisnology.info/video/Window_limited.mp4 -
Similar Threads
-
MPC-HC: Output dynamic range / black level / color range stuck? Washed out
By vlad992 in forum Newbie / General discussionsReplies: 16Last Post: 10th Nov 2020, 08:54 -
How do I forcibly alter the colour range from RGB full to limited
By bergqvistjl in forum Video ConversionReplies: 2Last Post: 22nd May 2020, 13:45 -
ffmpeg 4.1.4 question regarding "limited color range" output file
By bokeron2020 in forum Newbie / General discussionsReplies: 12Last Post: 1st Aug 2019, 18:28 -
does mjpeg .AVI files a flag that signal the Full/Limited Dynamic range?
By marcorocchini in forum Newbie / General discussionsReplies: 1Last Post: 27th Jan 2019, 22:58 -
Looking for best Full HD 25 or 30p shooting camera in 1000$ price range
By Srivas in forum Camcorders (DV/HDV/AVCHD/HD)Replies: 0Last Post: 21st Oct 2017, 13:25