diff mbox series

[FFmpeg-devel,14/25] fftools/ffmpeg: open decoders right after we know they are needed

Message ID 20230413141223.17245-14-anton@khirnov.net
State Accepted
Commit 2058402e001268e8bc68b33a8979429a73ed1b74
Headers show
Series [FFmpeg-devel,01/25] fftools/ffmpeg_mux_init: move new_output_stream() lower in the file | 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 April 13, 2023, 2:12 p.m. UTC
Will allow initializing subtitle encoding earlier.
---
 fftools/ffmpeg.c       | 5 -----
 fftools/ffmpeg_demux.c | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d8b06eb724..900d6e5e83 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1882,11 +1882,6 @@  static int transcode_init(void)
                 ifile->streams[j]->start = av_gettime_relative();
     }
 
-    /* init input streams */
-    for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
-        if (ist->decoding_needed && (ret = dec_open(ist)) < 0)
-            goto dump_format;
-
     /*
      * initialize stream copy and subtitle/data streams.
      * Encoded AVFrame based streams will get initialized when the first AVFrame
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index d15a714e90..91609509b2 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -566,6 +566,12 @@  static void ist_use(InputStream *ist, int decoding_needed)
     ist->discard          = 0;
     ist->st->discard      = ist->user_set_discard;
     ist->decoding_needed |= decoding_needed;
+
+    if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) {
+        int ret = dec_open(ist);
+        if (ret < 0)
+            report_and_exit(ret);
+    }
 }
 
 void ist_output_add(InputStream *ist, OutputStream *ost)