[FFmpeg-devel] [PATCH] ffprobe: add compact and compactnk writers
Stefano Sabatini
stefasab at gmail.com
Sun Sep 25 13:41:53 CEST 2011
On date Sunday 2011-09-25 02:43:49 +0200, Clément Bœsch encoded:
> On Sun, Sep 25, 2011 at 02:09:24AM +0200, Stefano Sabatini wrote:
> > From: Stefano Sabatini <stefano.sabatini-lala at poste.it>
> >
> > ---
> > doc/ffprobe.texi | 17 +++++++++++++++++
> > ffprobe.c | 39 ++++++++++++++++++++++++++++++++++++++-
> > 2 files changed, 55 insertions(+), 1 deletions(-)
> >
> > diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
> > index e9b26ac..a41ce1d 100644
> > --- a/doc/ffprobe.texi
> > +++ b/doc/ffprobe.texi
> > @@ -93,6 +93,23 @@ Current available formats are:
> >
> > @table @option
> >
> > + at item compact
> > +Compact format.
> > +
> > +Each section is printed on a single line, and has the form:
> > + at example
> > +[SECTION] key1=val1 ... keyN=valN [/SECTION]
> > + at end example
> > +
> > + at item compactnk
> > +Compact format with no key printing.
> > +
> > +Like the @option{compact} format, but no key is printed.
> > +Each section is printed on a single line, and has the form:
> > + at example
> > +[SECTION] val1 ... valN [/SECTION]
> > + at end example
> > +
> > @item default
> > It is default format.
> >
>
> Maybe keep the default on top?
Fixed.
> > diff --git a/ffprobe.c b/ffprobe.c
> > index d12c98c..b975cf8 100644
> > --- a/ffprobe.c
> > +++ b/ffprobe.c
> > @@ -238,6 +238,25 @@ static void default_print_footer(const char *section)
> > printf("\n[/%s]", section);
> > }
> >
> > +static void compact_print_header(const char *section)
> > +{
> > + printf("[%s] ", section);
> > +}
> > +
> > +static void compact_print_footer(const char *section)
> > +{
> > + printf(" [/%s]\n", section);
> > +}
> > +
>
> I wonder if keeping this nesting really is important. We might be limited
> in width, so better keep it really compact. What about something like:
>
> SECTION: k=v ...
> SECTION: k=v ...
> ...
Good idea.
>
> > +static void compactnk_print_int(const char *key, int value)
> > +{
> > + printf("%d", value);
> > +}
> > +
> > +static void compactnk_print_str(const char *key, const char *value)
> > +{
> > + printf("%s", value);
> > +}
> >
>
> Maybe some quoting would be worth here? It's sometimes hard to tell what
> are the limit of a key. Another solution might be to use some '|'.
>
> Those are just suggestions, I won't push for this.
I added escaping (which may be used e.g. for CSV output), and change
the item separator from " " to "|".
Output looks like this:
[...]
PACKET: audio|1|238080|238.080000|238080|238.080000|26|0.026000|26.000000|9866826|K
PACKET: audio|1|238106|238.106000|238106|238.106000|26|0.026000|26.000000|9866868|K
PACKET: audio|1|238132|238.132000|238132|238.132000|26|0.026000|26.000000|9866910|K
PACKET: audio|1|238158|238.158000|238158|238.158000|26|0.026000|26.000000|9866952|K
STREAM: 0|flv|Flash Video (FLV) / Sorenson Spark / Sorenson H.263|video|1/1000|[0][0][0][0]|0x0000|320|240|0|yuv420p|-99|30000/1001|0/0|1/1000|0.000000|N/A
STREAM: 1|mp3|MP3 (MPEG audio layer 3)|audio|0/1|[0][0][0][0]|0x0000|22050.000000|1|0|0/0|500/13|1/1000|0.000000|N/A
FORMAT: samples/slow.flv|2|flv|FLV format|0.000000|238.158000|9866982.000000|331443.000000
>
> > /* Print helpers */
> >
> > @@ -539,6 +558,24 @@ static struct writer writers[] = {{
> > .print_section_start = json_print_section_start,
> > .print_section_end = json_print_section_end,
> > WRITER_FUNC(json),
> > + },{
> > + .name = "compact",
> > + .item_sep = " ",
> > + .items_sep = "",
> > + .print_header = compact_print_header,
> > + .print_footer = compact_print_footer,
> > + .print_integer = default_print_int,
> > + .print_string = default_print_str,
> > + .show_tags = default_show_tags,
> > + },{
> > + .name = "compactnk",
> > + .item_sep = " ",
> > + .items_sep = "",
> > + .print_header = compact_print_header,
> > + .print_footer = compact_print_footer,
> > + .print_integer = compactnk_print_int,
> > + .print_string = compactnk_print_str,
> > + .show_tags = default_show_tags,
> > }
> > };
> >
> > @@ -656,7 +693,7 @@ static const OptionDef options[] = {
> > "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" },
> > - { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, "set the output printing format (available formats are: default, json)", "format" },
> > + { "print_format", OPT_STRING | HAS_ARG, {(void*)&print_format}, "set the output printing format (available formats are: default, json, compact, compactnk)", "format" },
>
> nit: let's keep the same order as the documentation: default, compact,
> compactnk, json. (default + alphabetical order).
Fixed.
Updated.
--
FFmpeg = Forgiving & Fiendish Meaningless Philosofic Eager Gadget
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-ffprobe-add-compact-and-compactnk-writers.patch
Type: text/x-diff
Size: 4638 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110925/810ccd28/attachment.bin>
More information about the ffmpeg-devel
mailing list