python3保存mp4 avi转mp4

动态库名称:

openh264-1.8.0-win64.dll

 


# !/usr/bin/env python
# -*-coding:utf-8-*-
import datetime
import time
import cv2
import os


cam = cv2.VideoCapture(0)
time_now =time.time()
# fourcc = cv2.VideoWriter_fourcc(*'avc1')
os.makedirs('capture', exist_ok=True)

fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
video_out = None

while True:
    ret, frame = cam.read()
    if video_out:
        video_out.write(frame)
    cv2.imshow("asdf", frame)
    cv2.waitKey(1)
    if video_out is None or time.time() - time_now > 10:
        if video_out:
            print("save", video_path)
            video_out.release()
            video_out = None
        timestr = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
        video_path = 'capture/' +timestr + '.mp4'
        video_out = cv2.VideoWriter(video_path, fourcc, 30.0, (640, 480))
        time_now = time.time()

 

你可能感兴趣的:(python,视频编解码)