python-ffmpeg读取视频关键帧以及逐帧读取视频

读取视频关键帧

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)
	# frame, err = (
	    # ffmpeg
	    # .input('file_path', skip_frame='nokey')
	    # .filter('select', 'gte(n,{})'.format(i))
	    # .output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
	    # .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)
	# frame, err = (
    #     ffmpeg
    #     .input('file_path')
    #     .filter('select', 'gte(n,{})'.format(i))
    #     .output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
    #     .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
  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值