[FFmpeg-devel] [PATCH] ffmpeg: support setting AVStream.discard
Michael Niedermayer
michaelni at gmx.at
Sat May 31 05:59:29 CEST 2014
TODO: update docs
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
ffmpeg.h | 3 +++
ffmpeg_opt.c | 17 +++++++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/ffmpeg.h b/ffmpeg.h
index 3783e2c..19d1bcf 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -204,6 +204,8 @@ typedef struct OptionsContext {
int nb_guess_layout_max;
SpecifierOpt *apad;
int nb_apad;
+ SpecifierOpt *discard;
+ int nb_discard;
} OptionsContext;
typedef struct InputFilter {
@@ -240,6 +242,7 @@ typedef struct InputStream {
int file_index;
AVStream *st;
int discard; /* true if stream data should be discarded */
+ int user_set_discard;
int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */
AVCodec *dec;
AVFrame *decoded_frame;
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index aad07b5..c3eda62 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -572,6 +572,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
char *framerate = NULL, *hwaccel = NULL, *hwaccel_device = NULL;
char *codec_tag = NULL;
char *next;
+ char *discard_str = NULL;
+ const AVOption *discard_opt = av_opt_find(dec, "skip_frame", NULL, 0, 0);
if (!ist)
exit_program(1);
@@ -601,6 +603,14 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
ist->reinit_filters = -1;
MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
+ MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
+ ist->user_set_discard = AVDISCARD_NONE;
+ if (discard_str && av_opt_eval_int(dec, discard_opt, discard_str, &ist->user_set_discard) < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
+ discard_str);
+ exit_program(1);
+ }
+
ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
switch (dec->codec_type) {
@@ -1148,7 +1158,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
if (source_index >= 0) {
ost->sync_ist = input_streams[source_index];
input_streams[source_index]->discard = 0;
- input_streams[source_index]->st->discard = AVDISCARD_NONE;
+ input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
}
ost->last_mux_dts = AV_NOPTS_VALUE;
@@ -1786,7 +1796,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) ost->avfilter = av_strdup("anull");
if(ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) ost->avfilter = av_strdup("null");
ist->discard = 0;
- ist->st->discard = AVDISCARD_NONE;
+ ist->st->discard = ist->user_set_discard;
break;
}
}
@@ -2834,6 +2844,9 @@ const OptionDef options[] = {
"print timestamp debugging info" },
{ "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
"maximum error rate", "ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success." },
+ { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
+ OPT_INPUT, { .off = OFFSET(discard) },
+ "discard", "" },
/* video options */
{ "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
--
1.7.9.5
More information about the ffmpeg-devel
mailing list