diff mbox series

[FFmpeg-devel,2/2] fftools/ffmpeg_demux: set discard on the AVStream directly

Message ID 20231218191913.2071-2-anton@khirnov.net
State Accepted
Commit 6916105b11fb2fbb6fb1698da47dc061c995afab
Headers show
Series [FFmpeg-devel,1/2] lavf: allow setting AVStream.discard as an AVOption | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Dec. 18, 2023, 7:19 p.m. UTC
Avoid taking an ugly detour through the decoder AVCodecContext.
---
 fftools/ffmpeg_demux.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index eca3de709c..a28a94b5ed 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1141,7 +1141,6 @@  static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
     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 ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
@@ -1150,20 +1149,20 @@  static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
         (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
             ist->user_set_discard = AVDISCARD_ALL;
 
-    ist->dec_ctx = avcodec_alloc_context3(ist->dec);
-    if (!ist->dec_ctx)
-        return AVERROR(ENOMEM);
-
+    MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
     if (discard_str) {
-        const AVOption *discard_opt = av_opt_find(ist->dec_ctx, "skip_frame",
-                                                  NULL, 0, 0);
-        ret = av_opt_eval_int(ist->dec_ctx, discard_opt, discard_str, &ist->user_set_discard);
+        ret = av_opt_set(ist->st, "discard", discard_str, 0);
         if (ret  < 0) {
             av_log(ist, AV_LOG_ERROR, "Error parsing discard %s.\n", discard_str);
             return ret;
         }
+        ist->user_set_discard = ist->st->discard;
     }
 
+    ist->dec_ctx = avcodec_alloc_context3(ist->dec);
+    if (!ist->dec_ctx)
+        return AVERROR(ENOMEM);
+
     ret = avcodec_parameters_to_context(ist->dec_ctx, par);
     if (ret < 0) {
         av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");