我使用的是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 -codecs | grep -P "(h264|VP8|VP9)"
。如果你在输出中看到以DEV
开头的编解码器,则说明你的ffmpeg支持它们。 - zindarodDEV.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 )
- Karthikaeyantag 0x30385056/'VP80' is not supported with codec id 139 and format 'webm / WebM'
,我也遇到了同样的问题。 - Karthikaeyan