gpt4 book ai didi

python - cv2.VideoCapture 和 ffmpeg

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:36 25 4
gpt4 key购买 nike

如何使用 ffmpeg 通过 OpenCV 读取视频?这是我的代码:

cap = cv2.VideoCapture("input2.mp4")
ret = cap.read()
print ret

结果是(False, None)

我通过 Anaconda 设置了 OpenCV。

最佳答案

我有时在读取 h264 mp4 时遇到错误。 ffmpeg 比 cv2 有更多的编解码器,可以解决读取问题。你可以使用这个pkg,它类似于API中的cv2。

#!pip install ffmpegcv
import ffmpegcv
vfile_in = 'A.mp4'
vfile_out = 'A_h264.mp4'
vidin = ffmpegcv.VideoCapture(vfile_in)
w, h = vidin.width, vidin.height
vidout = ffmpegcv.VideoWriter(vfile_out, 'h264_nvenc', vidin.fps, (w, h))

for frame in vidin:
vidout.write(frame)

vidin.release()
vidout.release()

关于python - cv2.VideoCapture 和 ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42355640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com