Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openCV - ffmpeg H264 and Webm error

I have ubuntu 16.04 LTS and OpenCV 3.4.0 Installed(Intel i5 and AMD graphics card), I need to create a browser supported video, which is playable in browser.

If I'm using H264 im getting

OpenCV: FFMPEG: tag 0x34363248/'H264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)' OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1' [h264_nvenc @ 0x7f4e0407f5e0] Cannot load libcuda.so.1 Could not open codec 'h264_nvenc': Unspecified error

if I'm using webm VP8

OpenCV: FFMPEG: tag 0x30385056/'VP80' is not supported with codec id 139 and format 'webm / WebM'

if I'm using webm VP9

OpenCV: FFMPEG: tag 0x30395056/'VP90' is not supported with codec id 167 and format 'webm / WebM'

I'm using this code for conversion.

    fourcc = cv2.VideoWriter_fourcc(*'VP80')
    frame = cv2.imread(movements[0].file_path)
    height, width, _ = frame.shape
    event_video_name = video.file_name.split('.')[0] + '_eventvideo.webm'
    event_video = cv2.VideoWriter(path + event_video_name, fourcc, 5, (width, height))

    for _, image in enumerate(movements):
        image = Image.objects.get(id=image.id)
        frame = cv2.imread(image.file_path)
        event_video.write(frame)
    event_video.release()
like image 663
Karthikaeyan Avatar asked Jun 18 '18 12:06

Karthikaeyan


1 Answers

I was facing the same issue this a week. After exploring and wasting lot of time in this, None of them have work for me. https://developer.mozilla.org/en-US/docs/Web/Media/Formats Please go through this article it will definitely help you guys as it help me a lot, it will provide a detail knowledge about codec and its suitable container type and also its browser compatibility.

I recommend please go once through this article.

After trying many suitable codec combinations, codec 'VP90' with container type 'webm' works for me. I was using Ubuntu 18.04 LTS and Python3 with 'opencv-python 4.2.0.34'

fourcc =  cv2.VideoWriter_fourcc(*'VP90')
            self.writer = cv2.VideoWriter('videoName.webm', fourcc, 20, (self.im_width,self.im_height)) 

Some how I still found this error message, but please ignore this if it occurs. Coz above code snippet will process your video and save it in browser compatible format successfully.

Error message:

OpenCV: FFMPEG: tag 0x30395056/'VP90' is not supported with codec id 167 and format 'webm / WebM'

Please ignore this error message, wait and let the video process. Try this, it works. Thank you.

like image 57
Shreyas Chim Avatar answered Oct 23 '22 07:10

Shreyas Chim