简体   繁体   中英

mp4 video codec in OpenCV

What is the video codec for mp4 in OpenCV 4.1.1.26?

I'm trying to write videos from two cameras, writing AVI video is working fine but writing the mp4 video is not working.

  • Python 3.7
  • OpenCV 4.1.1.26
  • Windows 10

Below is sample code for one camera

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output_1.mp4', fourcc, 15, (640, 480))

I used different codecs (MPEG, H264, mp4v, ('m','p','4','v'), FFmpeg etc.) as in OpenCV 4 Documentations , FOURCC Codecs Documentations and suggested by different experts and helpers on different platforms but any solution is not working in my code, mp4 video is saved but can't be played in any media player even in OpenCV VideoCapture due to problem in codec. On other hand when I save avi video, it works fine. I checked these links to get help.

what is the codec for mp4 videos in python OpenCV

https://medium.com/@iKhushPatel/convert-video-to-images-images-to-video-using-opencv-python-db27a128a481

How to write mp4 video file with H264 codec?

Looking for valuable suggestions.

I also had a similar problem. What I found was that the OpenCV-python usually gets some unexpected errors with the mp4 files (fails to read frames from the mp4 file, etc).

To solve this problem, what I did was re-write codes by using the skvideo(scikit-video). The scikit-video uses the command line FFmpeg tool, so you need to install FFmpeg before using the scikit-video.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM