opencv encoding_error ai_generated partial

OpenCV: FFMPEG: tag 0x3234504d/'MP42' is not supported with codec id 12

ID: opencv/videowriter-codec-not-supported-linux

Also available as: JSON · Markdown · 中文
70%Fix Rate
80%Confidence
1Evidence
2023-05-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.0 active
4.6.0 active
4.7.0 active
4.8.0 active
4.9.0 active

Root Cause

The specified video codec (MP42) is not supported by the FFMPEG backend on the current system, often due to missing codec libraries or incompatible FFMPEG build.

generic

中文

指定的视频编解码器 (MP42) 不被当前系统上的 FFMPEG 后端支持,通常是因为缺少编解码器库或 FFMPEG 构建不兼容。

Official Documentation

https://docs.opencv.org/4.x/dd/d9e/classcv_1_1VideoWriter.html

Workarounds

  1. 75% success Use a widely supported codec like 'avc1' or 'H264' with FFMPEG: `fourcc = cv2.VideoWriter_fourcc(*'avc1')` and verify with `cv2.VideoWriter.isOpened()`.
    Use a widely supported codec like 'avc1' or 'H264' with FFMPEG: `fourcc = cv2.VideoWriter_fourcc(*'avc1')` and verify with `cv2.VideoWriter.isOpened()`.
  2. 80% success Install the necessary codec libraries: `sudo apt-get install libavcodec-extra` on Ubuntu/Debian or `brew install ffmpeg` on macOS.
    Install the necessary codec libraries: `sudo apt-get install libavcodec-extra` on Ubuntu/Debian or `brew install ffmpeg` on macOS.
  3. 70% success Fall back to a raw video codec like 'I420' (uncompressed) for debugging: `fourcc = cv2.VideoWriter_fourcc(*'I420')`.
    Fall back to a raw video codec like 'I420' (uncompressed) for debugging: `fourcc = cv2.VideoWriter_fourcc(*'I420')`.

中文步骤

  1. Use a widely supported codec like 'avc1' or 'H264' with FFMPEG: `fourcc = cv2.VideoWriter_fourcc(*'avc1')` and verify with `cv2.VideoWriter.isOpened()`.
  2. Install the necessary codec libraries: `sudo apt-get install libavcodec-extra` on Ubuntu/Debian or `brew install ffmpeg` on macOS.
  3. Fall back to a raw video codec like 'I420' (uncompressed) for debugging: `fourcc = cv2.VideoWriter_fourcc(*'I420')`.

Dead Ends

Common approaches that don't work:

  1. 75% fail

    The codec is still MP42, which may not be supported regardless of container format.

  2. 85% fail

    Without FFMPEG, OpenCV uses a different backend (e.g., VFW on Windows) which may have its own limitations.

  3. 65% fail

    XVID might also be unsupported if the codec is not installed; the fix is to use a codec known to work on the system.