import os
import time
import cv2
from pathlib import Path
import glob
start_time = time.time()
result = os.system('ffmpeg -i out.mp4 -f image2 -v quiet ./video_test/frame%05d.jpg')
end_time = time.time()
ffmpeg_total_time = end_time-start_time
image_list = glob.glob('./video_test/*.jpg')
print('解析出来的图片个数:', len(image_list))
print(result)
print(ffmpeg_total_time)
cv_start_time = time.time()
cap = cv2.VideoCapture('./out.mp4')
current_frame = 0
while True:
ret_val, img0 = cap.read()
if ret_val:
cv2.imwrite(str(Path('./video_test/'+str(current_frame)).with_suffix('.jpg')), img0)
current_frame += 1
else:
break
cv_end_time = time.time()
cv_total_time = cv_end_time-cv_start_time
image_list = glob.glob('./video_test/*.jpg')
print('解析出来的图片个数:', len(image_list))
print(cv_total_time)
print("ffmpeg和cv解析的时间差", ffmpeg_total_time - cv_total_time)
frames_num=cap.get(7)
print(frames_num)
完整信息看下边这个
从上边可以看出来
1、ffmpeg解析的速度要比cv2解析的速度快两倍多 2、但是从解析出来的图片大小上看,会发现ffmpeg解析出来的图片明显较小 3、而且两者解析出来的帧也不一样
|