~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to ffprobe.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-19 15:04:55 UTC
  • mfrom: (1.2.1 upstream)
  • mto: (1.3.4 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20110419150455-c1nac6gjm3t2aa4n
Tags: 4:0.7~b1-1
* New upstream version
* bump SONAME and SHLIBS
* configure flags --disable-stripping was removed upstream
* the MAINTAINERS file was removed upstream
* remove patch disable-configuration-warning.patch
* drop avfilter confflags, it is enable by default in 0.7
* libfaad wrapper has been removed upstream
* also update the *contents* of the lintian overrides

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * FFprobe : Simple Media Prober based on the FFmpeg libraries
 
2
 * FFprobe : Simple Media Prober based on the Libav libraries
3
3
 * Copyright (c) 2007-2010 Stefano Sabatini
4
4
 *
5
 
 * This file is part of FFmpeg.
 
5
 * This file is part of Libav.
6
6
 *
7
 
 * FFmpeg is free software; you can redistribute it and/or
 
7
 * Libav is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
9
9
 * License as published by the Free Software Foundation; either
10
10
 * version 2.1 of the License, or (at your option) any later version.
11
11
 *
12
 
 * FFmpeg is distributed in the hope that it will be useful,
 
12
 * Libav is distributed in the hope that it will be useful,
13
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
15
 * Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with FFmpeg; if not, write to the Free Software
 
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
32
32
const int program_birth_year = 2007;
33
33
 
34
34
static int do_show_format  = 0;
 
35
static int do_show_packets = 0;
35
36
static int do_show_streams = 0;
36
37
 
37
 
static int convert_tags                 = 0;
38
38
static int show_value_unit              = 0;
39
39
static int use_value_prefix             = 0;
40
40
static int use_byte_value_binary_prefix = 0;
101
101
    return buf;
102
102
}
103
103
 
 
104
static char *ts_value_string (char *buf, int buf_size, int64_t ts)
 
105
{
 
106
    if (ts == AV_NOPTS_VALUE) {
 
107
        snprintf(buf, buf_size, "N/A");
 
108
    } else {
 
109
        snprintf(buf, buf_size, "%"PRId64, ts);
 
110
    }
 
111
 
 
112
    return buf;
 
113
}
 
114
 
104
115
static const char *media_type_string(enum AVMediaType media_type)
105
116
{
106
117
    switch (media_type) {
113
124
    }
114
125
}
115
126
 
 
127
static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
 
128
{
 
129
    char val_str[128];
 
130
    AVStream *st = fmt_ctx->streams[pkt->stream_index];
 
131
 
 
132
    printf("[PACKET]\n");
 
133
    printf("codec_type=%s\n"   , media_type_string(st->codec->codec_type));
 
134
    printf("stream_index=%d\n" , pkt->stream_index);
 
135
    printf("pts=%s\n"          , ts_value_string  (val_str, sizeof(val_str), pkt->pts));
 
136
    printf("pts_time=%s\n"     , time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base));
 
137
    printf("dts=%s\n"          , ts_value_string  (val_str, sizeof(val_str), pkt->dts));
 
138
    printf("dts_time=%s\n"     , time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base));
 
139
    printf("duration=%s\n"     , ts_value_string  (val_str, sizeof(val_str), pkt->duration));
 
140
    printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base));
 
141
    printf("size=%s\n"         , value_string     (val_str, sizeof(val_str), pkt->size, unit_byte_str));
 
142
    printf("pos=%"PRId64"\n"   , pkt->pos);
 
143
    printf("flags=%c\n"        , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_');
 
144
    printf("[/PACKET]\n");
 
145
}
 
146
 
 
147
static void show_packets(AVFormatContext *fmt_ctx)
 
148
{
 
149
    AVPacket pkt;
 
150
 
 
151
    av_init_packet(&pkt);
 
152
 
 
153
    while (!av_read_frame(fmt_ctx, &pkt))
 
154
        show_packet(fmt_ctx, &pkt);
 
155
}
 
156
 
116
157
static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
117
158
{
118
159
    AVStream *stream = fmt_ctx->streams[stream_idx];
120
161
    AVCodec *dec;
121
162
    char val_str[128];
122
163
    AVMetadataTag *tag = NULL;
123
 
    char a, b, c, d;
124
164
    AVRational display_aspect_ratio;
125
165
 
126
166
    printf("[STREAM]\n");
139
179
        printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den);
140
180
 
141
181
        /* print AVI/FourCC tag */
142
 
        a = dec_ctx->codec_tag     & 0xff;
143
 
        b = dec_ctx->codec_tag>>8  & 0xff;
144
 
        c = dec_ctx->codec_tag>>16 & 0xff;
145
 
        d = dec_ctx->codec_tag>>24 & 0xff;
146
 
        printf("codec_tag_string=");
147
 
        if (isprint(a)) printf("%c", a); else printf("[%d]", a);
148
 
        if (isprint(b)) printf("%c", b); else printf("[%d]", b);
