<div>call avformat_find_stream_info was blocked when open rtsp stream from network. how to deal with it.</div><div><div><br></div><div><br></div><div style="padding: 2px 0px; font-family: Arial Narrow; font-size: 12px;">------------------ Original ------------------</div><div style="background: rgb(239, 239, 239); padding: 8px; font-size: 12px;"><div><b>From: </b> "Taha Ansari"<mtaha.ansari@gmail.com>;</div><div><b>Date: </b> Tue, Jan 22, 2013 03:41 PM</div><div><b>To: </b> "This list is about using libavcodec, libavformat, libavutil,libavdevice and libavfilter."<libav-user@ffmpeg.org>; <wbr></div><div></div><div><b>Subject: </b> Re: [Libav-user] Detecting bit rate from live stream</div></div><div><br></div>As an update: I do not call 'avformat_find_stream_info()' after opening codec context, rather, the sequence is as similar to following:<br><br>1- pFormatCtx = avformat_alloc_context();<br>2- rv = avformat_open_input(&this->pFormatCtx, this->finalInputName.c_str(), NULL, NULL);<br>
        if ( this->pFormatCtx == NULL            || <br>            this->pFormatCtx->iformat == NULL    )<br>        {<br>            return -1;<br>        }<br>3- if(avformat_find_stream_info(this->pFormatCtx, NULL)<0)<br>
        return -1; // Couldn't find stream information<br><br>    // Dump information about file onto standard error<br>    av_dump_format(this->pFormatCtx, 0, this->finalInputName.c_str(), 0);<br>4- this->videoStream = -1;<br>
    for(i=0; i<this->pFormatCtx->nb_streams; i++)<br>    {<br>        if(this->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) <br>        {<br>            this->videoStream=i;<br>            break;<br>
        }<br>    }<br>5- if(this->videoStream !=-1)<br>    {<br>        // Get a pointer to the codec context for the video stream<br>        this->pCodecCtxVideo=this->pFormatCtx->streams[this->videoStream]->codec;<br>
<br>        // Find the decoder for the video stream<br>        this->pCodecVideo=avcodec_find_decoder(this->pCodecCtxVideo->codec_id);<br>        if(this->pCodecVideo==NULL) {<br>            fprintf(stderr, "Unsupported avido codec!\n");<br>
            return -1; // Codec not found<br>        }<br>        // Open codec<br>        AVDictionary *codecDictOptions = NULL;<br>        if(avcodec_open2(this->pCodecCtxVideo, this->pCodecVideo, &codecDictOptions)<0)<br>
            return -1; // Could not open codec<br><br>...<br>...<br>...<br>So on...<br><br>So, in words, this is the sequence:<br><br>1- open format context<br>2- get video stream index<br>3- get codec context for video 'from' format context's stream<br>
4- open codec using avcodec_open2 function<br><br><br><div class="gmail_quote">On Tue, Jan 22, 2013 at 12:34 PM, Taha Ansari <span dir="ltr"><<a href="mailto:mtaha.ansari@gmail.com" target="_blank">mtaha.ansari@gmail.com</a>></span> wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">Hi <span>kalileo,<br><br>Thanks for the reply, yes I just tried this - i.e. looking at following code:<br><br>    if(avformat_find_stream_info(this->pFormatCtx, NULL)<0)<br>
        return -1; // Couldn't find stream information<br>
<br>    // Dump information about file onto standard error<br>    av_dump_format(this->pFormatCtx, 0, this->finalInputName.c_str(), 0);<br><br>At time of opening up decoder for live udp stream (like: udp://localhost:8765/a.h264) is still giving me bit_rate '0'.<br>

<br><br></span><div class="HOEnZb"><div class="h5"><div class="gmail_quote">On Tue, Jan 22, 2013 at 10:35 AM, Kalileo <span dir="ltr"><<a href="mailto:kalileo@universalx.net" target="_blank">kalileo@universalx.net</a>></span> wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote">
<div><div><br>
On Jan 22, 2013, at 11:37 , Taha Ansari wrote:<br>
<br>
> Hi,<br>
><br>
> I've been looking deeper into this, unfortunately so far I could not find a way to detect live stream's bit rate, or any way I could some how 'stuff' custom data (which would be bit rate in my case) with the encoder, and extract that on the network decoding end.<br>


><br>
> Kindly, could anyone guide me how can I achieve this? Also any hints are most welcome...<br>
><br>
> Thanks for your time...<br>
><br>
> On Wed, Jan 16, 2013 at 12:48 PM, Taha Ansari <<a href="mailto:mtaha.ansari@gmail.com" target="_blank">mtaha.ansari@gmail.com</a>> wrote:<br>
> Hi!<br>
><br>
> I am using h264 encoding to transmit video to destination network address using udp protocol. I also want to detect bit rate of the encoded frame on receiver end. In the pFormatCtx->bit_rate, and pCodecCtx->bit_rate, I see on receiver end, they are all zero. I understand since it is live streaming bit rate isn't stuffed there, but I would like to know if there is any way I could retrieve actual bit rate frame was transmitted on, on client side (i.e. decoder side decoding video over network).<br>


><br>
> Can anyone kindly provide some guidance or tips on how to do this?<br>
><br>
> Thanks for your time!<br>
><br>
<br>
</div></div>Did you try running  avformat_find_stream_info()  after opening the codec context and before checking the bitrate fields?<br>
<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br></div>