【发布时间】:2022-11-08 10:51:25
【问题描述】:
我有一个批处理脚本来运行 ffmpeg 命令将 RTSP 流视频 + 音频写入 .ts 文件。 rtsp 流来自 IP 摄像机。这是批处理/命令:
set VID_SOURCE=rtsp://192.168.0.80:9000/live
set VIDEO_OPTS=-f mpegts -b:v 800k -r 60 -vcodec libx264 -s 1280x960 -aspect 4:3 -bufsize 6000k
set AUDIO_OPTS=-af asetrate=48000 -acodec aac -b:a 96k -ac 1
ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i %VID_SOURCE% %VIDEO_OPTS% %AUDIO_OPTS% -y %outputpath%\%OUTPUT_FILE%
此批处理由 python 脚本调用,并设置为运行 1 分钟(超时 = 60)。然后杀掉录制进程,如下:
def recording_start(script_path, output_path, output_filename):
# call batch script to start recording
return subprocess.Popen(['cmd', '/c', os.path.join(script_path, 'batch_script.bat'), output_path, output_filename])
# if camera connected
if capture.isOpened():
print('INFO: camera connected')
proc = recording_start(script_path=REC_PATH, output_path=OUTPUT_PATH, output_filename=OUTPUT_FILENAME)
# start recording for "timeout" seconds
try:
print('INFO: start recording')
proc.communicate(timeout=60) # record 60 seconds
# when time's up, will catch the "TimeoutExpired" exception and kill the recording process
except subprocess.TimeoutExpired:
print('{} seconds finished, stop the recording process: {}'.format(timeout, proc.pid))
kill_recording(proc)
print('INFO: recording complete')
print('INFO: recording file saved at {}'.format(OUTPUT_PATH))
break
# still not connected, go back to wait
else:
print('Error opening video stream')
但实际录音文件只有 48 秒长,而不是 60 秒。任何人都可以帮助解决哪里出了问题?谢谢
【问题讨论】: