python+opencv批量讀取.mp4視頻屬性

opencv可以去讀.mp4視頻的常用屬性,參數(shù)詳見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)) # 讀取幀數(shù)
    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文件中,全選復(fù)制到excel中即可生成表格。(因?yàn)閑xcel表格中相鄰元素使用\t隔開)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容