# 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`
- **Domain:** opencv
- **Category:** runtime_error
- **Error Code:** `-2`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

The specified codec (e.g., MJPG, H264) is not supported by the installed FFmpeg or encoder backend on the system.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

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.** (80% success)
   ```
   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.** (70% success)
   ```
   Install a more complete FFmpeg build (e.g., from conda-forge or compile with --enable-libx264) to add missing codecs.
   ```

## Dead Ends

- **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% fail)
- **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% fail)
- **Use .avi extension instead of .mp4** — The extension does not determine the codec; the fourcc code must match a supported encoder. (50% fail)
