# cv2.error: OpenCV(4.8.0) /modules/videoio/src/cap_images.cpp: 错误: (-2:未指定错误) 找不到编码器用于编解码器 0x47504A4D

- **ID:** `opencv/video-writer-codec-not-found`
- **领域:** opencv
- **类别:** runtime_error
- **错误码:** `-2`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

指定的编解码器（例如 MJPG、H264）不被系统上安装的 FFmpeg 或编码器后端支持。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## 解决方案

1. ```
   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.
   ```
2. ```
   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** — 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. (65% 失败率)
- **Change codec ID to a random fourcc code** — Random codecs are even less likely to be supported; must use a codec known to work with the installed FFmpeg. (90% 失败率)
- **Use .avi extension instead of .mp4** — The extension does not determine the codec; the fourcc code must match a supported encoder. (50% 失败率)
