码农们是怎么玩拽视频剪辑的!!! 安排上
用python生成视频剪辑的代码
import cv2
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
# 设置输入视频文件路径
input_file = 'input.mp4'
# 设置输出视频文件路径
output_file = 'output.mp4'
# 设置剪辑起始时间和结束时间(单位:秒)
start_time = 10
end_time = 20
# 使用OpenCV读取输入视频文件
cap = cv2.VideoCapture(input_file)
# 获取输入视频的帧率和宽高信息
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# 使用ffmpeg_extract_subclip函数剪辑视频
ffmpeg_extract_subclip(input_file, start_time, end_time, targetname=output_file)
# 使用OpenCV打开剪辑后的输出视频文件
cap = cv2.VideoCapture(output_file)
# 创建视频输出对象
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height))
# 读取视频帧并写入输出视频文件
while cap.isOpened():
ret, frame = cap.read()
if ret:
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# 释放资源
cap.release()
out.release()
cv2.destroyAllWindows()
标签:cap,frame,安排,cv2,码农们,file,视频文件,output,视频剪辑
From: https://blog.csdn.net/weixin_46155462/article/details/139388496