[Libav-user] Problem in Getting Stream Information

Vijay Ajay namballa.vijaykumar at gmail.com
Sat May 26 08:09:35 CEST 2012


Hi,

I am using libavformat to get the stream information...but there is a
problem in getting the total stram information

here is my code...



typedef struct Duration
{
int hours, mins, secs, us;
}Duration;

Duration getDuration(AVFormatContext *ic)
{
Duration dur;
if (ic->duration != AV_NOPTS_VALUE)
{
            dur.secs = ic->duration / AV_TIME_BASE;
            dur.us = ic->duration % AV_TIME_BASE;
            dur.mins = dur.secs / 60;
            dur.secs %= 60;
            dur.hours = dur.mins / 60;
            dur.mins %= 60;
            //printf("%02d:%02d:%02d.%02d", hours, mins, secs,(100 * us) /
AV_TIME_BASE);
}
return dur;
}

double getBitrate(AVFormatContext *ic)
{
return (ic->bit_rate)? (double)ic->bit_rate / 1000 : 0.0;
}

int main(int argc,char **argv)
{
 Duration dur;
AVFormatContext *ic=NULL;
int bitrate;

AVDictionary *tag=NULL;
AVDictionaryEntry *elemts = NULL;

    av_register_all();
 int is_output = 0;
char url[35];
strcpy(url,argv[1]);

if(avformat_open_input(&ic,argv[1],NULL,NULL))
return -1;
 avformat_find_stream_info(ic,NULL);

 uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
    if (ic->nb_streams && !printed)
        return -1;

printf("%s #%d, %s, %s '%s':\n",is_output ? "Output" : "Input",0,is_output
? ic->oformat->name : ic->iformat->name,is_output ? "to" : "from", url);

printf("\n Duration : ");
        dur = getDuration(ic);
printf("%02d:%02d:%02d.%02d %llu\n", dur.hours, dur.mins, dur.secs,(100 *
dur.us) / AV_TIME_BASE,ic->duration);


int i;
printf("\n Chapters : %d",*ic->nb_chapters*);
for (i = 0; i < *ic->nb_chapters*; i++)
{
        AVChapter *ch = ic->chapters[i];
        printf("Chapter #%d.%d: ", 0, i);
        printf("start %f, ", ch->start * av_q2d(ch->time_base));
        printf("end %f\n",ch->end*av_q2d(ch->time_base));
}



bitrate = getBitrate(ic);
printf("\n Bitrate : %d kb/s.",bitrate);

if(ic->*nb_programs*)
{
        int j, k, total = 0;
        for(j=0; j<ic->*nb_programs*; j++)
{
            AVDictionaryEntry *name =
av_dict_get(ic->programs[j]->metadata,"name", NULL, 0);
            printf("  Program %d %s\n", ic->programs[j]->id,name ?
name->value : "");
            //dump_metadata(NULL, ic->programs[j]->metadata, "    ");
            for(k=0; k<ic->programs[j]->nb_stream_indexes; k++)
{
                //dump_stream_format(ic, ic->programs[j]->stream_index[k],
index, is_output);
                printed[ic->programs[j]->stream_index[k]] = 1;
            }
             total += ic->programs[j]->nb_stream_indexes;
        }
if (total < ic->nb_streams)
        printf("  No Program\n");
    }

avformat_free_context(ic);


return 0;
}

compiling this code iam only getting bitrate and duration.. and i am not
able to get the remaining information such as fps audio metadata.......

ic->nb_chapters and ic->nb_programs is set to 0.

what shall i do to get the complete stream info.



thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120526/da759843/attachment.html>


More information about the Libav-user mailing list