2016-02-01 145 views
2

我正在使用ffmpeg庫寫入到rtsp流。 當rtsp網址正確時,它運行良好。 但是,當這個rtsp網址不正確,然後它卡在avformat_write_header。 有沒有解決這個問題的方法? 謝謝。如何在ffmpeg中設置rtsp連接超時

回答

0

請參考以下鏈接: [FFmpeg-user] How do I set a timeout for an RTSP source?

有選項兩個超時類型RTSP:

'-timeout'

Set maximum timeout (in seconds) to wait for incoming connections. 

A value of -1 mean infinite (default). This option implies the 
‘rtsp_flags’ set to ‘listen’. ‘reorder_queue_size’ 

Set number of packets to buffer for handling of reordered packets. 

'-stimeout'

Set socket TCP I/O timeout in micro seconds. 
+0

我想OP是問libav API。你可能誤解了這個問題。 – bot1131357

+0

在ffmpeg對象(如屬於rtsp流的AVFormatContext)上使用av_opt _ *()設置API選項很簡單。該選項的名稱將與ffmpeg CLI應用程序中的名稱相同。 –

1

'-timeout'&'-stimeout'不適合我。

我的解決方案[Python代碼]是:

while True: 
    try: 
     check_call('ffmpeg -i <rtsp://your-input-stream-url> -frames:v 1 screenshot.jpg', shell=True, timeout=N) # try to get a screenshot if RTSP stream is OK 
    except TimeoutExpired as e: 
     logger.error('RTSP stream error') # send error message if timeout 
     break 

好運。