python3 opencv 视频格式转换

python3 opencv 视频格式转换:

import cv2  
   
#获得视频的格式  
videoCapture = cv2.VideoCapture('ad3.avi')  
   
#获得码率及尺寸  
fps = videoCapture.get(cv2.cv.CV_CAP_PROP_FPS)  
size = (int(videoCapture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),   
        int(videoCapture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))  
   
#指定写视频的格式, I420-avi, MJPG-mp4  
videoWriter = cv2.VideoWriter('oto_other.mp4', cv2.cv.CV_FOURCC('M', 'J', 'P', 'G'), fps, size)  
   
#读帧  
success, frame = videoCapture.read()  
   
while success :  
    cv2.imshow(ad3 Video, frame) #显示  
    cv2.waitKey(1000/int(fps)) #延迟  
    videoWriter.write(frame) #写视频帧  
    success, frame = videoCapture.read() #获取下一帧  

猜你喜欢

转载自blog.csdn.net/qq_40575024/article/details/105908013