diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index f541c295..2c181193 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -458,6 +458,24 @@ void FFmpegReader::Open() throw InvalidCodec("Hardware device reference create failed.", path); } /* + av_buffer_unref(&ist->hw_frames_ctx); + ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); + if (!ist->hw_frames_ctx) { + av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n"); + return AVERROR(ENOMEM); + } + + frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; + + frames_ctx->format = AV_PIX_FMT_CUDA; + frames_ctx->sw_format = avctx->sw_pix_fmt; + frames_ctx->width = avctx->width; + frames_ctx->height = avctx->height; + + av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n", + av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height); + + ret = av_hwframe_ctx_init(pCodecCtx->hw_device_ctx); ret = av_hwframe_ctx_init(ist->hw_frames_ctx); if (ret < 0) { diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index 66befe5c..c4f2ca43 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -1053,6 +1053,7 @@ AVStream* FFmpegWriter::add_video_stream() } #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 39, 101) else { +#if IS_FFMPEG_3_2 if (hw_en_on) { double mbs = 15000000.0; if (info.video_bit_rate > 0) { @@ -1065,7 +1066,9 @@ AVStream* FFmpegWriter::add_video_stream() } c->bit_rate = (int)(mbs); } - else { + else +#endif + { switch (c->codec_id) { #if (LIBAVCODEC_VERSION_MAJOR >= 58) case AV_CODEC_ID_AV1 :