diff mbox series

[FFmpeg-devel,08/27] fftools/ffmpeg: do not use the encoder context for streamcopy

Message ID 20220723140952.31814-8-anton@khirnov.net
State Accepted
Commit 1eae0ee02ee74dc1833e9610a1574fe25cc7a2f0
Headers show
Series [FFmpeg-devel,01/27] fftools/ffmpeg: replace AVFrame.pkt_duration with duration | 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 July 23, 2022, 2:09 p.m. UTC
The streamcopy initialization code briefly needs an AVCodecContext to
apply AVOptions to. Allocate a temporary codec context, do not use the
encoding one.
---
 fftools/ffmpeg.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index cad9f1e885..0e30f8ce01 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2757,22 +2757,29 @@  static int init_output_stream_streamcopy(OutputStream *ost)
     OutputFile *of = output_files[ost->file_index];
     InputStream *ist = get_input_stream(ost);
     AVCodecParameters *par = ost->st->codecpar;
+    AVCodecContext *codec_ctx;
     AVRational sar;
     int i, ret;
     uint32_t codec_tag = par->codec_tag;
 
     av_assert0(ist && !ost->filter);
 
-    ret = avcodec_parameters_to_context(ost->enc_ctx, ist->st->codecpar);
+    codec_ctx = avcodec_alloc_context3(NULL);
+    if (!codec_ctx)
+        return AVERROR(ENOMEM);
+
+    ret = avcodec_parameters_to_context(codec_ctx, ist->st->codecpar);
     if (ret >= 0)
-        ret = av_opt_set_dict(ost->enc_ctx, &ost->encoder_opts);
+        ret = av_opt_set_dict(codec_ctx, &ost->encoder_opts);
     if (ret < 0) {
         av_log(NULL, AV_LOG_FATAL,
                "Error setting up codec context options.\n");
+        avcodec_free_context(&codec_ctx);
         return ret;
     }
 
-    ret = avcodec_parameters_from_context(par, ost->enc_ctx);
+    ret = avcodec_parameters_from_context(par, codec_ctx);
+    avcodec_free_context(&codec_ctx);
     if (ret < 0) {
         av_log(NULL, AV_LOG_FATAL,
                "Error getting reference codec parameters.\n");