openCV-ffmpeg H264和Webm错误

问题描述 投票:7回答:1

我安装了Ubuntu 16.04 LTS和OpenCV 3.4.0(Intel i5和AMD显卡),我需要创建一个受浏览器支持的视频,该视频可以在浏览器中播放。

如果我正在使用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

如果我使用的是webm VP8

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

如果我使用的是webm VP9

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

我正在使用此代码进行转换。

    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()
opencv ffmpeg html5-video h.264 webm
1个回答
0
投票

我本周面临着同样的问题。在探索和浪费大量时间之后,他们都没有为我工作。https://developer.mozilla.org/en-US/docs/Web/Media/Formats请仔细阅读本文,它肯定会对您有所帮助,因为它对我有很大帮助,它将提供有关编解码器及其适合的容器类型以及浏览器兼容性的详细知识。

我建议请仔细阅读本文。

[尝试了许多合适的编解码器组合后,容器类型为'webm'的编解码器'VP90'对我有用。我在使用带有'opencv-python 4.2.0.34'的Ubuntu 18.04 LTS和Python3

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

以某种方式仍然可以找到此错误消息,但是如果发生,请忽略此错误。因为上面的代码片段将处理您的视频,并将其成功保存为与浏览器兼容的格式。

错误消息:

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

请忽略此错误消息,请等待并处理视频。试试这个,行得通。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.