[FFmpeg-devel] [PATCH 6/6] ffmpeg: Pass the global device context to encoder and decoder instances

Mark Thompson sw at jkqxz.net
Wed Jan 18 00:32:15 EET 2017


---
 ffmpeg.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index 6d1e358..781c0a4 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2748,6 +2748,12 @@ static int init_input_stream(int ist_index, char *error, int error_len)
          * audio, and video decoders such as cuvid or mediacodec */
         av_codec_set_pkt_timebase(ist->dec_ctx, ist->st->time_base);
 
+        if (hw_device_ctx) {
+            ist->dec_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
+            if (!ist->dec_ctx->hw_device_ctx)
+                return AVERROR(ENOMEM);
+        }
+
         if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
             av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
         if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) {
@@ -3271,6 +3277,12 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len)
             !av_dict_get(ost->encoder_opts, "ab", NULL, 0))
             av_dict_set(&ost->encoder_opts, "b", "128000", 0);
 
+        if (hw_device_ctx) {
+            ost->enc_ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
+            if (!ost->enc_ctx->hw_device_ctx)
+                return AVERROR(ENOMEM);
+        }
+
         if (ost->filter && av_buffersink_get_hw_frames_ctx(ost->filter->filter)) {
             ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter));
             if (!ost->enc_ctx->hw_frames_ctx)
-- 
2.7.4


More information about the ffmpeg-devel mailing list