【发布时间】:2020-11-25 13:34:27
【问题描述】:
当我尝试使用 OpenCV2 简单地读写视频时,它会在视频中引入 1.033 倍的延迟 - 例如,3:17 分钟的原始视频在输出视频中变为 3:24 分钟,19:00 分钟变为19:38 分钟。我在这里做错了吗?
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()
【问题讨论】:
-
FRAME_LIMIT是什么?是length吗? -
是的,长度,会更新问题
-
您如何验证视频长度?
-
我正在检查帧数 -
output_movie='output.mp4'; output_movie = cv2.VideoCapture(output_movie); output_movie.get(cv2.CAP_PROP_FRAME_COUNT)并得到相同的数字 -
我的意思是你如何验证视频的持续时间。
标签: opencv image-processing video-processing frame-rate opencv-python