No subject
bogus at does.not.exist.com
bogus at does.not.exist.com
Tue Aug 25 22:50:44 CEST 2009
| The `%f' conversion prints its argument in fixed-point notation,
|producing output of the form [`-']DDD`.'DDD, where the number of digits
|following the decimal point is controlled by the precision you specify.
And I couldn't find a way to force printf to pad to 2 digits the
decimal part, also it looks more complicate (I need to compute secs,
and then re-add the microseconds like secs = secs + usecs / 1000000,
maybe there is a simpler way though).
> > + return buf;
> > + }
> > +
> > + if (flags & VALUE_STRING_USE_PREFIX) {
> > + if (flags & VALUE_STRING_USE_BINARY_PREFIX) {
> > + index = (int) (log2(val)) / 10;
> > + index = FFMAX(0, index);
> > + index = FFMIN(index, binary_unit_prefixes_nb -1);
>
> av_clip()
Used.
>
>
> > + val /= pow(2, index*10);
> > + prefix_str = binary_unit_prefixes[index];
> > + } else {
> > + index = (int) (log10(val)) / 3;
> > + index = FFMAX(0, index);
> > + index = FFMIN(index, decimal_unit_prefixes_nb -1);
> > + val /= pow(10, index*3);
> > + prefix_str = decimal_unit_prefixes[index];
> > + }
> > + } else
> > + prefix_str = "";
> > +
> > + unit_str = flags & VALUE_STRING_USE_UNIT ? measure_units[unit].str : "";
> > +
>
> > + if (flags & VALUE_STRING_USE_PREFIX)
> > + snprintf(buf, buf_size, "%.3f %s%s", val, prefix_str, unit_str);
> > + else
>
> {}
Done.
> > + snprintf(buf, buf_size, "%f %s", val, unit_str);
> > +
> > + return buf;
> > +}
> > +
> > +static char *time_value_string(char *buf, int buf_size, int64_t val,
> > + AVRational *time_base, int value_string_flags)
> > +{
> > + double d;
> > +
> > + if (val == AV_NOPTS_VALUE) {
> > + snprintf(buf, buf_size, "N/A");
> > + } else {
> > + d = (double) (val * time_base->num) / (double) time_base->den;
>
> av_q2d()
Yes.
> [...]
> > +#define P(...) do { printf(__VA_ARGS__); } while(0)
>
> obfuscated mess
> next comes
> #define I if(
> #define SV static void
> and so on
Removed the macro.
Also addressed Diego's remarks.
Regards.
--
FFmpeg = Fast & Free Miracolous Philosofic Energized Guru
--wac7ysb48OaltWcw
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="add-ffprobe.patch"
Index: ffmpeg/Makefile
===================================================================
--- ffmpeg.orig/Makefile 2010-01-03 15:10:48.000000000 +0100
+++ ffmpeg/Makefile 2010-01-03 17:20:51.000000000 +0100
@@ -6,6 +6,7 @@
PROGS-$(CONFIG_FFMPEG) += ffmpeg
PROGS-$(CONFIG_FFPLAY) += ffplay
+PROGS-$(CONFIG_FFPROBE) += ffprobe
PROGS-$(CONFIG_FFSERVER) += ffserver
PROGS := $(addsuffix $(EXESUF), $(PROGS-yes))
@@ -15,7 +16,7 @@
TOOLS = $(addprefix tools/, $(addsuffix $(EXESUF), cws2fws pktdumper probetest qt-faststart trasher))
HOSTPROGS = $(addprefix tests/, audiogen videogen rotozoom tiny_psnr)
-BASENAMES = ffmpeg ffplay ffserver
+BASENAMES = ffmpeg ffplay ffprobe ffserver
ALLPROGS = $(addsuffix $(EXESUF), $(BASENAMES))
ALLPROGS_G = $(addsuffix _g$(EXESUF), $(BASENAMES))
ALLMANPAGES = $(addsuffix .1, $(BASENAMES))
@@ -83,7 +84,7 @@
alltools: $(TOOLS)
documentation: $(addprefix doc/, developer.html faq.html ffmpeg-doc.html \
- ffplay-doc.html ffserver-doc.html \
+ ffplay-doc.html ffprobe-doc.html ffserver-doc.html \
general.html libavfilter.html $(ALLMANPAGES))
doc/%.html: doc/%.texi
Index: ffmpeg/configure
===================================================================
--- ffmpeg.orig/configure 2010-01-03 15:10:48.000000000 +0100
+++ ffmpeg/configure 2010-01-03 17:20:51.000000000 +0100
@@ -82,6 +82,7 @@
--disable-doc do not build documentation
--disable-ffmpeg disable ffmpeg build
--disable-ffplay disable ffplay build
+ --disable-ffprobe disable ffprobe build
--disable-ffserver disable ffserver build
--enable-postproc enable GPLed postprocessing support [no]
--enable-avfilter video filter support [no]
@@ -830,6 +831,7 @@
fastdiv
ffmpeg
ffplay
+ ffprobe
ffserver
fft
golomb
@@ -1327,6 +1329,7 @@
enable fastdiv
enable ffmpeg
enable ffplay
+enable ffprobe
enable ffserver
enable ipv6
enable mpegaudio_hp
Index: ffmpeg/ffprobe.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ffmpeg/ffprobe.c 2010-01-03 17:44:07.000000000 +0100
@@ -0,0 +1,362 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#undef HAVE_AV_CONFIG_H
+#include "libavformat/avformat.h"
+#include "cmdutils.h"
+
+const char program_name[] = "FFprobe";
+const int program_birth_year = 2007;
+
+/* globals */
+const OptionDef options[];
+
+/* FFprobe context */
+static const char *input_filename;
+static int value_string_flags = 0;
+static int do_show_format = 0;
+static int do_show_streams = 0;
+
+const char *binary_unit_prefixes[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi" };
+static const int binary_unit_prefixes_nb = FF_ARRAY_ELEMS(binary_unit_prefixes);
+
+const char *decimal_unit_prefixes[] = { "", "K", "M", "G", "T", "P" };
+static const int decimal_unit_prefixes_nb = FF_ARRAY_ELEMS(decimal_unit_prefixes);
+
+typedef enum UnitPrefixType {
+ UNIT_PREFIX_TYPE_BINARY,
+ UNIT_PREFIX_TYPE_DECIMAL
+} UnitPrefixType;
+
+typedef enum UnitId {
+ UNIT_NONE,
+ UNIT_SECOND,
+ UNIT_HERTZ,
+ UNIT_BYTE_PER_SECOND,
+ UNIT_BIT_PER_SECOND,
+ UNIT_BIT,
+ UNIT_BYTE,
+ UNIT_NB,
+} UnitId;
+
+typedef struct Unit {
+ const UnitId id;
+ const char *str;
+} Unit;
+
+const Unit measure_units[UNIT_NB] = {
+ [UNIT_NONE] = { UNIT_NONE , "" },
+ [UNIT_SECOND] = { UNIT_SECOND , "s" },
+ [UNIT_HERTZ] = { UNIT_HERTZ , "Hz" },
+ [UNIT_BIT] = { UNIT_BIT , "bit" },
+ [UNIT_BYTE] = { UNIT_BYTE , "byte" },
+ [UNIT_BYTE_PER_SECOND] = { UNIT_BYTE_PER_SECOND, "byte/s" },
+ [UNIT_BIT_PER_SECOND] = { UNIT_BIT_PER_SECOND , "bit/s" }
+};
+
+/** Print unit of measure. */
+#define VALUE_STRING_USE_UNIT 0x0001
+
+/** Print using (binary or decimal) prefixes. */
+#define VALUE_STRING_USE_PREFIX 0x0002
+/** Use binary type prefixes, implies the use of prefixes */
+#define VALUE_STRING_USE_BINARY_PREFIX 0x0004
+
+/** Force the use of binary prefixes with bytes measure units. */
+#define VALUE_STRING_USE_BYTE_BINARY_PREFIX 0x0008
+
+/* Use sexagesimal time format HH:MM:SS.MICROSECONDS. */
+#define VALUE_STRING_USE_SEXAGESIMAL_TIME_FORMAT 0x0010
+
+static char *value_string(char *buf, int buf_size, double val,
+ UnitId unit, int flags)
+{
+ int index;
+ const char *prefix_str;
+ const char *unit_str;
+
+ if (unit == UNIT_BYTE && flags & VALUE_STRING_USE_BYTE_BINARY_PREFIX)
+ flags |= VALUE_STRING_USE_BINARY_PREFIX;
+
+ if (unit == UNIT_SECOND && flags & VALUE_STRING_USE_SEXAGESIMAL_TIME_FORMAT) {
+ int hours, mins, secs, usecs;
+ /* takes the 6 digits representing the microseconds and round */
+ usecs = (int)(round((val - floor(val)) * 1000000));
+ secs = (int)val;
+ mins = secs / 60;
+ secs %= 60;
+ hours = mins / 60;
+ mins %= 60;
+
+ snprintf(buf, buf_size, "%d:%02d:%02d.%06d", hours, mins, secs, usecs);
+ return buf;
+ }
+
+ if (flags & VALUE_STRING_USE_PREFIX) {
+ if (flags & VALUE_STRING_USE_BINARY_PREFIX) {
+ index = (int) (log2(val)) / 10;
+ index = av_clip(index, 0, binary_unit_prefixes_nb -1);
+ val /= pow(2, index*10);
+ prefix_str = binary_unit_prefixes[index];
+ } else {
+ index = (int) (log10(val)) / 3;
+ index = av_clip(index, 0, decimal_unit_prefixes_nb -1);
+ index = FFMIN(index, decimal_unit_prefixes_nb -1);
+ val /= pow(10, index*3);
+ prefix_str = decimal_unit_prefixes[index];
+ }
+ } else {
+ prefix_str = "";
+ }
+
+ unit_str = flags & VALUE_STRING_USE_UNIT ? measure_units[unit].str : "";
+
+ if (flags & VALUE_STRING_USE_PREFIX)
+ snprintf(buf, buf_size, "%.3f %s%s", val, prefix_str, unit_str);
+ else
+ snprintf(buf, buf_size, "%f %s", val, unit_str);
+
+ return buf;
+}
+
+static char *time_value_string(char *buf, int buf_size, int64_t val,
+ AVRational *time_base, int value_string_flags)
+{
+ double d;
+
+ if (val == AV_NOPTS_VALUE) {
+ snprintf(buf, buf_size, "N/A");
+ } else {
+ d = val * av_q2d(*time_base);
+ value_string(buf, buf_size, d, UNIT_SECOND, value_string_flags);
+ }
+
+ return buf;
+}
+
+static const char *codec_type_string(enum CodecType codec_type)
+{
+ switch (codec_type) {
+ case CODEC_TYPE_VIDEO: return "video";
+ case CODEC_TYPE_AUDIO: return "audio";
+ case CODEC_TYPE_DATA: return "data";
+ case CODEC_TYPE_SUBTITLE: return "subtitle";
+ case CODEC_TYPE_ATTACHMENT: return "attachment";
+ default: return "unknown";
+ }
+}
+
+static void show_stream(AVFormatContext *fmt_ctx, int stream_idx)
+{
+ AVStream *stream = fmt_ctx->streams[stream_idx];
+ AVCodecContext *dec_ctx = stream->codec;
+ AVCodec *dec = stream->codec->codec;
+ char val_str[128];
+ AVMetadataTag *tag;
+
+ printf("[STREAM]\n");
+
+ printf("index=%d\n", stream->index);
+ if (dec) {
+ printf("codec_name=%s\n", dec->name);
+ printf("codec_long_name=%s\n", dec->long_name);
+ printf("codec_time_base=%d/%d\n", dec_ctx->time_base.num, dec_ctx->time_base.den);
+ printf("codec_type=%s\n", codec_type_string(dec_ctx->codec_type));
+
+ if (fmt_ctx->iformat->flags & AVFMT_SHOW_IDS)
+ printf("id=0x%x\n", stream->id);
+
+ switch (dec_ctx->codec_type) {
+ case CODEC_TYPE_VIDEO:
+ printf("r_frame_rate=%d/%d\n", stream->r_frame_rate.num, stream->r_frame_rate.den);
+ 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);
+ printf("sample_aspect_ratio=%d/%d\n", dec_ctx->sample_aspect_ratio.num,
+ dec_ctx->sample_aspect_ratio.den);
+ printf("display_aspect_ratio=%d/%d\n", dec_ctx->sample_aspect_ratio.num,
+ dec_ctx->sample_aspect_ratio.den);
+ printf("pix_fmt=%s\n", avcodec_get_pix_fmt_name(dec_ctx->pix_fmt));
+ break;
+
+ case CODEC_TYPE_AUDIO:
+ printf("sample_rate=%d\n", dec_ctx->sample_rate);
+ printf("channels=%d\n", dec_ctx->channels);
+ printf("bits_per_sample=%d\n", av_get_bits_per_sample(dec_ctx->codec_id));
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ printf("codec_name=unknown\n");
+ }
+
+ printf("time_base=%d/%d\n", stream->time_base.num, stream->time_base.den);
+ if (stream->language[0])
+ printf("language=%s\n", stream->language);
+ printf("start_time=%s\n", time_value_string(val_str, sizeof(val_str), stream->start_time,
+ &stream->time_base, value_string_flags));
+ printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), stream->duration,
+ &stream->time_base, value_string_flags));
+ printf("nb_frames=%"PRId64"\n", stream->nb_frames);
+
+ while ((tag = av_metadata_get(stream->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
+ printf("%s=%s\n", tag->key, tag->value);
+
+ printf("[/STREAM]\n");
+}
+
+static void show_format(AVFormatContext *fmt_ctx)
+{
+ AVMetadataTag *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, value_string_flags));
+ printf("duration=%s\n", time_value_string(val_str, sizeof(val_str), fmt_ctx->duration,
+ &AV_TIME_BASE_Q, value_string_flags));
+ printf("size=%s\n", value_string(val_str, sizeof(val_str), (double)fmt_ctx->file_size,
+ UNIT_BYTE, value_string_flags));
+ printf("bit_rate=%s\n", value_string(val_str, sizeof(val_str), (double)fmt_ctx->bit_rate,
+ UNIT_BIT_PER_SECOND, value_string_flags));
+
+ while ((tag = av_metadata_get(fmt_ctx->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))
+ printf("%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;
+
+ fmt_ctx = avformat_alloc_context();
+
+ if ((err = av_open_input_file(&fmt_ctx, filename, NULL, 0, NULL)) < 0) {
+ print_error(filename, err);
+ return err;
+ }
+
+ /* fill the streams in the format context */
+ if ((err = av_find_stream_info(fmt_ctx)) < 0) {
+ print_error(filename, err);
+ return err;
+ }
+
+ /* dump info */
+ 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 (id=%d) for input stream %d\n",
+ stream->codec->codec_id, stream->index);
+ } else if (avcodec_open(stream->codec, codec) < 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_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 void show_help(void)
+{
+ show_usage();
+ show_help_options(options, "Main options:\n", 0, 0);
+}
+
+static void opt_pretty(void)
+{
+ value_string_flags =
+ VALUE_STRING_USE_UNIT |
+ VALUE_STRING_USE_PREFIX |
+ VALUE_STRING_USE_SEXAGESIMAL_TIME_FORMAT |
+ VALUE_STRING_USE_BYTE_BINARY_PREFIX;
+}
+
+const OptionDef options[] = {
+#include "cmdutils_common_opts.h"
+ { "pretty", 0, {(void*)opt_pretty}, "pretty-print numerical values, more human readable" },
+ { "show_format", OPT_BOOL, {(void*)&do_show_format}, "show stream format info" },
+ { "show_streams", OPT_BOOL, {(void*)&do_show_streams}, "show streams info" },
+ { NULL, },
+};
+
+static void opt_input_file(const char *filename)
+{
+ if (!strcmp(filename, "-"))
+ filename = "pipe:";
+ input_filename = filename;
+}
+
+int main(int argc, char **argv)
+{
+ av_register_all();
+
+ 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);
+ }
+
+ return probe_file(input_filename);
+}
Index: ffmpeg/doc/ffprobe-doc.texi
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ ffmpeg/doc/ffprobe-doc.texi 2010-01-03 17:20:51.000000000 +0100
@@ -0,0 +1,73 @@
+\input texinfo @c -*- texinfo -*-
+
+ at settitle FFprobe Documentation
+ at titlepage
+ at sp 7
+ at center @titlefont{FFprobe Documentation}
+ at sp 3
+ at end titlepage
+
+ at chapter Introduction
+ at 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.
+
+FFprobe output is designed to be easily parsable by a textual filter,
+and consists of one or more stanzas of the form:
+ at example
+[TAG]
+key1=val1
+...
+keyN=valN
+[/TAG]
+ at end example
+
+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.
+ at c man end
+
+ at chapter Invocation
+
+ at section Syntax
+ at example
+ at c man begin SYNOPSIS
+ffprobe [options] [@file{input_file}]
+ at c man end
+ at end example
+
+ at c man begin OPTIONS
+ at section Main options
+
+ at table @option
+ at include fftools-common-opts.texi
+ at item -pretty
+Prettify printed values, show used measure units and prefixes to ease
+readability for human readers.
+ at item -show_format
+Show information about the container format of the input multimedia
+stream.
+ at item -show_streams
+Show information about each media stream contained in the input
+multimedia stream.
+
+ at end table
+ at c man end
+
+ at ignore
+
+ at setfilename ffprobe
+ at settitle FFmpeg based simple media prober
+
+ at c man begin SEEALSO
+ffmpeg(1), ffplay(1), ffserver(1)
+ at c man end
+
+ at end ignore
+
+ at bye
--wac7ysb48OaltWcw--
More information about the ffmpeg-devel
mailing list