如何在相对较短的时间内编辑OpenCV中的python视频?



所以我要这样做:

fourcc = cv2.VideoWriter_fourcc(*'avi')
source = cv2.VideoCapture('video.avi')
while(source.isOpened()):
ret, frame = source.read()
if(type(frame) != type(None)):
for line in frame:
for pixel in line:
someedit()

我的问题是,5秒的300:400视频需要大约5分钟,即使someedit()是一些基本的像像素[0]+1。python做这样的事情通常很慢吗,还是有解决办法?

#import deps
import cv2                                                                                                                                                                   
import numpy as np                                                                                                                                                            
#read the video
source = cv2.VideoCapture('videoPath')  
# flag                                                                                                                          
ret = True                                                                                                                                                                    
# iterate through all the frames if the video clip present
while(source.isOpened() and ret):                                                                                                                                                 
#read the frame
ret, frame = source.read()                                                                                                                                                    
#check for flag
if(ret):       
# add 1 to 0th channel                                                                                                                                                                   
frame[:, :, 0] = 1 + frame[:, :, 0]                                                                                                                                   
print("Done")

最新更新