[FFmpeg-cvslog] ffmpeg: add abort_on option to allow aborting on empty output
Marton Balint
git at videolan.org
Thu Oct 22 19:12:02 CEST 2015
ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Sat Oct 17 23:46:09 2015 +0200| [ddc6bd8c95868b14aec385b2e7bb519559583042] | committer: Marton Balint
ffmpeg: add abort_on option to allow aborting on empty output
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Marton Balint <cus at passwd.hu>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ddc6bd8c95868b14aec385b2e7bb519559583042
---
doc/ffmpeg.texi | 8 ++++++++
ffmpeg.c | 7 +++++++
ffmpeg.h | 3 +++
ffmpeg_opt.c | 21 +++++++++++++++++++++
4 files changed, 39 insertions(+)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 76ea238..651c33c 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -1260,6 +1260,14 @@ Discard all frames excepts keyframes.
Discard all frames.
@end table
+ at item -abort_on @var{flags} (@emph{global})
+Stop and abort on various conditions. The following flags are available:
+
+ at table @option
+ at item empty_output
+No packets were passed to the muxer, the output is empty.
+ at end table
+
@item -xerror (@emph{global})
Stop and exit on error
diff --git a/ffmpeg.c b/ffmpeg.c
index 5e9a127..a19c816 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4054,6 +4054,7 @@ static int transcode(void)
OutputStream *ost;
InputStream *ist;
int64_t timer_start;
+ int64_t total_packets_written = 0;
ret = transcode_init();
if (ret < 0)
@@ -4134,6 +4135,12 @@ static int transcode(void)
if (ost->encoding_needed) {
av_freep(&ost->enc_ctx->stats_in);
}
+ total_packets_written += ost->packets_written;
+ }
+
+ if (!total_packets_written && (abort_on_flags & ABORT_ON_FLAG_EMPTY_OUTPUT)) {
+ av_log(NULL, AV_LOG_FATAL, "Empty output\n");
+ exit_program(1);
}
/* close each decoder */
diff --git a/ffmpeg.h b/ffmpeg.h
index e8066f8..cdcb3b4 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -383,6 +383,8 @@ enum forced_keyframes_const {
FKF_NB
};
+#define ABORT_ON_FLAG_EMPTY_OUTPUT (1 << 0)
+
extern const char *const forced_keyframes_const_names[];
typedef enum {
@@ -527,6 +529,7 @@ extern int start_at_zero;
extern int copy_tb;
extern int debug_ts;
extern int exit_on_error;
+extern int abort_on_flags;
extern int print_stats;
extern int qp_hist;
extern int stdin_interaction;
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 0da1ffd..8f6416c 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -106,6 +106,7 @@ int start_at_zero = 0;
int copy_tb = -1;
int debug_ts = 0;
int exit_on_error = 0;
+int abort_on_flags = 0;
int print_stats = -1;
int qp_hist = 0;
int stdin_interaction = 1;
@@ -199,6 +200,24 @@ static AVDictionary *strip_specifiers(AVDictionary *dict)
return ret;
}
+static int opt_abort_on(void *optctx, const char *opt, const char *arg)
+{
+ static const AVOption opts[] = {
+ { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
+ { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
+ { NULL },
+ };
+ static const AVClass class = {
+ .class_name = "",
+ .item_name = av_default_item_name,
+ .option = opts,
+ .version = LIBAVUTIL_VERSION_INT,
+ };
+ const AVClass *pclass = &class;
+
+ return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
+}
+
static int opt_sameq(void *optctx, const char *opt, const char *arg)
{
av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
@@ -3123,6 +3142,8 @@ const OptionDef options[] = {
"timestamp error delta threshold", "threshold" },
{ "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
"exit on error", "error" },
+ { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
+ "abort on the specified condition flags", "flags" },
{ "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
"copy initial non-keyframes" },
More information about the ffmpeg-cvslog
mailing list