VideoHelp Forum




+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 31 to 36 of 36
  1. ^^^^
    Exactly. Treating the footage with the RGB clipping sledgehammer in order to comply with some broadcast specs, or 'manipulating' the YUV (aka digital YCbCr) data to minimize the RGB clipping are two sides of the coin.
    If Chris319 is concerned about his YUV (0....255) camcorder videos it may be easiest to open these in a tool (NLE) which treats the signal as YUV (or converts to RGB floats) and then make adjustments such that the resulting RGB parade looks "reasonable" (say none or only one of the RGB components getting clipped) and yet the picture looks "pleasing", IMO. Such legalizing YUV adjustments usually mean to move (shrink) CbCr towards their origin (128,128) until they hit the surface of the inner (valid RGB) block of the YCbCr cube (e.g. reduce the saturation, color grading tools).
    Last edited by Sharc; 17th Jan 2026 at 13:03.
    Quote Quote  
  2. Originally Posted by chris319 View Post
    The idea is to take footage shot with a camcorder which outputs 0 - 255 and make it 16 - 235 or 5 - 246 if you prefer.

    After spinning my wheels here and being gaslit by one particular member, I worked with a guy on reddit/ffmpeg to get the code posted here. It was his idea to use ffmpeg's clip function. I put the project aside for a couple of years and am now coming back to it.
    Are you sure you really need to clip the RGB (assuming 'studio' YUV<->RGB conversion)? Clipping usually damages the footage. Doesn't the usual YUV levels adjustments do what is needed (in best case avoiding RGB clipping) - with less damage than clipping? Do you submit your material to broadcasters who request min/max RGB boundaries? Just curious.
    Quote Quote  
  3. Originally Posted by chris319 View Post
    The idea is to take footage shot with a camcorder which outputs 0 - 255 and make it 16 - 235 or 5 - 246 if you prefer.

    After spinning my wheels here and being gaslit by one particular member, I worked with a guy on reddit/ffmpeg to get the code posted here. It was his idea to use ffmpeg's clip function. I put the project aside for a couple of years and am now coming back to it.
    Assuming your camera outputs limited range YUV with excursions in the 0...16 and 235...255 luma range, and you want to clip it to stated limits in RGB (16-235) or (5-246) acc. EBUr103 or whatever, I woud suggest in any case to add the colorspace (matrix) and range of the source and target to the scale filter, to prevent surprises with the conversion and clipping.
    For the "720p" case of post #1 this would become, for example (adjust to your use cases):
    Code:
    ffmpeg  -hide_banner  -i "%~1" -vf  scale=interl=0:in_color_matrix=bt709:out_color_matrix=bt709:in_range=limited:out_range=limited:width=1280:height=720:flags='bilinear',"lutrgb=r='clip(val,16,235)':g='clip(val,16,235)':b='clip(val,16,235)'",setrange=range=limited  -codec:v libx264  -crf 0  -pix_fmt:v yuv420p  -color_range "tv"  -color_primaries bt709  -color_trc bt709 -colorspace bt709  -movflags +write_colr   -c:a copy  "%~1_clipped_.mp4"
    Just trusting in defaults or (incorrect or undefined) flags may mess it up and/or give unexpected results, in my experience.
    Last edited by Sharc; 25th Jan 2026 at 11:14.
    Quote Quote  
  4. Sharc:

    Your code works!

    Could you please add your code to the 1080i version? Thank you.
    Quote Quote  
  5. For interlaced sources and EBUr103 preferred limits try something like
    Code:
    ffmpeg -hide_banner -i "%~1" -vf  scale=interl=1:width=1920:height=1080:in_color_matrix=bt709:out_color_matrix=bt709:in_range=limited:out_range=limited,setfield=tff,setsar=1/1,"lutrgb=r='clip(val,5,246)':g='clip(val,5,246)':b='clip(val,5,246)'",setrange=range=limited -codec:v libx264  -crf 16 -pix_fmt:v yuv420p  -color_range "tv"  -color_primaries bt709  -colorspace bt709  -flags +ilme+ildct  -movflags +write_colr  -c:a copy  "%~1_clipped_.mp4"
    Quote Quote  
  6. to 720p 16 - 235
    Pixel format = 4:2:2

    Code:
    ffmpeg  -y  -hide_banner  -i "C0015.mp4" -vf  scale=interl=0:in_color_matrix=bt709:out_color_matrix=bt709:in_range=limited:out_range=limited:width=1280:height=720:flags='bilinear',"lutrgb=r='clip(val,16,235)':g='clip(val,16,235)':b='clip(val,16,235)'",setrange=range=limited  -codec:v libx264  -crf 0  -pix_fmt:v yuv422p  -color_range "tv"  -color_primaries bt709  -color_trc bt709 -colorspace bt709  -movflags +write_colr   -c:a copy  "clipped_.mp4"

    to 1080i 16 - 235
    Pixel format = 4:2:2

    Code:
    ffmpeg -y  -hide_banner -i "C0015.mp4" -vf  scale=interl=1:width=1920:height=1080:in_color_matrix=bt709:out_color_matrix=bt709:in_range=limited:out_range=limited,setfield=tff,setsar=1/1,"lutrgb=r='clip(val,16,235)':g='clip(val,16,235)':b='clip(val,16,235)'",setrange=range=limited -codec:v libx264  -crf 16 -pix_fmt:v yuv422p  -color_range "tv"  -color_primaries bt709  -colorspace bt709  -flags +ilme+ildct  -movflags +write_colr  -c:a copy  "1080_clipped_.mp4"
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!