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