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
How to write mp4 video file with H264 codec?
Looking for valuable suggestions.
(640, 480)
then you have to change its size before you save it in file. If you don't chage size then it may create empty file and then you can't play it – furas(640,480)
then you may have to doframe = cv2.resize(frame, (640, 480))
before you save it. – furasDIVX
with extension.mp4
then it shows me message thatFFMPEG
can't create it - but if I use extension.avi
then it has no problem to create file. But I use Linux. – furas