[FFmpeg-cvslog] ffprobe: parse arguments for -print_format writer
Stefano Sabatini
git at videolan.org
Sun Oct 9 16:12:46 CEST 2011
ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sun Oct 2 11:26:07 2011 +0200| [cb50ada4f87bc6f735b76f798fddc8d3e6045497] | committer: Stefano Sabatini
ffprobe: parse arguments for -print_format writer
This allows -print_format to accept string of the form WRITER=OPTIONS,
as required by the pending compact writer patch.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cb50ada4f87bc6f735b76f798fddc8d3e6045497
---
doc/ffprobe.texi | 5 ++++-
ffprobe.c | 36 ++++++++++++++++++++++++++----------
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index 597b6b5..9496fc9 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -80,9 +80,12 @@ Use sexagesimal format HH:MM:SS.MICROSECONDS for time values.
Prettify the format of the displayed values, it corresponds to the
options "-unit -prefix -byte_binary_prefix -sexagesimal".
- at item -print_format @var{format}
+ at item -print_format @var{writer_name}[=@var{writer_options}]
Set the output printing format.
+ at var{writer_name} specifies the name of the writer, and
+ at var{writer_options} specifies the options to be passed to the writer.
+
For example for printing the output in JSON format, specify:
@example
-print_format json
diff --git a/ffprobe.c b/ffprobe.c
index d2ef86f..82a8f54 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -23,6 +23,7 @@
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
+#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/dict.h"
@@ -737,23 +738,34 @@ static int probe_file(const char *filename)
AVFormatContext *fmt_ctx;
int ret;
Writer *w;
+ const char *buf = print_format;
+ char *w_str = NULL, *w_args = NULL;
WriterContext *wctx;
writer_register_all();
- if (!print_format)
- print_format = av_strdup("default");
- w = writer_get_by_name(print_format);
- if (!w) {
- fprintf(stderr, "Invalid output format '%s'\n", print_format);
- return AVERROR(EINVAL);
+ if (buf) {
+ w_str = av_get_token(&buf, "=");
+ if (*buf == '=') {
+ buf++;
+ w_args = av_get_token(&buf, "");
+ }
}
- if ((ret = writer_open(&wctx, w, NULL, NULL)) < 0)
- return ret;
+ if (!w_str)
+ w_str = av_strdup("default");
+ w = writer_get_by_name(w_str);
+ if (!w) {
+ av_log(NULL, AV_LOG_ERROR, "Invalid output format '%s'\n", w_str);
+ ret = AVERROR(EINVAL);
+ goto end;
+ }
+
+ if ((ret = writer_open(&wctx, w, w_args, NULL)) < 0)
+ goto end;
if ((ret = open_input_file(&fmt_ctx, filename)))
- return ret;
+ goto end;
writer_print_header(wctx);
PRINT_CHAPTER(packets);
@@ -764,7 +776,11 @@ static int probe_file(const char *filename)
av_close_input_file(fmt_ctx);
writer_close(&wctx);
- return 0;
+end:
+ av_free(w_str);
+ av_free(w_args);
+
+ return ret;
}
static void show_usage(void)
More information about the ffmpeg-cvslog
mailing list