FFmpeg is blocked by default when parsing a network stream with Avformat_open_input ().
When a network stream that resolves an error is encountered, it causes the function to not return for a long time.
To do this you can set the parameters of the FFmpeg-stimeout, note that the-stimeout unit is US subtle.
The usage is set before the resolved URL (where the timeout is set to 5 seconds) that is:
"FFmpeg -stimeout 5000000-i rtsp://admin:[email protected]:554/h264 ...."
Or:
"FFmpeg -stimeout 5000000 -rtsp_transport tcp-i rtsp://admin:[email protected]:554/h264 ..."
Note: The-stimeout setting is not useful after the URL you want to parse.
=============================================
Information found on the Web:
First:
" to see the source code of the FFmpeg tcp.c (the blocked network address is basically the TCP protocol), search the above two keywords, it is clear how to exit." My previous article only said open when blocking, in fact, the network environment is complex, it is possible to read or write when the network or blocking exception. But the foundation is in tcp.c this file. Set the Interrupt_callback and timeout so that you can solve these problems. "
Second:
Theffmpeg avformat_open_input () is blocked by default, and the user can set the ic->flags |= Avfmt_flag_nonblock; Set to non-blocking (usually not recommended), or set timeout to set time-out, or set the Interrupt_callback definition return mechanism.
attach a code reference below.
IC = Avformat_alloc_context ();
if (ic = = NULL) {
ERR ("error avformat_alloc_context \ n");
return-1;
}
ic->interrupt_callback.callback = TVIE_DECODE_INTERRUPT_CB;
ic->interrupt_callback.opaque = handle;
//ic->flags |= Avfmt_flag_nonblock;
if (strncmp (Handle->params.path, "rtmp:", sizeof ("rtmp:")) = = 0) {
Av_dict_set (&opts, "timeout", "6", 0);//in secs
}
Else if (strncmp (Handle->params.path, "http:", sizeof ("http:")) = = 0) {
Av_dict_set (&opts, "timeout", "6000", 0);//in Ms
}
err = Avformat_open_input (&ic, Handle->params.path, NULL, &opts);
FFmpeg setting Avformat_open_input () timeout-stimeout