<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
this is the piece of code responsable of open the stream :<br>
<br>
    const char *filename = "rtsp://hostname/live.sdp";<br>
<br>
    av_register_all();<br>
    avformat_network_init();<br>
<br>
    AVFormatContext *pFormatCtx = NULL;<br>
<br>
    // Open video file<br>
    if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0){<br>
        std::cout << "could not open file " << filename << std::endl;<br>
        return -1; // Couldn't open file<br>
    }else{<br>
        std::cout << "video opened" << std::endl;<br>
    }<br>
<br>
The problem is that when the host is down the function avformat_open_input does not return any value, it just stay there forever.<br></blockquote></div><br></div><div class="gmail_extra">This is a known behavior. You need to setup a callback mechanism before calling avformat_open_input() function.<br><br></div><div class="gmail_extra">Just before avformat_open_input() call pFormatCtx->interrupt_callback = int_cb;<br><br></div><div class="gmail_extra">where int_cb is the callback function's variable: <br><br>AVIOInterruptCB int_cb;<br><br>with following signature:<br><br>AVIOInterruptCB {<br>    int (*callback)(void*);<br>    void *opaque;<br>}<br><br></div><div class="gmail_extra">set the callback function and implement a timeout mechanism. In general if you return '1' from callback it means to exit from avformat_open_input() function, else return 0 if you want to give it some more time (perhaps also applies to all read operations but you can take it from here).<br><br></div><div class="gmail_extra">some help here:<br><br><a href="https://trac.ffmpeg.org/ticket/2694">https://trac.ffmpeg.org/ticket/2694</a><br><br><br></div></div>