[Libav-user] Detecting bit rate from live stream
Taha Ansari
mtaha.ansari at gmail.com
Tue Jan 22 08:41:51 CET 2013
As an update: I do not call 'avformat_find_stream_info()' after opening
codec context, rather, the sequence is as similar to following:
1- pFormatCtx = avformat_alloc_context();
2- rv = avformat_open_input(&this->pFormatCtx,
this->finalInputName.c_str(), NULL, NULL);
if ( this->pFormatCtx == NULL ||
this->pFormatCtx->iformat == NULL )
{
return -1;
}
3- if(avformat_find_stream_info(this->pFormatCtx, NULL)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
av_dump_format(this->pFormatCtx, 0, this->finalInputName.c_str(), 0);
4- this->videoStream = -1;
for(i=0; i<this->pFormatCtx->nb_streams; i++)
{
if(this->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
this->videoStream=i;
break;
}
}
5- if(this->videoStream !=-1)
{
// Get a pointer to the codec context for the video stream
this->pCodecCtxVideo=this->pFormatCtx->streams[this->videoStream]->codec;
// Find the decoder for the video stream
this->pCodecVideo=avcodec_find_decoder(this->pCodecCtxVideo->codec_id);
if(this->pCodecVideo==NULL) {
fprintf(stderr, "Unsupported avido codec!\n");
return -1; // Codec not found
}
// Open codec
AVDictionary *codecDictOptions = NULL;
if(avcodec_open2(this->pCodecCtxVideo, this->pCodecVideo,
&codecDictOptions)<0)
return -1; // Could not open codec
...
...
...
So on...
So, in words, this is the sequence:
1- open format context
2- get video stream index
3- get codec context for video 'from' format context's stream
4- open codec using avcodec_open2 function
On Tue, Jan 22, 2013 at 12:34 PM, Taha Ansari <mtaha.ansari at gmail.com>wrote:
> Hi kalileo,
>
> Thanks for the reply, yes I just tried this - i.e. looking at following
> code:
>
> if(avformat_find_stream_info(this->pFormatCtx, NULL)<0)
> return -1; // Couldn't find stream information
>
> // Dump information about file onto standard error
> av_dump_format(this->pFormatCtx, 0, this->finalInputName.c_str(), 0);
>
> At time of opening up decoder for live udp stream (like:
> udp://localhost:8765/a.h264) is still giving me bit_rate '0'.
>
>
> On Tue, Jan 22, 2013 at 10:35 AM, Kalileo <kalileo at universalx.net> wrote:
>
>>
>> On Jan 22, 2013, at 11:37 , Taha Ansari wrote:
>>
>> > Hi,
>> >
>> > 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.
>> >
>> > Kindly, could anyone guide me how can I achieve this? Also any hints
>> are most welcome...
>> >
>> > Thanks for your time...
>> >
>> > On Wed, Jan 16, 2013 at 12:48 PM, Taha Ansari <mtaha.ansari at gmail.com>
>> wrote:
>> > Hi!
>> >
>> > 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).
>> >
>> > Can anyone kindly provide some guidance or tips on how to do this?
>> >
>> > Thanks for your time!
>> >
>>
>> Did you try running avformat_find_stream_info() after opening the codec
>> context and before checking the bitrate fields?
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130122/b0b3e133/attachment.html>
More information about the Libav-user
mailing list