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
5
* This file is part of FFmpeg.
5
* This file is part of Libav.
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.
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.
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
32
32
const int program_birth_year = 2007;
34
34
static int do_show_format = 0;
35
static int do_show_packets = 0;
35
36
static int do_show_streams = 0;
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;
104
static char *ts_value_string (char *buf, int buf_size, int64_t ts)
106
if (ts == AV_NOPTS_VALUE) {
107
snprintf(buf, buf_size, "N/A");
109
snprintf(buf, buf_size, "%"PRId64, ts);
104
115
static const char *media_type_string(enum AVMediaType media_type)
106
117
switch (media_type) {
127
static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt)
130
AVStream *st = fmt_ctx->streams[pkt->stream_index];
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");
147
static void show_packets(AVFormatContext *fmt_ctx)
151
av_init_packet(&pkt);
153
while (!av_read_frame(fmt_ctx, &pkt))
154
show_packet(fmt_ctx, &pkt);
116
157
static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
118
159
AVStream *stream = fmt_ctx->streams[stream_idx];
139
179
printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den);
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);
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));
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);
235
264
AVFormatContext *fmt_ctx;
237
266
fmt_ctx = avformat_alloc_context();
267
set_context_opts(fmt_ctx, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
239
269
if ((err = av_open_input_file(&fmt_ctx, filename, iformat, 0, NULL)) < 0) {
240
270
print_error(filename, err);
250
dump_format(fmt_ctx, 0, filename, 0);
280
av_dump_format(fmt_ctx, 0, filename, 0);
252
282
/* bind a decoder to each input stream */
253
283
for (i = 0; i < fmt_ctx->nb_streams; i++) {
317
350
static void show_help(void)
352
av_log_set_callback(log_callback_help);
320
354
show_help_options(options, "Main options:\n", 0, 0);
356
av_opt_show2(avformat_opts, NULL,
357
AV_OPT_FLAG_DECODING_PARAM, 0);
324
360
static void opt_pretty(void)
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", "" },
349
386
int main(int argc, char **argv)
351
390
av_register_all();
352
391
#if CONFIG_AVDEVICE
353
392
avdevice_register_all();
395
avformat_opts = avformat_alloc_context();
357
398
parse_options(argc, argv, options, opt_input_file);