# OpenCV: FFMPEG: init: Could not find codec parameters for stream 0 (Video: h264, none): unspecified size

- **ID:** `opencv/video-capture-ffmpeg-init-failed`
- **Domain:** opencv
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

FFmpeg cannot parse the video stream's codec parameters, often due to a corrupted or incomplete video file header.

## Version Compatibility

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

## Workarounds

1. **Re-encode the video file using FFmpeg with a clean header: ffmpeg -i corrupted.mp4 -c:v libx264 -preset fast -crf 23 -c:a aac fixed.mp4. Then open the fixed file in OpenCV.** (90% success)
   ```
   Re-encode the video file using FFmpeg with a clean header: ffmpeg -i corrupted.mp4 -c:v libx264 -preset fast -crf 23 -c:a aac fixed.mp4. Then open the fixed file in OpenCV.
   ```
2. **Use OpenCV's VideoCapture with the CAP_FFMPEG backend and set the FFMPEG debug flag to get more details: cv::VideoCapture cap; cap.set(cv::CAP_PROP_FFMPEG_DEBUG, 1); cap.open("video.mp4");** (70% success)
   ```
   Use OpenCV's VideoCapture with the CAP_FFMPEG backend and set the FFMPEG debug flag to get more details: cv::VideoCapture cap; cap.set(cv::CAP_PROP_FFMPEG_DEBUG, 1); cap.open("video.mp4");
   ```

## Dead Ends

- **** — The codec (h264) is present, but the video file itself is malformed; reinstalling does not fix file corruption. (75% fail)
- **** — Changing the extension does not fix the underlying stream metadata; the file must be properly transcoded. (60% fail)
