【发布时间】:2018-11-27 06:54:04
【问题描述】:
我已经安装了 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()
【问题讨论】:
-
确保您的 ffmpeg 支持您尝试使用的编解码器。如果您使用的是 linux,请在终端中输入:
ffmpeg -codecs | grep -P "(h264|VP8|VP9)"。如果您在输出中看到以DEV开头的编解码器,那么您的 ffmpeg 支持它们。 -
DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_crystalhd h264_vdpau ) (encoders: libx264 libx264rgb ) DEV.L. vp8 On2 VP8 (decoders: vp8 libvpx ) (encoders: libvpx ) DEV.L. vp9 Google VP9 (decoders: vp9 libvpx-vp9 ) (encoders: libvpx-vp9 ) -
@zindarod
OpenCV: FFMPEG: tag 0x30385056/'VP80' is not supported with codec id 139 and format 'webm / WebM'遇到同样的问题 -
阅读 this link 了解容器和编解码器的兼容性(即 AVI 和 H.264)。
标签: opencv ffmpeg html5-video h.264 webm