Answers.Body: <p>The main answer didn't work for me, this did:</p>
  <pre><code>ffmpeg -i input.mkv -f lavfi -i color=gray:s=1280x720 -f lavfi -i color=black:s=1280x720 -f lavfi -i color=white:s=1280x720 -filter_complex &quot;[0:v]scale=1280x720,threshold&quot; output.mkv
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-22T04:34:06.020Z
Answers.LastActivityDate: 2023-02-22T04:34:06.020Z
Answers.UserDisplayName: jangles
Answers.Body: <p>maskfun filter has a slightly easier syntax and I assume gets the same result.</p>
  <pre><code>ffmpeg -i video.mp4 -vf format=gray,maskfun=low=128:high=128:fill=0:sum=128 video-bw.mp4
  </code></pre>
  <p><a href="https://ffmpeg.org/ffmpeg-filters.html#maskfun" rel="nofollow noreferrer">https://ffmpeg.org/ffmpeg-filters.html#maskfun</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-21T18:48:51.927Z
Answers.LastActivityDate: 2023-07-21T18:48:51.927Z
Answers.UserDisplayName: jason gilbert
Answers.Body: <p>Use the <a href="https://ffmpeg.org/ffmpeg-filters.html#threshold" rel="nofollow noreferrer">threshold</a> filter:</p>
  
  <p><a href="https://i.sstatic.net/umOvC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/umOvC.png" alt="enter image description here"></a></p>
  
  <pre><code>ffmpeg -i main_1280x720.mp4 -f lavfi -i color=gray:s=1280x720 -f lavfi -i color=black:s=1280x720 -f lavfi -i color=white:s=1280x720 -filter_complex threshold output.mkv
  </code></pre>
  
  <p>This filter requires four video streams to perform thresholding:</p>
  
  <ol>
  <li>main input</li>
  <li>threshold</li>
  <li>min</li>
  <li>max</li>
  </ol>
  
  <p>You can optionally add the <a href="https://ffmpeg.org/ffmpeg-filters.html#format" rel="nofollow noreferrer">format</a> filter for a grayscale pixel format: <code>threshold,format=gray</code> (assuming your output format supports that otherwise additional pixel format conversion will automatically take place).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T18:48:27.223Z
Answers.LastActivityDate: 2019-10-29T18:48:27.223Z
Answers.UserDisplayName: llogan
Body: <p>I'd like to convert videos to black and white but also specify the threshold of what to convert to black/white.</p>
  
  <p>I'm currently using cv2 to do this successfully using the 2 lines below (first converts to grayscale then B&amp;W). But it would help my workflow to do everything with FFMPEG if possible.</p>
  
  <pre><code>    grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      (thresh, BW) = cv2.threshold(grayFrame, 10, 255, cv2.THRESH_BINARY)
  </code></pre>
  
Tags: <ffmpeg>
Title: FFMPEG - convert video to Black & White with threshold?
UserDisplayName: user3158732
ThreadText: # FFMPEG - convert video to Black & White with threshold?
  
  (Asked by: username_0 on 2019-10-29)
  
  I'd like to convert videos to black and white but also specify the threshold of what to convert to black/white.
  
  I'm currently using cv2 to do this successfully using the 2 lines below (first converts to grayscale then B&W). But it would help my workflow to do everything with FFMPEG if possible.
  
  ```
      grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      (thresh, BW) = cv2.threshold(grayFrame, 10, 255, cv2.THRESH_BINARY)
  
  ```
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2019-10-29. Score: 4 | Accepted answer
  
  Use the [threshold](https://ffmpeg.org/ffmpeg-filters.html#threshold) filter:
  
  [![enter image description here](https://i.sstatic.net/umOvC.png)](https://i.sstatic.net/umOvC.png)
  
  ```
  ffmpeg -i main_1280x720.mp4 -f lavfi -i color=gray:s=1280x720 -f lavfi -i color=black:s=1280x720 -f lavfi -i color=white:s=1280x720 -filter_complex threshold output.mkv
  
  ```
  
  This filter requires four video streams to perform thresholding:
  
  1. main input
  2. threshold
  3. min
  4. max
  
  You can optionally add the [format](https://ffmpeg.org/ffmpeg-filters.html#format) filter for a grayscale pixel format: `threshold,format=gray` (assuming your output format supports that otherwise additional pixel format conversion will automatically take place).
  
  
  ---
  
  ### Answer by username_1 on 2023-02-22. Score: 1
  
  The main answer didn't work for me, this did:
  
  ```
  ffmpeg -i input.mkv -f lavfi -i color=gray:s=1280x720 -f lavfi -i color=black:s=1280x720 -f lavfi -i color=white:s=1280x720 -filter_complex "[0:v]scale=1280x720,threshold" output.mkv
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2023-07-21. Score: 1
  
  maskfun filter has a slightly easier syntax and I assume gets the same result.
  
  ```
  ffmpeg -i video.mp4 -vf format=gray,maskfun=low=128:high=128:fill=0:sum=128 video-bw.mp4
  
  ```
  
  <https://ffmpeg.org/ffmpeg-filters.html#maskfun>
  
  
  ---
  
  