From 9e12f0bf5f45361a36f9d8c3abca24af55ca740c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 26 Jul 2011 19:04:43 +0200 Subject: Rename ffprobe to avprobe. --- .gitignore | 2 +- Changelog | 2 +- Makefile | 4 +- avprobe.c | 419 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 8 +- doc/avplay.texi | 2 +- doc/avprobe.texi | 134 +++++++++++++++++ doc/ffmpeg.texi | 2 +- doc/ffprobe.texi | 134 ----------------- doc/ffserver.texi | 2 +- ffprobe.c | 419 ------------------------------------------------------ 11 files changed, 564 insertions(+), 564 deletions(-) create mode 100644 avprobe.c create mode 100644 doc/avprobe.texi delete mode 100644 doc/ffprobe.texi delete mode 100644 ffprobe.c diff --git a/.gitignore b/.gitignore index e867470820..5fb57b11b6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ doc/*.pod doxy ffmpeg avplay -ffprobe +avprobe ffserver libavcodec/*_tablegen libavcodec/*_tables.c diff --git a/Changelog b/Changelog index ad3d867cb4..6cdafbabf6 100644 --- a/Changelog +++ b/Changelog @@ -5,7 +5,7 @@ releases are sorted from youngest to oldest. version : - BWF muxer - Flash Screen Video 2 decoder -- ffplay renamed to avplay +- ffplay/ffprobe renamed to avplay/avprobe version 0.7: diff --git a/Makefile b/Makefile index 5214f5a45e..958ef8a14b 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ COMPILE_S = $(call COMPILE,AS) PROGS-$(CONFIG_FFMPEG) += ffmpeg PROGS-$(CONFIG_AVPLAY) += avplay -PROGS-$(CONFIG_FFPROBE) += ffprobe +PROGS-$(CONFIG_AVPROBE) += avprobe PROGS-$(CONFIG_FFSERVER) += ffserver PROGS := $(PROGS-yes:%=%$(EXESUF)) @@ -64,7 +64,7 @@ HOSTPROGS := $(TESTTOOLS:%=tests/%) TOOLS = qt-faststart trasher TOOLS-$(CONFIG_ZLIB) += cws2fws -BASENAMES = ffmpeg avplay ffprobe ffserver +BASENAMES = ffmpeg avplay avprobe ffserver ALLPROGS = $(BASENAMES:%=%$(EXESUF)) ALLMANPAGES = $(BASENAMES:%=%.1) diff --git a/avprobe.c b/avprobe.c new file mode 100644 index 0000000000..3843af9b72 --- /dev/null +++ b/avprobe.c @@ -0,0 +1,419 @@ +/* + * avprobe : Simple Media Prober based on the Libav libraries + * Copyright (c) 2007-2010 Stefano Sabatini + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include "libavformat/avformat.h" +#include "libavcodec/avcodec.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/dict.h" +#include "libavdevice/avdevice.h" +#include "cmdutils.h" + +const char program_name[] = "avprobe"; +const int program_birth_year = 2007; + +static int do_show_format = 0; +static int do_show_packets = 0; +static int do_show_streams = 0; + +static int show_value_unit = 0; +static int use_value_prefix = 0; +static int use_byte_value_binary_prefix = 0; +static int use_value_sexagesimal_format = 0; + +/* globals */ +static const OptionDef options[]; + +/* AVprobe context */ +static const char *input_filename; +static AVInputFormat *iformat = NULL; + +static const char *binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" }; +static const char *decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" }; + +static const char *unit_second_str = "s" ; +static const char *unit_hertz_str = "Hz" ; +static const char *unit_byte_str = "byte" ; +static const char *unit_bit_per_second_str = "bit/s"; + +static char *value_string(char *buf, int buf_size, double val, const char *unit) +{ + if (unit == unit_second_str && use_value_sexagesimal_format) { + double secs; + int hours, mins; + secs = val; + mins = (int)secs / 60; + secs = secs - mins * 60; + hours = mins / 60; + mins %= 60; + snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs); + } else if (use_value_prefix) { + const char *prefix_string; + int index; + + if (unit == unit_byte_str && use_byte_value_binary_prefix) { + index = (int) (log(val)/log(2)) / 10; + index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) -1); + val /= pow(2, index*10); + prefix_string = binary_unit_prefixes[index]; + } else { + index = (int) (log10(val)) / 3; + index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) -1); + val /= pow(10, index*3); + prefix_string = decimal_unit_prefixes[index]; + } + + snprintf(buf, buf_size, "%.3f %s%s", val, prefix_string, show_value_unit ? unit : ""); + } else { + snprintf(buf, buf_size, "%f %s", val, show_value_unit ? unit : ""); + } + + return buf; +} + +static char *time_value_string(char *buf, int buf_size, int64_t val, const AVRational *time_base) +{ + if (val == AV_NOPTS_VALUE) { + snprintf(buf, buf_size, "N/A"); + } else { + value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str); + } + + return buf; +} + +static char *ts_value_string (char *buf, int buf_size, int64_t ts) +{ + if (ts == AV_NOPTS_VALUE) { + snprintf(buf, buf_size, "N/A"); + } else { + snprintf(buf, buf_size, "%"PRId64, ts); + } + + return buf; +} + +static const char *media_type_string(enum AVMediaType media_type) +{ + switch (media_type) { + case AVMEDIA_TYPE_VIDEO: return "video"; + case AVMEDIA_TYPE_AUDIO: return "audio"; + case AVMEDIA_TYPE_DATA: return "data"; + case AVMEDIA_TYPE_SUBTITLE: return "subtitle"; + case AVMEDIA_TYPE_ATTACHMENT: return "attachment"; + default: return "unknown"; + } +} + +static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt) +{ + char val_str[128]; + AVStream *st = fmt_ctx->streams[pkt->stream_index]; + + printf("[PACKET]\n"); + printf("codec_type=%s\n" , media_type_string(st->codec->codec_type)); + printf("stream_index=%d\n" , pkt->stream_index); + printf("pts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->pts)); + printf("pts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base)); + printf("dts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->dts)); + printf("dts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base)); + printf("duration=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->duration)); + printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base)); + printf("size=%s\n" , value_string (val_str, sizeof(val_str), pkt->size, unit_byte_str)); + printf("pos=%"PRId64"\n" , pkt->pos); + printf("flags=%c\n" , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_'); + printf("[/PACKET]\n"); +} + +static void show_packets(AVFormatContext *fmt_ctx) +{ + AVPacket pkt; + + av_init_packet(&pkt); + + while (!av_read_frame(fmt_ctx, &pkt)) + show_packet(fmt_ctx, &pkt); +} + +static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) +{ + AVStream *stream = fmt_ctx->streams[stream_idx]; + AVCodecContext *dec_ctx; + AVCodec *dec; + char val_str[128]; + AVDictionaryEntry *tag = NULL; + AVRational display_aspect_ratio; + + printf("[STREAM]\n"); + + printf("index=%d\n", stream->index); + + if ((dec_ctx = stream->codec)) { + if ((dec = dec_ctx->codec)) { + printf("codec_name=%s\n", dec->name); + printf("codec_long_name=%s\n", dec->long_name); + } else { + printf("codec_name=unknown\n"); + } + + printf("codec_type=%s\n", media_type_string(dec_ctx->codec_type)); + printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den); + + /* print AVI/FourCC tag */ + av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag); + printf("codec_tag_string=%s\n", val_str); + printf("codec_tag=0x%04x\n", dec_ctx->codec_tag); + + switch (dec_ctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + printf("width=%d\n", dec_ctx->width); + printf("height=%d\n", dec_ctx->height); + printf("has_b_frames=%d\n", dec_ctx->has_b_frames); + if (dec_ctx->sample_aspect_ratio.num) { + printf("sample_aspect_ratio=%d:%d\n", dec_ctx->sample_aspect_ratio.num, + dec_ctx->sample_aspect_ratio.den); + av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, + dec_ctx->width * dec_ctx->sample_aspect_ratio.num, + dec_ctx->height * dec_ctx->sample_aspect_ratio.den, + 1024*1024); + printf("display_aspect_ratio=%d:%d\n", display_aspect_ratio.num, + display_aspect_ratio.den); + } + printf("pix_fmt=%s\n", dec_ctx->pix_fmt != PIX_FMT_NONE ? + av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown"); + printf("level=%d\n", dec_ctx->level); + break; + + case AVMEDIA_TYPE_AUDIO: + printf("sample_rate=%s\n", value_string(val_str, sizeof(val_str), + dec_ctx->sample_rate, + unit_hertz_str)); + printf("channels=%d\n", dec_ctx->channels); + printf("bits_per_sample=%d\n", av_get_bits_per_sample(dec_ctx->codec_id)); + break; + } + } else { + printf("codec_type=unknown\n"); + } + + if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) + printf("id=0x%x\n", stream->id); + printf("r_frame_rate=%d/%d\n", stream->r_frame_rate.num, stream->r_frame_rate.den); + printf("avg_frame_rate=%d/%d\n", stream->avg_frame_rate.num, stream->avg_frame_rate.den); + printf("time_base=%d/%d\n", stream->time_base.num, stream->time_base.den); + printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), stream->start_time, + &stream->time_base)); + printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), stream->duration, + &stream->time_base)); + if (stream->nb_frames) + printf("nb_frames=%"PRId64"\n", stream->nb_frames); + + while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) + printf("TAG:%s=%s\n", tag->key, tag->value); + + printf("[/STREAM]\n"); +} + +static void show_format(AVFormatContext *fmt_ctx) +{ + AVDictionaryEntry *tag = NULL; + char val_str[128]; + + printf("[FORMAT]\n"); + + printf("filename=%s\n", fmt_ctx->filename); + printf("nb_streams=%d\n", fmt_ctx->nb_streams); + printf("format_name=%s\n", fmt_ctx->iformat->name); + printf("format_long_name=%s\n", fmt_ctx->iformat->long_name); + printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, + &AV_TIME_BASE_Q)); + printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration, + &AV_TIME_BASE_Q)); + printf("size=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->file_size, + unit_byte_str)); + printf("bit_rate=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate, + unit_bit_per_second_str)); + + while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) + printf("TAG:%s=%s\n", tag->key, tag->value); + + printf("[/FORMAT]\n"); +} + +static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) +{ + int err, i; + AVFormatContext *fmt_ctx = NULL; + AVDictionaryEntry *t; + + if ((err = avformat_open_input(&fmt_ctx, filename, iformat, &format_opts)) < 0) { + print_error(filename, err); + return err; + } + if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) { + av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key); + return AVERROR_OPTION_NOT_FOUND; + } + + + /* fill the streams in the format context */ + if ((err = av_find_stream_info(fmt_ctx)) < 0) { + print_error(filename, err); + return err; + } + + av_dump_format(fmt_ctx, 0, filename, 0); + + /* bind a decoder to each input stream */ + for (i = 0; i < fmt_ctx->nb_streams; i++) { + AVStream *stream = fmt_ctx->streams[i]; + AVCodec *codec; + + if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) { + fprintf(stderr, "Unsupported codec with id %d for input stream %d\n", + stream->codec->codec_id, stream->index); + } else if (avcodec_open2(stream->codec, codec, NULL) < 0) { + fprintf(stderr, "Error while opening codec for input stream %d\n", + stream->index); + } + } + + *fmt_ctx_ptr = fmt_ctx; + return 0; +} + +static int probe_file(const char *filename) +{ + AVFormatContext *fmt_ctx; + int ret, i; + + if ((ret = open_input_file(&fmt_ctx, filename))) + return ret; + + if (do_show_packets) + show_packets(fmt_ctx); + + if (do_show_streams) + for (i = 0; i < fmt_ctx->nb_streams; i++) + show_stream(fmt_ctx, i); + + if (do_show_format) + show_format(fmt_ctx); + + av_close_input_file(fmt_ctx); + return 0; +} + +static void show_usage(void) +{ + printf("Simple multimedia streams analyzer\n"); + printf("usage: %s [OPTIONS] [INPUT_FILE]\n", program_name); + printf("\n"); +} + +static int opt_format(const char *opt, const char *arg) +{ + iformat = av_find_input_format(arg); + if (!iformat) { + fprintf(stderr, "Unknown input format: %s\n", arg); + return AVERROR(EINVAL); + } + return 0; +} + +static void opt_input_file(const char *arg) +{ + if (input_filename) { + fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n", + arg, input_filename); + exit(1); + } + if (!strcmp(arg, "-")) + arg = "pipe:"; + input_filename = arg; +} + +static void show_help(void) +{ + av_log_set_callback(log_callback_help); + show_usage(); + show_help_options(options, "Main options:\n", 0, 0); + printf("\n"); + av_opt_show2(avformat_opts, NULL, + AV_OPT_FLAG_DECODING_PARAM, 0); +} + +static void opt_pretty(void) +{ + show_value_unit = 1; + use_value_prefix = 1; + use_byte_value_binary_prefix = 1; + use_value_sexagesimal_format = 1; +} + +static const OptionDef options[] = { +#include "cmdutils_common_opts.h" + { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" }, + { "unit", OPT_BOOL, {(void*)&show_value_unit}, "show unit of the displayed values" }, + { "prefix", OPT_BOOL, {(void*)&use_value_prefix}, "use SI prefixes for the displayed values" }, + { "byte_binary_prefix", OPT_BOOL, {(void*)&use_byte_value_binary_prefix}, + "use binary prefixes for byte units" }, + { "sexagesimal", OPT_BOOL, {(void*)&use_value_sexagesimal_format}, + "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" }, + { "pretty", 0, {(void*)&opt_pretty}, + "prettify the format of displayed values, make it more human readable" }, + { "show_format", OPT_BOOL, {(void*)&do_show_format} , "show format/container info" }, + { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" }, + { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" }, + { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, + { NULL, }, +}; + +int main(int argc, char **argv) +{ + int ret; + + av_register_all(); + init_opts(); +#if CONFIG_AVDEVICE + avdevice_register_all(); +#endif + + avformat_opts = avformat_alloc_context(); + + show_banner(); + parse_options(argc, argv, options, opt_input_file); + + if (!input_filename) { + show_usage(); + fprintf(stderr, "You have to specify one input file.\n"); + fprintf(stderr, "Use -h to get full help or, even better, run 'man %s'.\n", program_name); + exit(1); + } + + ret = probe_file(input_filename); + + av_free(avformat_opts); + + return ret; +} diff --git a/configure b/configure index 7277409996..9134bc51a1 100755 --- a/configure +++ b/configure @@ -82,7 +82,7 @@ Configuration options: --disable-doc do not build documentation --disable-ffmpeg disable ffmpeg build --disable-avplay disable avplay build - --disable-ffprobe disable ffprobe build + --disable-avprobe disable avprobe build --disable-ffserver disable ffserver build --disable-avdevice disable libavdevice build --disable-avcodec disable libavcodec build @@ -914,7 +914,7 @@ CONFIG_LIST=" fastdiv ffmpeg avplay - ffprobe + avprobe ffserver fft frei0r @@ -1491,7 +1491,7 @@ ffmpeg_deps="avcodec avformat swscale" ffmpeg_select="buffer_filter" avplay_deps="avcodec avformat swscale sdl" avplay_select="rdft" -ffprobe_deps="avcodec avformat" +avprobe_deps="avcodec avformat" ffserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer" ffserver_extralibs='$ldl' @@ -1636,7 +1636,7 @@ enable doc enable fastdiv enable ffmpeg enable avplay -enable ffprobe +enable avprobe enable ffserver enable network enable optimizations diff --git a/doc/avplay.texi b/doc/avplay.texi index 0c74c59a3d..e8446b75d9 100644 --- a/doc/avplay.texi +++ b/doc/avplay.texi @@ -170,7 +170,7 @@ Seek to percentage in file corresponding to fraction of width. @settitle AVplay media player @c man begin SEEALSO -ffmpeg(1), ffprobe(1), ffserver(1) and the Libav HTML documentation +ffmpeg(1), avprobe(1), ffserver(1) and the Libav HTML documentation @c man end @c man begin AUTHORS diff --git a/doc/avprobe.texi b/doc/avprobe.texi new file mode 100644 index 0000000000..003f5e65c9 --- /dev/null +++ b/doc/avprobe.texi @@ -0,0 +1,134 @@ +\input texinfo @c -*- texinfo -*- + +@settitle avprobe Documentation +@titlepage +@center @titlefont{avprobe Documentation} +@end titlepage + +@top + +@contents + +@chapter Synopsis + +The generic syntax is: + +@example +@c man begin SYNOPSIS +avprobe [options] [@file{input_file}] +@c man end +@end example + +@chapter Description +@c man begin DESCRIPTION + +avprobe gathers information from multimedia streams and prints it in +human- and machine-readable fashion. + +For example it can be used to check the format of the container used +by a multimedia stream and the format and type of each media stream +contained in it. + +If a filename is specified in input, avprobe will try to open and +probe the file content. If the file cannot be opened or recognized as +a multimedia file, a positive exit code is returned. + +avprobe may be employed both as a standalone application or in +combination with a textual filter, which may perform more +sophisticated processing, e.g. statistical processing or plotting. + +Options are used to list some of the formats supported by avprobe or +for specifying which information to display, and for setting how +avprobe will show it. + +avprobe output is designed to be easily parsable by a textual filter, +and consists of one or more sections of the form: +@example +[SECTION] +key1=val1 +... +keyN=valN +[/SECTION] +@end example + +Metadata tags stored in the container or in the streams are recognized +and printed in the corresponding "FORMAT" or "STREAM" section, and +are prefixed by the string "TAG:". + +@c man end + +@chapter Options +@c man begin OPTIONS + +@include fftools-common-opts.texi + +@section Main options + +@table @option + +@item -f @var{format} +Force format to use. + +@item -unit +Show the unit of the displayed values. + +@item -prefix +Use SI prefixes for the displayed values. +Unless the "-byte_binary_prefix" option is used all the prefixes +are decimal. + +@item -byte_binary_prefix +Force the use of binary prefixes for byte values. + +@item -sexagesimal +Use sexagesimal format HH:MM:SS.MICROSECONDS for time values. + +@item -pretty +Prettify the format of the displayed values, it corresponds to the +options "-unit -prefix -byte_binary_prefix -sexagesimal". + +@item -show_format +Show information about the container format of the input multimedia +stream. + +All the container format information is printed within a section with +name "FORMAT". + +@item -show_packets +Show information about each packet contained in the input multimedia +stream. + +The information for each single packet is printed within a dedicated +section with name "PACKET". + +@item -show_streams +Show information about each media stream contained in the input +multimedia stream. + +Each media stream information is printed within a dedicated section +with name "STREAM". + +@end table +@c man end + +@include demuxers.texi +@include muxers.texi +@include protocols.texi +@include indevs.texi + +@ignore + +@setfilename avprobe +@settitle avprobe media prober + +@c man begin SEEALSO +ffmpeg(1), avplay(1), ffserver(1) and the Libav HTML documentation +@c man end + +@c man begin AUTHORS +The Libav developers +@c man end + +@end ignore + +@bye diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 6393516c6d..af9bdcd3f3 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1079,7 +1079,7 @@ file to which you want to add them. @settitle ffmpeg video converter @c man begin SEEALSO -avplay(1), ffprobe(1), ffserver(1) and the Libav HTML documentation +avplay(1), avprobe(1), ffserver(1) and the Libav HTML documentation @c man end @c man begin AUTHORS diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi deleted file mode 100644 index 079cf659d7..0000000000 --- a/doc/ffprobe.texi +++ /dev/null @@ -1,134 +0,0 @@ -\input texinfo @c -*- texinfo -*- - -@settitle ffprobe Documentation -@titlepage -@center @titlefont{ffprobe Documentation} -@end titlepage - -@top - -@contents - -@chapter Synopsis - -The generic syntax is: - -@example -@c man begin SYNOPSIS -ffprobe [options] [@file{input_file}] -@c man end -@end example - -@chapter Description -@c man begin DESCRIPTION - -ffprobe gathers information from multimedia streams and prints it in -human- and machine-readable fashion. - -For example it can be used to check the format of the container used -by a multimedia stream and the format and type of each media stream -contained in it. - -If a filename is specified in input, ffprobe will try to open and -probe the file content. If the file cannot be opened or recognized as -a multimedia file, a positive exit code is returned. - -ffprobe may be employed both as a standalone application or in -combination with a textual filter, which may perform more -sophisticated processing, e.g. statistical processing or plotting. - -Options are used to list some of the formats supported by ffprobe or -for specifying which information to display, and for setting how -ffprobe will show it. - -ffprobe output is designed to be easily parsable by a textual filter, -and consists of one or more sections of the form: -@example -[SECTION] -key1=val1 -... -keyN=valN -[/SECTION] -@end example - -Metadata tags stored in the container or in the streams are recognized -and printed in the corresponding "FORMAT" or "STREAM" section, and -are prefixed by the string "TAG:". - -@c man end - -@chapter Options -@c man begin OPTIONS - -@include fftools-common-opts.texi - -@section Main options - -@table @option - -@item -f @var{format} -Force format to use. - -@item -unit -Show the unit of the displayed values. - -@item -prefix -Use SI prefixes for the displayed values. -Unless the "-byte_binary_prefix" option is used all the prefixes -are decimal. - -@item -byte_binary_prefix -Force the use of binary prefixes for byte values. - -@item -sexagesimal -Use sexagesimal format HH:MM:SS.MICROSECONDS for time values. - -@item -pretty -Prettify the format of the displayed values, it corresponds to the -options "-unit -prefix -byte_binary_prefix -sexagesimal". - -@item -show_format -Show information about the container format of the input multimedia -stream. - -All the container format information is printed within a section with -name "FORMAT". - -@item -show_packets -Show information about each packet contained in the input multimedia -stream. - -The information for each single packet is printed within a dedicated -section with name "PACKET". - -@item -show_streams -Show information about each media stream contained in the input -multimedia stream. - -Each media stream information is printed within a dedicated section -with name "STREAM". - -@end table -@c man end - -@include demuxers.texi -@include muxers.texi -@include protocols.texi -@include indevs.texi - -@ignore - -@setfilename ffprobe -@settitle ffprobe media prober - -@c man begin SEEALSO -ffmpeg(1), avplay(1), ffserver(1) and the Libav HTML documentation -@c man end - -@c man begin AUTHORS -The Libav developers -@c man end - -@end ignore - -@bye diff --git a/doc/ffserver.texi b/doc/ffserver.texi index 3d64b79377..05e52970dc 100644 --- a/doc/ffserver.texi +++ b/doc/ffserver.texi @@ -265,7 +265,7 @@ rather than as a daemon. @c man begin SEEALSO -ffmpeg(1), avplay(1), ffprobe(1), the @file{ffmpeg/doc/ffserver.conf} +ffmpeg(1), avplay(1), avprobe(1), the @file{ffmpeg/doc/ffserver.conf} example and the Libav HTML documentation @c man end diff --git a/ffprobe.c b/ffprobe.c deleted file mode 100644 index 2457b063a5..0000000000 --- a/ffprobe.c +++ /dev/null @@ -1,419 +0,0 @@ -/* - * ffprobe : Simple Media Prober based on the Libav libraries - * Copyright (c) 2007-2010 Stefano Sabatini - * - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config.h" - -#include "libavformat/avformat.h" -#include "libavcodec/avcodec.h" -#include "libavutil/opt.h" -#include "libavutil/pixdesc.h" -#include "libavutil/dict.h" -#include "libavdevice/avdevice.h" -#include "cmdutils.h" - -const char program_name[] = "ffprobe"; -const int program_birth_year = 2007; - -static int do_show_format = 0; -static int do_show_packets = 0; -static int do_show_streams = 0; - -static int show_value_unit = 0; -static int use_value_prefix = 0; -static int use_byte_value_binary_prefix = 0; -static int use_value_sexagesimal_format = 0; - -/* globals */ -static const OptionDef options[]; - -/* FFprobe context */ -static const char *input_filename; -static AVInputFormat *iformat = NULL; - -static const char *binary_unit_prefixes [] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" }; -static const char *decimal_unit_prefixes[] = { "", "K" , "M" , "G" , "T" , "P" }; - -static const char *unit_second_str = "s" ; -static const char *unit_hertz_str = "Hz" ; -static const char *unit_byte_str = "byte" ; -static const char *unit_bit_per_second_str = "bit/s"; - -static char *value_string(char *buf, int buf_size, double val, const char *unit) -{ - if (unit == unit_second_str && use_value_sexagesimal_format) { - double secs; - int hours, mins; - secs = val; - mins = (int)secs / 60; - secs = secs - mins * 60; - hours = mins / 60; - mins %= 60; - snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs); - } else if (use_value_prefix) { - const char *prefix_string; - int index; - - if (unit == unit_byte_str && use_byte_value_binary_prefix) { - index = (int) (log(val)/log(2)) / 10; - index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) -1); - val /= pow(2, index*10); - prefix_string = binary_unit_prefixes[index]; - } else { - index = (int) (log10(val)) / 3; - index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) -1); - val /= pow(10, index*3); - prefix_string = decimal_unit_prefixes[index]; - } - - snprintf(buf, buf_size, "%.3f %s%s", val, prefix_string, show_value_unit ? unit : ""); - } else { - snprintf(buf, buf_size, "%f %s", val, show_value_unit ? unit : ""); - } - - return buf; -} - -static char *time_value_string(char *buf, int buf_size, int64_t val, const AVRational *time_base) -{ - if (val == AV_NOPTS_VALUE) { - snprintf(buf, buf_size, "N/A"); - } else { - value_string(buf, buf_size, val * av_q2d(*time_base), unit_second_str); - } - - return buf; -} - -static char *ts_value_string (char *buf, int buf_size, int64_t ts) -{ - if (ts == AV_NOPTS_VALUE) { - snprintf(buf, buf_size, "N/A"); - } else { - snprintf(buf, buf_size, "%"PRId64, ts); - } - - return buf; -} - -static const char *media_type_string(enum AVMediaType media_type) -{ - switch (media_type) { - case AVMEDIA_TYPE_VIDEO: return "video"; - case AVMEDIA_TYPE_AUDIO: return "audio"; - case AVMEDIA_TYPE_DATA: return "data"; - case AVMEDIA_TYPE_SUBTITLE: return "subtitle"; - case AVMEDIA_TYPE_ATTACHMENT: return "attachment"; - default: return "unknown"; - } -} - -static void show_packet(AVFormatContext *fmt_ctx, AVPacket *pkt) -{ - char val_str[128]; - AVStream *st = fmt_ctx->streams[pkt->stream_index]; - - printf("[PACKET]\n"); - printf("codec_type=%s\n" , media_type_string(st->codec->codec_type)); - printf("stream_index=%d\n" , pkt->stream_index); - printf("pts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->pts)); - printf("pts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->pts, &st->time_base)); - printf("dts=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->dts)); - printf("dts_time=%s\n" , time_value_string(val_str, sizeof(val_str), pkt->dts, &st->time_base)); - printf("duration=%s\n" , ts_value_string (val_str, sizeof(val_str), pkt->duration)); - printf("duration_time=%s\n", time_value_string(val_str, sizeof(val_str), pkt->duration, &st->time_base)); - printf("size=%s\n" , value_string (val_str, sizeof(val_str), pkt->size, unit_byte_str)); - printf("pos=%"PRId64"\n" , pkt->pos); - printf("flags=%c\n" , pkt->flags & AV_PKT_FLAG_KEY ? 'K' : '_'); - printf("[/PACKET]\n"); -} - -static void show_packets(AVFormatContext *fmt_ctx) -{ - AVPacket pkt; - - av_init_packet(&pkt); - - while (!av_read_frame(fmt_ctx, &pkt)) - show_packet(fmt_ctx, &pkt); -} - -static void show_stream(AVFormatContext *fmt_ctx, int stream_idx) -{ - AVStream *stream = fmt_ctx->streams[stream_idx]; - AVCodecContext *dec_ctx; - AVCodec *dec; - char val_str[128]; - AVDictionaryEntry *tag = NULL; - AVRational display_aspect_ratio; - - printf("[STREAM]\n"); - - printf("index=%d\n", stream->index); - - if ((dec_ctx = stream->codec)) { - if ((dec = dec_ctx->codec)) { - printf("codec_name=%s\n", dec->name); - printf("codec_long_name=%s\n", dec->long_name); - } else { - printf("codec_name=unknown\n"); - } - - printf("codec_type=%s\n", media_type_string(dec_ctx->codec_type)); - printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den); - - /* print AVI/FourCC tag */ - av_get_codec_tag_string(val_str, sizeof(val_str), dec_ctx->codec_tag); - printf("codec_tag_string=%s\n", val_str); - printf("codec_tag=0x%04x\n", dec_ctx->codec_tag); - - switch (dec_ctx->codec_type) { - case AVMEDIA_TYPE_VIDEO: - printf("width=%d\n", dec_ctx->width); - printf("height=%d\n", dec_ctx->height); - printf("has_b_frames=%d\n", dec_ctx->has_b_frames); - if (dec_ctx->sample_aspect_ratio.num) { - printf("sample_aspect_ratio=%d:%d\n", dec_ctx->sample_aspect_ratio.num, - dec_ctx->sample_aspect_ratio.den); - av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, - dec_ctx->width * dec_ctx->sample_aspect_ratio.num, - dec_ctx->height * dec_ctx->sample_aspect_ratio.den, - 1024*1024); - printf("display_aspect_ratio=%d:%d\n", display_aspect_ratio.num, - display_aspect_ratio.den); - } - printf("pix_fmt=%s\n", dec_ctx->pix_fmt != PIX_FMT_NONE ? - av_pix_fmt_descriptors[dec_ctx->pix_fmt].name : "unknown"); - printf("level=%d\n", dec_ctx->level); - break; - - case AVMEDIA_TYPE_AUDIO: - printf("sample_rate=%s\n", value_string(val_str, sizeof(val_str), - dec_ctx->sample_rate, - unit_hertz_str)); - printf("channels=%d\n", dec_ctx->channels); - printf("bits_per_sample=%d\n", av_get_bits_per_sample(dec_ctx->codec_id)); - break; - } - } else { - printf("codec_type=unknown\n"); - } - - if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS) - printf("id=0x%x\n", stream->id); - printf("r_frame_rate=%d/%d\n", stream->r_frame_rate.num, stream->r_frame_rate.den); - printf("avg_frame_rate=%d/%d\n", stream->avg_frame_rate.num, stream->avg_frame_rate.den); - printf("time_base=%d/%d\n", stream->time_base.num, stream->time_base.den); - printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), stream->start_time, - &stream->time_base)); - printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), stream->duration, - &stream->time_base)); - if (stream->nb_frames) - printf("nb_frames=%"PRId64"\n", stream->nb_frames); - - while ((tag = av_dict_get(stream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) - printf("TAG:%s=%s\n", tag->key, tag->value); - - printf("[/STREAM]\n"); -} - -static void show_format(AVFormatContext *fmt_ctx) -{ - AVDictionaryEntry *tag = NULL; - char val_str[128]; - - printf("[FORMAT]\n"); - - printf("filename=%s\n", fmt_ctx->filename); - printf("nb_streams=%d\n", fmt_ctx->nb_streams); - printf("format_name=%s\n", fmt_ctx->iformat->name); - printf("format_long_name=%s\n", fmt_ctx->iformat->long_name); - printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->start_time, - &AV_TIME_BASE_Q)); - printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration, - &AV_TIME_BASE_Q)); - printf("size=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->file_size, - unit_byte_str)); - printf("bit_rate=%s\n", value_string(val_str, sizeof(val_str), fmt_ctx->bit_rate, - unit_bit_per_second_str)); - - while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) - printf("TAG:%s=%s\n", tag->key, tag->value); - - printf("[/FORMAT]\n"); -} - -static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) -{ - int err, i; - AVFormatContext *fmt_ctx = NULL; - AVDictionaryEntry *t; - - if ((err = avformat_open_input(&fmt_ctx, filename, iformat, &format_opts)) < 0) { - print_error(filename, err); - return err; - } - if ((t = av_dict_get(format_opts, "", NULL, AV_DICT_IGNORE_SUFFIX))) { - av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key); - return AVERROR_OPTION_NOT_FOUND; - } - - - /* fill the streams in the format context */ - if ((err = av_find_stream_info(fmt_ctx)) < 0) { - print_error(filename, err); - return err; - } - - av_dump_format(fmt_ctx, 0, filename, 0); - - /* bind a decoder to each input stream */ - for (i = 0; i < fmt_ctx->nb_streams; i++) { - AVStream *stream = fmt_ctx->streams[i]; - AVCodec *codec; - - if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) { - fprintf(stderr, "Unsupported codec with id %d for input stream %d\n", - stream->codec->codec_id, stream->index); - } else if (avcodec_open2(stream->codec, codec, NULL) < 0) { - fprintf(stderr, "Error while opening codec for input stream %d\n", - stream->index); - } - } - - *fmt_ctx_ptr = fmt_ctx; - return 0; -} - -static int probe_file(const char *filename) -{ - AVFormatContext *fmt_ctx; - int ret, i; - - if ((ret = open_input_file(&fmt_ctx, filename))) - return ret; - - if (do_show_packets) - show_packets(fmt_ctx); - - if (do_show_streams) - for (i = 0; i < fmt_ctx->nb_streams; i++) - show_stream(fmt_ctx, i); - - if (do_show_format) - show_format(fmt_ctx); - - av_close_input_file(fmt_ctx); - return 0; -} - -static void show_usage(void) -{ - printf("Simple multimedia streams analyzer\n"); - printf("usage: ffprobe [OPTIONS] [INPUT_FILE]\n"); - printf("\n"); -} - -static int opt_format(const char *opt, const char *arg) -{ - iformat = av_find_input_format(arg); - if (!iformat) { - fprintf(stderr, "Unknown input format: %s\n", arg); - return AVERROR(EINVAL); - } - return 0; -} - -static void opt_input_file(const char *arg) -{ - if (input_filename) { - fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n", - arg, input_filename); - exit(1); - } - if (!strcmp(arg, "-")) - arg = "pipe:"; - input_filename = arg; -} - -static void show_help(void) -{ - av_log_set_callback(log_callback_help); - show_usage(); - show_help_options(options, "Main options:\n", 0, 0); - printf("\n"); - av_opt_show2(avformat_opts, NULL, - AV_OPT_FLAG_DECODING_PARAM, 0); -} - -static void opt_pretty(void) -{ - show_value_unit = 1; - use_value_prefix = 1; - use_byte_value_binary_prefix = 1; - use_value_sexagesimal_format = 1; -} - -static const OptionDef options[] = { -#include "cmdutils_common_opts.h" - { "f", HAS_ARG, {(void*)opt_format}, "force format", "format" }, - { "unit", OPT_BOOL, {(void*)&show_value_unit}, "show unit of the displayed values" }, - { "prefix", OPT_BOOL, {(void*)&use_value_prefix}, "use SI prefixes for the displayed values" }, - { "byte_binary_prefix", OPT_BOOL, {(void*)&use_byte_value_binary_prefix}, - "use binary prefixes for byte units" }, - { "sexagesimal", OPT_BOOL, {(void*)&use_value_sexagesimal_format}, - "use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units" }, - { "pretty", 0, {(void*)&opt_pretty}, - "prettify the format of displayed values, make it more human readable" }, - { "show_format", OPT_BOOL, {(void*)&do_show_format} , "show format/container info" }, - { "show_packets", OPT_BOOL, {(void*)&do_show_packets}, "show packets info" }, - { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" }, - { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, - { NULL, }, -}; - -int main(int argc, char **argv) -{ - int ret; - - av_register_all(); - init_opts(); -#if CONFIG_AVDEVICE - avdevice_register_all(); -#endif - - avformat_opts = avformat_alloc_context(); - - show_banner(); - parse_options(argc, argv, options, opt_input_file); - - if (!input_filename) { - show_usage(); - fprintf(stderr, "You have to specify one input file.\n"); - fprintf(stderr, "Use -h to get full help or, even better, run 'man ffprobe'.\n"); - exit(1); - } - - ret = probe_file(input_filename); - - av_free(avformat_opts); - - return ret; -} -- cgit v1.2.3