[FFmpeg-devel] [PATCH] ffprobe: add flat output format.
Stefano Sabatini
stefasab at gmail.com
Sat May 26 20:52:21 CEST 2012
On date Saturday 2012-05-26 01:14:50 +0200, Clément Bœsch encoded:
> ---
> doc/ffprobe.texi | 6 ++++
> ffprobe.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 86 insertions(+), 1 deletion(-)
>
> diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
> index ed96575..2cab961 100644
> --- a/doc/ffprobe.texi
> +++ b/doc/ffprobe.texi
> @@ -269,6 +269,12 @@ CSV format.
> This writer is equivalent to
> @code{compact=item_sep=,:nokey=1:escape=csv}.
>
> + at section flat
> +Flat format.
> +
> +A free-form output with each line contains an explicit key=value, such as
> +"stream.3.tag.25=foobar"
> +
> @section json
> JSON based format.
>
> diff --git a/ffprobe.c b/ffprobe.c
> index d53ec11..43770cb 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -710,6 +710,84 @@ static const Writer csv_writer = {
> .flags = WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS,
> };
>
> +/* Flat output */
> +
> +typedef struct FlatContext {
> + const AVClass *class;
> + const char *section;
> + int section_entry_id;
> +} FlatContext;
> +
> +#undef OFFSET
> +#define OFFSET(x) offsetof(FlatContext, x)
> +
> +static const char *flat_get_name(void *ctx)
> +{
> + return "flat";
> +}
> +
> +static const AVClass flat_class = {
> + "FlatContext",
> + flat_get_name,
> +};
> +
> +static void flat_print_section(const FlatContext *flat)
> +{
> + printf("%s.", flat->section);
> + if (!strcmp(flat->section, "format") || !strcmp(flat->section, "error"))
> + return;
> + printf("%d.", flat->section_entry_id);
> +}
> +
> +static void flat_print_section_header(WriterContext *wctx, const char *section)
> +{
> + FlatContext *flat = wctx->priv;
> + if (flat->section && strcmp(flat->section, section) == 0) {
> + flat->section_entry_id++;
> + } else {
> + flat->section = section;
> + flat->section_entry_id = 0;
> + }
> +}
> +
> +static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
> +{
> + FlatContext *flat = wctx->priv;
> +
> + flat_print_section(flat);
> + printf("%s=%s\n", key, value);
I think we should add support to escaping here (which we could use for
the default writer as well). init-like escaping should be fine. Leave
it for another patch if you don't care.
> +}
> +
> +static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
> +{
> + FlatContext *flat = wctx->priv;
> +
> + flat_print_section(flat);
> + printf("%s=%lld\n", key, value);
> +}
> +
> +static void flat_show_tags(WriterContext *wctx, AVDictionary *dict)
> +{
> + int id = 0;
> + FlatContext *flat = wctx->priv;
> + AVDictionaryEntry *tag = NULL;
> +
> + while ((tag = av_dict_get(dict, "", tag, AV_DICT_IGNORE_SUFFIX))) {
> + flat_print_section(flat);
> + printf("tag.%d=%s\n", id++, tag->value);
Same here, may need escaping.
Also what about something like:
stream.STREAM_ID.tag.KEY=foobar
KEY seems more useful than a number (also: we may add a format option
for that).
[...]
Looks good otherwise, thanks.
--
FFmpeg = Free and Fascinating Marvellous Peaceful Everlasting Gangster
More information about the ffmpeg-devel
mailing list