我正在从流中写入视频文件,当它达到我的总帧数限制时,我想停止视频写入过程。
我试图写一个30秒的视频,但它不准确,所以我尝试根据总帧数(30fps x 30sec =视频中的900个总帧)为基础。 我尝试对输出视频在写入时的总帧数进行计数,但最终导致其失真。
vcap = cv2.VideoCapture('udp://'+cctv_ip+':'+cctv_port+'/')
frame_width = int(vcap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(vcap.get(cv2.CAP_PROP_FRAME_HEIGHT))
frame_rate = int(vcap.get(cv2.CAP_PROP_FPS))
video = cv2.VideoWriter(base_mov_dir+'/carlo.mpg', -1, frame_rate, (frame_width, frame_height))
frameCounter = 0
# while True:
while frameCounter <= 900:
has_frame, frame = vcap.read()
if not has_frame:
print('Can\'t get frame')
break
video.write(frame)
out_vcap = cv2.VideoCapture(base_mov_dir + '/carlo.mpg')
frameCounter = int(out_vcap.get(cv2.CAP_PROP_FRAME_COUNT))
out_vcap.release()
print(frameCounter)
video.release()