简体   繁体   English

openCV - ffmpeg H264 和 Webm 错误

[英]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.我安装了 ubuntu 16.04 LTS 和 OpenCV 3.4.0(Intel i5 和 AMD 显卡),我需要创建一个浏览器支持的视频,该视频可在浏览器中播放。

If I'm using H264 im getting如果我使用的是 H264,我会得到

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如果我使用 webm VP8

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

if I'm using webm VP9如果我使用 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()

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. https://developer.mozilla.org/en-US/docs/Web/Media/Formats请仔细阅读这篇文章,它肯定会对你们有所帮助,因为它对我有很大帮助,它将提供有关编解码器及其适用的详细知识容器类型及其浏览器兼容性。

I recommend please go once through this article.我建议请仔细阅读这篇文章。

After trying many suitable codec combinations, codec 'VP90' with container type 'webm' works for me.在尝试了许多合适的编解码器组合后,容器类型为“webm”的编解码器“VP90”对我有用。 I was using Ubuntu 18.04 LTS and Python3 with 'opencv-python 4.2.0.34'我使用 Ubuntu 18.04 LTS 和 Python3 和“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.谢谢你。

Thanks for the answer I fixed the issue by using multi threading.感谢您的回答我通过使用多线程解决了这个问题。 Since write method takes more time, during that time the opencv might miss the reference frame so I used seperate thread for read and write.由于 write 方法需要更多时间,在此期间 opencv 可能会错过参考系,因此我使用单独的线程进行读写。 Then used to queue to store the images before writing to disk.然后用于在写入磁盘之前排队存储图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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