import cv2 import subprocess input_video_path = "/home/navy/Desktop/1.mp4" opencv_video_path = "/home/navy/Desktop/2.mp4" new_video_path = "/home/navy/Desktop/3.mp4" # 打开视频文件 video = cv2.VideoCapture(input_video_path) # 获取视频帧率和尺寸 fps = int(video.get(cv2.CAP_PROP_FPS)) width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 创建输出视频文件 fourcc = cv2.VideoWriter_fourcc(*'mp4v') out = cv2.VideoWriter(opencv_video_path, fourcc, fps, (width, height)) # 处理每一帧并写入输出视频 while True: ret, frame = video.read() if not ret: break # 在这里对每一帧进行处理 # ... out.write(frame) # 释放资源 video.release() out.release() # 使用FFmpeg将音频从原始视频中提取出来并与生成的视频合并 subprocess.call(['ffmpeg', '-i', input_video_path, '-i', opencv_video_path, '-c:v', 'copy', '-c:a', 'aac', '-strict', 'experimental', new_video_path])
标签:视频,ffmpeg,CAP,cv2,opencv,video,path From: https://www.cnblogs.com/navysummer/p/17573753.html