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

CC BY-SA 4.0
2023-02-22T04:34:06.020Z
2023-02-22T04:34:06.020Z
jangles
<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>

CC BY-SA 4.0
2023-07-21T18:48:51.927Z
2023-07-21T18:48:51.927Z
jason gilbert
<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>

CC BY-SA 4.0
2019-10-29T18:48:27.223Z
2019-10-29T18:48:27.223Z
llogan
<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>

<ffmpeg>
FFMPEG - convert video to Black & White with threshold?
user3158732
# 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 filter:

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:

main input
threshold
min
max

You can optionally add the 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


---

