-2
opencv
runtime_error
ai_generated
partial
cv2.error: OpenCV(4.8.0) /modules/videoio/src/cap_images.cpp: 错误: (-2:未指定错误) 找不到编码器用于编解码器 0x47504A4D
cv2.error: OpenCV(4.8.0) /modules/videoio/src/cap_images.cpp: error: (-2:Unspecified error) could not find encoder for codec 0x47504A4D
ID: opencv/video-writer-codec-not-found
75%修复率
88%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
根因分析
指定的编解码器(例如 MJPG、H264)不被系统上安装的 FFmpeg 或编码器后端支持。
English
The specified codec (e.g., MJPG, H264) is not supported by the installed FFmpeg or encoder backend on the system.
官方文档
https://docs.opencv.org/4.x/dd/d9e/classcv_1_1VideoWriter.html解决方案
-
List available encoders with 'ffmpeg -encoders' and use a codec that appears in the list. Common working codecs: 'mp4v' (for MP4), 'XVID' (for AVI), 'MJPG' for motion JPEG.
-
Install a more complete FFmpeg build (e.g., from conda-forge or compile with --enable-libx264) to add missing codecs.
无效尝试
常见但无效的做法:
-
Reinstall OpenCV with --with-ffmpeg flag
65% 失败
The issue is not build-time but runtime; FFmpeg may be installed but the specific codec might be missing or disabled in the FFmpeg build.
-
Change codec ID to a random fourcc code
90% 失败
Random codecs are even less likely to be supported; must use a codec known to work with the installed FFmpeg.
-
Use .avi extension instead of .mp4
50% 失败
The extension does not determine the codec; the fourcc code must match a supported encoder.