Error while saving video as MP4 using videoWriter(OpenCV) in Ubuntu

1

I am trying to save a video file as MP4 format in ubuntu16.04 using videoWriter function as below

int frame_width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
VideoWriter video("/home/Desktop/1.mp4",CV_FOURCC('M','J','P','G'),10, Size(frame_width,frame_height));

But I am getting the error as below:

OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 8 and format 'mp4 / MP4 (MPEG-4 Part 14)' 

OpenCV: FFMPEG: fallback to use tag 0x0000006c/'l???

When I change my output file extension to .avi, I get no error but VLC player doesn't display any video. I tried different players also but in vain.

I even did the following thinking my VLC might be a problem but didn't work. Really in need of a solution

sudo apt-get ubuntu-restricted-extras
c++
opencv
asked on Stack Overflow Feb 18, 2019 by Madhumathi

1 Answer

0

As per this link, Writing x264 from OpenCV 3 with FFmpeg on Linux the terminal message OpenCV: FFMPEG: tag 0x47504a4d/'MJPG' is not supported with codec id 8 and format 'mp4 / MP4 (MPEG-4 Part 14)' is not an error but a warning that the codec type is incompatible with ffmpeg and mp4 container. However, it does generate the output videofile.

If MJPG codec does not matter to you, then try to replace it with 0x21 and check the output.

VideoWriter video("/home/Desktop/1.mp4",0x21,10, Size(frame_width,frame_height));

If your video still does not play then probably, your VideoWriter is not writing any frames to video. You can check if there are any frames in the written output video by your algorithm.

For more clarifications you can check the VideoWriter class refernce https://docs.opencv.org/3.4.3/dd/d9e/classcv_1_1VideoWriter.html

Thanks

answered on Stack Overflow Feb 18, 2019 by TheLazy

User contributions licensed under CC BY-SA 3.0