python+opencv批量读取.mp4视频属性

opencv可以去读.mp4视频的常用属性,参数详见https://blog.csdn.net/u011436429/article/details/80604590

import os
from os import path
import cv2
# 子文件夹
sub = 'ykt.eduyun.cn'

path='G:/CRSR/test_seq/'+sub
videoList = os.listdir(path)
framenum=[]
fps=[]
width=[]
height=[]

for name in videoList:
    cap=cv2.VideoCapture(path+'/'+name)
    framenum.append(cap.get(7)) # 读取帧数
    fps.append(cap.get(5)) # 读取帧率
    height.append(cap.get(4)) # 读取高度
    width.append(cap.get(3)) # 读取宽度
f=open('G:/CRSR/test_seq/'+sub+'_framenum.txt','w')
for i in range(len(framenum)):
  f.write(sub+'\t'+videoList[i]+'\t'+str(width[i])+'x'+str(height[i])+'\t'+str(framenum[i])+'\t'+str(fps[i])+'\n')

其中写入了.txt文件中,全选复制到excel中即可生成表格。(因为excel表格中相邻元素使用\t隔开)

你可能感兴趣的:(python+opencv批量读取.mp4视频属性)