当我尝试使用OpenCV2简单地读写视频时,它在视频中引入了1.033倍的延迟-例如,原始视频3:17min变为输出视频中的3:24min,19:00min变为19:38min 。我在这里做错什么了吗?
FPS(29)和帧数在输入和输出视频中保持不变。(我正在尝试进行面部识别,但是我想先找出延迟)
input_movie = cv2.VideoCapture(video_under_analysis)
length = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))
width, height = (
int(input_movie.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(input_movie.get(cv2.CAP_PROP_FRAME_HEIGHT))
)
fps = int(input_movie.get(cv2.CAP_PROP_FPS))
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
output_movie = cv2.VideoWriter()
output_file_name = "output.mp4"
# Define the codec and create VideoWriter object
output_movie.open(output_file_name, fourcc, fps, (width, height), True)
frame_number = 0
FRAME_LIMIT = length
while True:
ret, frame = input_movie.read()
frame_number += 1
if not ret or frame_number > FRAME_LIMIT:
break
if frame is not None:
output_movie.write(frame)
update_progress(1)
output_movie.release()
input_movie.release()
cv2.destroyAllWindows()
我认为问题可能出在这方面
fps = int(input_movie.get(cv2.CAP_PROP_FPS))
您正在将float
值转换为int
。输入视频的fps可能约为float
29.9,已转换为29。因此,恒定滞后。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句