I couldn't get that code to run on my Windows 10 machine either.
So here's what I did:
- I followed these instructions and installed the latest ffmpeg build on machine:
- Download the latest static build for Windows and then extract the files. You may need 7zip to extract.
- Create a folder in C:\ called
ffmpeg
- Copy the contents of the extracted files into C:\ffmpeg
- Edit your PATH environment variable to append at the end the following entry:
C:\ffmpeg\bin;
- Confirm that everything is working correct by opening a cmd prompt and enter the following (Note you might need to run cmd as administrator):
ffmpeg -version
我通过这些步骤,通过安装最新的ffmpeg 在机器上
1.下载最新的static build for Windows 然后解压这些文件
2.创建一个文件在C盘下面,文件名叫做ffmpeg
3.复制上面解压出来的文件到ffmpeg文件中
4.设置环境变量(网上搜索就好)复制上述变量名字到里面就可以
5.确定所有的工作都可以正常运行通过cmd打开命令行输入ffmpeg -version
最后在自己openCV代码中写入文件的格式改成mp4格式
如:
cv::VideoWriter writer("VideoTest.mp4", cv::CAP_OPENCV_MJPEG, rate, videoSize);
这段是在网站上搜索到的:翻译部分是我自己写的。链接在这贴出来: https://stackoverflow.com/questions/36643139/python-and-opencv-cannot-write-readable-avi-video-files/36647509