149
 
        if (isprint(c)) printf("%c", c); else printf("[%d]", c);
150
 
        if (isprint(d)) printf("%c", d); else printf("[%d]", d);
151
 
        printf("\ncodec_tag=0x%04x\n", dec_ctx->codec_tag);
 
182
        av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag);
 
183
        printf("codec_tag_string=%s\n", val_str);
 
184
        printf("codec_tag=0x%04x\n", dec_ctx->codec_tag);
152
185
 
153
186
        switch (dec_ctx->codec_type) {
154
187
        case AVMEDIA_TYPE_VIDEO:
186
219
    printf("r_frame_rate=%d/%d\n",         stream->r_frame_rate.num,   stream->r_frame_rate.den);
187
220
    printf("avg_frame_rate=%d/%d\n",       stream->avg_frame_rate.num, stream->avg_frame_rate.den);
188
221
    printf("time_base=%d/%d\n",            stream->time_base.num,      stream->time_base.den);
189
 
    if (stream->language[0])
190
 
        printf("language=%s\n",            stream->language);
191
222
    printf("start_time=%s\n",   time_value_string(val_str, sizeof(val_str), stream->start_time,
192
223
                                                  &stream->time_base));
193
224
    printf("duration=%s\n",     time_value_string(val_str, sizeof(val_str), stream->duration,
221
252
    printf("bit_rate=%s\n",         value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate,
222
253
                                                 unit_bit_per_second_str));
223
254
 
224
 
    if (convert_tags)
225
 
        av_metadata_conv(fmt_ctx, NULL, fmt_ctx->iformat->metadata_conv);
226
255
    while ((tag = av_metadata_get(fmt_ctx->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
227
256
        printf("TAG:%s=%s\n", tag->key, tag->value);
228
257
 
235
264
    AVFormatContext *fmt_ctx;
236
265
 
237
266
    fmt_ctx = avformat_alloc_context();
 
267
    set_context_opts(fmt_ctx, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
238
268
 
239
269
    if ((err = av_open_input_file(&fmt_ctx, filename, iformat, 0, NULL)) < 0) {
240
270
        print_error(filename, err);
247
277
        return err;
248
278
    }
249
279
 
250
 
    dump_format(fmt_ctx, 0, filename, 0);
 
280
    av_dump_format(fmt_ctx, 0, filename, 0);
251
281
 
252
282
    /* bind a decoder to each input stream */
253
283
    for (i = 0; i < fmt_ctx->nb_streams; i++) {
275
305
    if ((ret = open_input_file(&fmt_ctx, filename)))
276
306
        return ret;
277
307
 
 
308
    if (do_show_packets)
 
309
        show_packets(fmt_ctx);
 
310
 
278
311
    if (do_show_streams)
279
312
        for (i = 0; i < fmt_ctx->nb_streams; i++)
280
313
            show_stream(fmt_ctx, i);
316
349
 
317
350
static void show_help(void)
318
351
{
 
352
    av_log_set_callback(log_callback_help);
319
353
    show_usage();
320
354
    show_help_options(options, "Main options:\n", 0, 0);
321
355
    printf("\n");
 
356
    av_opt_show2(avformat_opts, NULL,
 
357
                 AV_OPT_FLAG_DECODING_PARAM, 0);
322
358
}
323
359
 
324
360
static void opt_pretty(void)
331
367
 
332
368
static const OptionDef options[] = {
333
369
#include "cmdutils_common_opts.h"
334
 
    { "convert_tags", OPT_BOOL, {(void*)&convert_tags}, "convert tag names to the FFmpeg generic tag names" },
335
370
    { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" },
336
371
    { "unit", OPT_BOOL, {(void*)&show_value_unit}, "show unit of the displayed values" },
337
372
    { "prefix", OPT_BOOL, {(void*)&use_value_prefix}, "use SI prefixes for the displayed values" },
342
377
    { "pretty", 0, {(void*)&opt_pretty},
343
378
      "prettify the format of displayed values, make it more human readable" },
344
379
    { "show_format",  OPT_BOOL, {(void*)&do_show_format} , "show format/container info" },
 
380
    { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" },
345
381
    { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
 
382
    { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
346
383
    { NULL, },
347
384
};
348
385
 
349
386
int main(int argc, char **argv)
350
387
{
 
388
    int ret;
 
389
 
351
390
    av_register_all();
352
391
#if CONFIG_AVDEVICE
353
392
    avdevice_register_all();
354
393
#endif
355
394
 
 
395
    avformat_opts = avformat_alloc_context();
 
396
 
356
397
    show_banner();
357
398
    parse_options(argc, argv, options, opt_input_file);
358
399
 
363
404
        exit(1);
364
405
    }
365
406
 
366
 
    return probe_file(input_filename);
 
407
    ret = probe_file(input_filename);
 
408
 
 
409
    av_free(avformat_opts);
 
410
 
 
411
    return ret;
367
412
}