我有一个小时长的视频,我想保存一个夹在两个时间戳之间--比如说,11:20-11:35。这是一帧一帧的最佳方式,还是有更好的方法?
发布于 2022-06-14 16:23:30
这是我一片狼藉所做的事情的要点。如果有更少的方法做这件事,我很想知道!我知道我可以在终端上使用ffmpeg完成它,但是我很好奇如何最好地使用cv2来完成它。
def get_clip(input_filename, output_filename, start_sec, end_sec):
# input and output videos are probably mp4
vidcap = cv2.VideoCapture(input_filename)
# math to find starting and ending frame number
fps = find_frames_per_second(vidcap)
start_frame = int(start_sec*fps)
end_frame = int(end_sec*fps)
vidcap.set(cv2.CAP_PROP_POS_FRAMES,start_frame)
# open video writer
vidwrite = cv2.VideoWriter(output_filename, cv2.VideoWriter_fourcc(*'MP4V'), fps, get_frame_size(vidcap))
success, image = vidcap.read()
frame_count = start_frame
while success and (frame_count < end_frame):
vidwrite.write(image) # write frame into video
success, image = vidcap.read() # read frame from video
frame_count+=1
vidwrite.release()https://stackoverflow.com/questions/72605811
复制相似问题