opencv
runtime_error
ai_generated
partial
OpenCV: FFMPEG: 初始化: 找不到流0(视频: h264, 无)的编解码器参数: 未指定尺寸
OpenCV: FFMPEG: init: Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
ID: opencv/video-capture-ffmpeg-init-failed
85%修复率
86%置信度
1证据数
2023-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.5.0 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
根因分析
FFmpeg无法解析视频流的编解码器参数,通常由于视频文件头损坏或不完整。
English
FFmpeg cannot parse the video stream's codec parameters, often due to a corrupted or incomplete video file header.
官方文档
https://docs.opencv.org/4.x/dd/d43/tutorial_py_video_display.html解决方案
-
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.
-
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");
无效尝试
常见但无效的做法:
-
75% 失败
The codec (h264) is present, but the video file itself is malformed; reinstalling does not fix file corruption.
-
60% 失败
Changing the extension does not fix the underlying stream metadata; the file must be properly transcoded.