# OpenCV: FFMPEG: 初始化: 找不到流0（视频: h264, 无）的编解码器参数: 未指定尺寸

- **ID:** `opencv/video-capture-ffmpeg-init-failed`
- **领域:** opencv
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

FFmpeg无法解析视频流的编解码器参数，通常由于视频文件头损坏或不完整。

## 版本兼容性

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

## 解决方案

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.
   ```
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");
   ```

## 无效尝试

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