读取视频关键帧
import ffmpeg
import numpy
import cv2
i = 0
while True:
stream = ffmpeg.input('file_path', skip_frame='nokey')
stream = stream.filter('select', 'gte(n,{})'.format(i))
stream = stream.output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
frame, err = stream.run(capture_stdout=True)
if not frame:
print('视频源链接断开', strUrl)
time.sleep(5)
break
i += 1
cv2.imshow('show', frame)
cv2.waitKeyEx(1)
逐帧读取视频
import ffmpeg
import numpy
import cv2
i = 0
while True:
stream = ffmpeg.input('file_path')
stream = stream.filter('select', 'gte(n,{})'.format(i))
stream = stream.output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
frame, err = stream.run(capture_stdout=True)
if not frame:
print('视频源链接断开', strUrl)
time.sleep(5)
break
i += 1
cv2.imshow('show', frame)
cv2.waitKeyEx(1)
- 其实这俩个代码也就是ffmpeg中差个参数
- 备注的部分和上边的几行其实是一个意思,但我不是很喜欢备注的那种写法
- 基本就是这些,希望能帮到有缘人
- ffmpeg中的参数,其实我也不是很懂,怎么个和ffepmg命令行的对应关系,我也不懂
- 我对python-ffmpeg的理解就是,我们写的这些python语句,其实经过python-ffmpeg转成了ffmpeg命令行给了ffmpeg,然后ffmpeg输出结果又通过管道返回到了python-ffmpeg。不知道对不对?如果遇上有缘大佬,还望能教教!!!!谢谢谢
- 哦哦,还有几篇很有帮助的文章,放下边啦
- https://blog.csdn.net/jacob210/article/details/112403313
- https://www.bookstack.cn/read/other-doc-cn-ffmpeg/ffmpeg-doc-cn-05.md