FFmpeg setting Avformat_open_input () timeout-stimeout

Source: Internet
Author: User



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.