mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-25 04:19:05 +00:00
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.
This commit is contained in:
parent
9806dda8a8
commit
cb50ada4f8
@ -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
|
Prettify the format of the displayed values, it corresponds to the
|
||||||
options "-unit -prefix -byte_binary_prefix -sexagesimal".
|
options "-unit -prefix -byte_binary_prefix -sexagesimal".
|
||||||
|
|
||||||
@item -print_format @var{format}
|
@item -print_format @var{writer_name}[=@var{writer_options}]
|
||||||
Set the output printing format.
|
Set the output printing format.
|
||||||
|
|
||||||
|
@var{writer_name} specifies the name of the writer, and
|
||||||
|
@var{writer_options} specifies the options to be passed to the writer.
|
||||||
|
|
||||||
For example for printing the output in JSON format, specify:
|
For example for printing the output in JSON format, specify:
|
||||||
@example
|
@example
|
||||||
-print_format json
|
-print_format json
|
||||||
|
36
ffprobe.c
36
ffprobe.c
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "libavformat/avformat.h"
|
#include "libavformat/avformat.h"
|
||||||
#include "libavcodec/avcodec.h"
|
#include "libavcodec/avcodec.h"
|
||||||
|
#include "libavutil/avstring.h"
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
#include "libavutil/pixdesc.h"
|
#include "libavutil/pixdesc.h"
|
||||||
#include "libavutil/dict.h"
|
#include "libavutil/dict.h"
|
||||||
@ -737,23 +738,34 @@ static int probe_file(const char *filename)
|
|||||||
AVFormatContext *fmt_ctx;
|
AVFormatContext *fmt_ctx;
|
||||||
int ret;
|
int ret;
|
||||||
Writer *w;
|
Writer *w;
|
||||||
|
const char *buf = print_format;
|
||||||
|
char *w_str = NULL, *w_args = NULL;
|
||||||
WriterContext *wctx;
|
WriterContext *wctx;
|
||||||
|
|
||||||
writer_register_all();
|
writer_register_all();
|
||||||
|
|
||||||
if (!print_format)
|
if (buf) {
|
||||||
print_format = av_strdup("default");
|
w_str = av_get_token(&buf, "=");
|
||||||
w = writer_get_by_name(print_format);
|
if (*buf == '=') {
|
||||||
if (!w) {
|
buf++;
|
||||||
fprintf(stderr, "Invalid output format '%s'\n", print_format);
|
w_args = av_get_token(&buf, "");
|
||||||
return AVERROR(EINVAL);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = writer_open(&wctx, w, NULL, NULL)) < 0)
|
if (!w_str)
|
||||||
return ret;
|
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)))
|
if ((ret = open_input_file(&fmt_ctx, filename)))
|
||||||
return ret;
|
goto end;
|
||||||
|
|
||||||
writer_print_header(wctx);
|
writer_print_header(wctx);
|
||||||
PRINT_CHAPTER(packets);
|
PRINT_CHAPTER(packets);
|
||||||
@ -764,7 +776,11 @@ static int probe_file(const char *filename)
|
|||||||
av_close_input_file(fmt_ctx);
|
av_close_input_file(fmt_ctx);
|
||||||
writer_close(&wctx);
|
writer_close(&wctx);
|
||||||
|
|
||||||
return 0;
|
end:
|
||||||
|
av_free(w_str);
|
||||||
|
av_free(w_args);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_usage(void)
|
static void show_usage(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user