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)

Use the threshold filter:

enter image description here

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 filter for a grayscale pixel format: threshold,format=gray (assuming your output format supports that otherwise additional pixel format conversion will automatically take place).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.