ffmpeg 录制 rtsp 视频和音频,但实际文件持续时间小于实际

问题描述 投票:0回答:2

我有一个批处理脚本来运行 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秒。任何人都可以帮忙解决哪里出了问题吗?谢谢

ffmpeg rtsp
2个回答
1
投票

我不是 ffmpeg 专家,但你将 -r 标志设置为 60 所以这意味着 60FPS, 也许当您的输入源 (RTSP) 不提供 60 FPS 时,您的输出持续时间不是精确的 60 秒。


1
投票

可以添加-c copy。这将以与从源接收到的完全相同的 FPS 进行记录。

© www.soinside.com 2019 - 2024. All rights reserved.