Answers.Body: <p>You can use the geq filter to remap the pixel value ranges.</p>
  
  <pre><code>ffmpeg
   -i input
   -vf "geq=lum='(p(X,Y)-16)/(255-16)*(235-16)+16':cb='(p(X,Y)-16)/(255-16)*(240-16)+16'"
   -c:v libx264 -c:a copy out.mp4
  </code></pre>
  
  <p>The geq filter rescales the input luma from 16-255 to 16-235, and both the input chroma from 16-255 to 16-240, which is  the legal range for broadcast 8-bit signals.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-28T10:16:34.707Z
Answers.Text: Thank you very mutch for your help ! Another question: is there a way to "legalize" any source level to broadcast level ? In other words: can FFMPEG probe source file(s) level before remap to broadcast ?
Answers.UserDisplayName: FORART npo
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-04T11:46:30.747Z
Answers.LastActivityDate: 2020-04-04T11:46:30.747Z
Answers.UserDisplayName: Gyan
Body: <p>for a noprofit project I do shoot with (up to 5x) Canon HF100 camera(s) but, as stated in <a href="http://nerdfever.com/video-editing-for-scientific-analysis/" rel="nofollow noreferrer">this interesting artile</a>, it genetates a "custom RGB range" (16-255) files.</p>
  
  <p>Thanks to <a href="https://github.com/dericed/ffmpeg-mpeg2video-clipping" rel="nofollow noreferrer">this cool repository</a> I've generated this GIF of 10s of source video:</p>
  
  <p><a href="http://www.forart.it/_priv/cultura/HF100_measurement.gif" rel="nofollow noreferrer">http://www.forart.it/_priv/cultura/HF100_measurement.gif</a> (33 Mb, so can't post. Click to watch)</p>
  
  <p>It graphically shows how recorded video exceed the broadcast range.</p>
  
  <p>The question is: how to "shift down" everything (and constrain inside broadcast range, of course) in order to preserve the maximum possible color quality ?</p>
  
  <p>(note: someone already suggested me to use " <em>Levels(0, 16, 255, 16, 235, coring=false)</em> " in AviSynth but, if possible, I want to do it only with FFMPEG)</p>
  
  <p>Thanks in advance to anyone that can/will help.</p>
  
  <p>Marco</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-14T07:25:25.227Z
Comments.Text: Well, I've already asked @ Doom9 forums and here is the response: https://forum.doom9.org/showthread.php?p=1902399
Comments.UserDisplayName: FORART npo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-25T10:27:44.083Z
Comments.Text: Can you share a sample video from HF100?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-25T18:24:43.453Z
Comments.Text: Of course, here's an untouched shooting as downloaded from the camera: https://clicknupload.co/0ooaljx1oqi1
Comments.UserDisplayName: FORART npo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-26T07:10:09.967Z
Comments.Text: Here's another interesting discussion - I'm partecipating in too - about FFMPEG's color "management": https://forum.videohelp.com/threads/395939-ffmpeg-Color-Range/
Comments.UserDisplayName: FORART npo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-27T11:20:14.827Z
Comments.Text: Ok, chris319 (@ videohelp.com 3ad) suggested this parameters: -vf lutrgb='r=clip(val,30,223)',lutrgb='g=clip(val,30,223)',lutrgb='b=clip(val,30,223)'
Comments.UserDisplayName: FORART npo
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-04T11:29:41.263Z
Comments.Text: Ok, so your video is YUV, not RGB.And clip will squish the values beyond the clip ranges. You should remap them. I'll post an answer shortly.
Comments.UserDisplayName: Gyan
Tags: <ffmpeg><canon><colorspace><broadcast><avisynth>
Title: "Canon RGB" color space *shift* to broadcast range with FFMPEG
UserDisplayName: FORART npo
ThreadText: # "Canon RGB" color space *shift* to broadcast range with FFMPEG
  
  (Asked by: username_0 on 2020-03-11)
  
  for a noprofit project I do shoot with (up to 5x) Canon HF100 camera(s) but, as stated in [this interesting artile](http://nerdfever.com/video-editing-for-scientific-analysis/), it genetates a "custom RGB range" (16-255) files.
  
  Thanks to [this cool repository](https://github.com/dericed/ffmpeg-mpeg2video-clipping) I've generated this GIF of 10s of source video:
  
  <http://www.username_0.it/_priv/cultura/HF100_measurement.gif> (33 Mb, so can't post. Click to watch)
  
  It graphically shows how recorded video exceed the broadcast range.
  
  The question is: how to "shift down" everything (and constrain inside broadcast range, of course) in order to preserve the maximum possible color quality ?
  
  (note: someone already suggested me to use " *Levels(0, 16, 255, 16, 235, coring=false)* " in AviSynth but, if possible, I want to do it only with FFMPEG)
  
  Thanks in advance to anyone that can/will help.
  
  Marco
  
  **Tags:** ffmpeg, canon, colorspace, broadcast, avisynth
  
  > **Comments:**
  > **username_0**: Well, I've already asked @ Doom9 forums and here is the response: https://forum.doom9.org/showthread.php?p=1902399  
  > **username_1**: Can you share a sample video from HF100?  
  > **username_0**: Of course, here's an untouched shooting as downloaded from the camera: https://clicknupload.co/0ooaljx1oqi1  
  > **username_0**: Here's another interesting discussion - I'm partecipating in too - about FFMPEG's color "management": https://forum.videohelp.com/threads/395939-ffmpeg-Color-Range/  
  > **username_0**: Ok, chris319 (@ videohelp.com 3ad) suggested this parameters: -vf lutrgb='r=clip(val,30,223)',lutrgb='g=clip(val,30,223)',lutrgb='b=clip(val,30,223)'  
  > **username_1**: Ok, so your video is YUV, not RGB.And clip will squish the values beyond the clip ranges. You should remap them. I'll post an answer shortly.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-04. Score: 1
  
  You can use the geq filter to remap the pixel value ranges.
  
  ```
  ffmpeg
   -i input
   -vf "geq=lum='(p(X,Y)-16)/(255-16)*(235-16)+16':cb='(p(X,Y)-16)/(255-16)*(240-16)+16'"
   -c:v libx264 -c:a copy out.mp4
  
  ```
  
  The geq filter rescales the input luma from 16-255 to 16-235, and both the input chroma from 16-255 to 16-240, which is the legal range for broadcast 8-bit signals.
  
  > **Comments:**
  > **username_0**: Thank you very mutch for your help ! Another question: is there a way to "legalize" any source level to broadcast level ? In other words: can FFMPEG probe source file(s) level before remap to broadcast ?  
  
  ---
  
  