opencv codec_error ai_generated true

OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 27

ID: opencv/codec-not-found

Also available as: JSON · Markdown
82%Fix Rate
85%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4 active
4 active

Root Cause

VideoWriter cannot find the requested codec fourcc. Codec not installed or not compiled into FFmpeg backend.

generic

Workarounds

  1. 92% success Use a widely-supported codec fourcc
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')  # MPEG-4 is nearly universally available

    Sources: https://docs.opencv.org/4.x/d0/d05/tutorial_dnn_googlenet.html

  2. 88% success Install FFmpeg with the required codec
    sudo apt install ffmpeg libx264-dev && pip install --force-reinstall opencv-python
  3. 82% success Check available backends and codecs
    print(cv2.getBuildInformation())  # check FFMPEG section for enabled codecs

Dead Ends

Common approaches that don't work:

  1. Use raw/uncompressed fourcc to avoid codec issues 68% fail

    Uncompressed video produces enormous files (1080p@30fps ~ 5.6 GB/min). Not a practical solution.

  2. Install a random codec pack 80% fail

    OpenCV uses its bundled FFmpeg or system FFmpeg. Random codec packs do not affect it.