我就废话不多说了,直接上代码吧!

1.视频分帧:

import cv2
vidcap = cv2.VideoCapture('005.avi')
success,image = vidcap.read()
count = 0
success = True
while success:
 success,image = vidcap.read()
 cv2.imwrite("frame%d.jpg" % count, image)   # save frame as JPEG file
 if cv2.waitKey(10) == 27:           
   break
 count += 1

2.多帧合成视频:

import cv2
 
def images_to_video():
  fps = 30 # 帧率
  num_frames = 500
  img_array = []
  img_width = 720
  img_height = 1280
  for i in range(num_frames+1):
    filename = "./frames/"+str(i)+".png"
    img = cv2.imread(filename)
 
    if img is None:
      print(filename + " is non-existent!")
      continue
    img_array.append(img)
 
  out = cv2.VideoWriter('demo.avi', cv2.VideoWriter_fourcc(*'DIVX'), fps,(img_width,img_height))
 
  for i in range(len(img_array)):
    out.write(img_array[i])
  out.release()
 
 
def main():
  
  images_to_video()
 
 
if __name__ == "__main__":
  main()

以上这篇python-视频分帧&多帧合成视频实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
python,视频分帧,多帧,合成

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
评论“python-视频分帧&多帧合成视频实例”
暂无“python-视频分帧&多帧合成视频实例”评论...