python-视频分帧&多帧合成视频实例

yipeiwu_com5年前Python基础

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

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设计】。

相关文章

深入浅析python 协程与go协程的区别

进程、线程和协程 进程的定义: 进程,是计算机中已运行程序的实体。程序本身只是指令、数据及其组织形式的描述,进程才是程序的真正运行实例。 线程的定义: 操作系统能够进行运算调度的最小单位...

对Pandas DataFrame缺失值的查找与填充示例讲解

查看DataFrame中每一列是否存在空值: temp = data.isnull().any() #列中是否存在空值 print(type(temp)) print(temp)...

Python中无限元素列表的实现方法

本文实例讲述了Python怎么实现无限元素列表的方法,具体实现可使用Yield来完成。 下面所述的2段实例代码通过Python Yield 生成器实现了简单的无限元素列表。 1.递增无限...

详解解决Python memory error的问题(四种解决方案)

昨天在用用Pycharm读取一个200+M的CSV的过程中,竟然出现了Memory Error!简直让我怀疑自己买了个假电脑,毕竟是8G内存i7处理器,一度怀疑自己装了假的内存条。。。。...

python使用pygame框架实现推箱子游戏

python使用pygame框架实现推箱子游戏

本代码来源于 《Python和Pygame游戏开发指南》中的 Star Pusher 游戏,供大家参考,具体内容如下 # Star Pusher (a Sokoban clone)...