PyAV是[FFmpeg][FFmpeg]库的python绑定。其目标是提供底层库的所有功能和控制,但是尽可能多地管理细节。PyAV用于通过容器、流、包、编解码器和帧直接而精确地访问您的媒体。它公开了该数据的一些转换,并帮助您从其他包(例如Numpy和Pillow)获取数据。具体安装方法参考GitHub
GitHub地址:https://github.com/PyAV-Org/PyAV
官方网站:https://pyav.org/docs/stable/
使用pyav库提取关键帧代码:
import avimport av.datasetsimport osimport cv2import argparseimport shutilimport mathvIDeos_src_path = './vIDeo/'vIDeos_save_path = './img+/'if not os.path.exists(vIDeos_save_path): os.makedirs(vIDeos_save_path)file_count = 0vIDeos = os.Listdir(vIDeos_src_path)for each_vIDeo in vIDeos: file_count += 1 each_vIDeo_name = each_vIDeo.split('.')[0] each_vIDeo_full_path = os.path.join(vIDeos_src_path, each_vIDeo) img_path = os.path.join(vIDeos_save_path, each_vIDeo_name) if os.path.exists(img_path): shutil.rmtree(img_path) os.mkdir(img_path) container = av.open(each_vIDeo_full_path) # Signal that we only want to look at keyframes. stream = container.streams.vIDeo[0] stream.codec_context.skip_frame = 'NONKEY' for frame in container.decode(stream): # We use `frame.pts` as `frame.index` won't make must sense with the `skip_frame`. frame.to_image().save(img_path + '/' + 'night-sky.{:04d}.jpg'.format(frame.pts), quality=80)print('\nvIDeo numbers:', str(file_count), '\nAll is done ,thanks')
其中官方示例:https://pyav.org/docs/stable/cookbook/basics.html#saving-keyframes
总结以上是内存溢出为你收集整理的python使用pyav库提取视频关键帧全部内容,希望文章能够帮你解决python使用pyav库提取视频关键帧所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)