From 9115df2346e23d2e3eff4fb78cbd80419267eb7d Mon Sep 17 00:00:00 2001 From: Trystan Mata Date: Sat, 21 May 2022 16:26:56 +0200 Subject: [PATCH] avcodec/mfenc: Dynamically load MediaFoundation library Allows non-UWP builds of FFmpeg with MediaFoundation to work on N editions of Windows which are without MediaFoundation by default. On UWP target, avcodec is link directly against MediaFoundation since LoadLibrary is not available. This commit adresses https://trac.ffmpeg.org/ticket/9788 Signed-off-by: Trystan Mata --- configure | 5 +- libavcodec/mf_utils.c | 106 ++++++++++++++++++++++++++++++++++-------- libavcodec/mf_utils.h | 19 ++++++-- libavcodec/mfenc.c | 25 +++++++++- 4 files changed, 131 insertions(+), 24 deletions(-) diff --git a/configure b/configure index f115b21064..432a0d163d 100755 --- a/configure +++ b/configure @@ -3130,7 +3130,6 @@ wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel" # hardware-accelerated codecs mediafoundation_deps="mftransform_h MFCreateAlignedMemoryBuffer" -mediafoundation_extralibs="-lmfplat -lmfuuid -lole32 -lstrmiids" omx_deps="libdl pthreads" omx_rpi_select="omx" qsv_deps="libmfx" @@ -6876,6 +6875,10 @@ test_cpp <priv_data; HRESULT hr; @@ -1134,6 +1138,10 @@ static int mf_close(AVCodecContext *avctx) ff_free_mf(&c->mft); +#if !HAVE_UWP + ff_mf_unload_library(); +#endif + av_frame_free(&c->frame); av_freep(&avctx->extradata); @@ -1142,6 +1150,21 @@ static int mf_close(AVCodecContext *avctx) return 0; } +#if !HAVE_UWP +static int mf_init(AVCodecContext *avctx) +{ + int ret; + + if ((ret = ff_mf_load_library(avctx)) == 0) { + if ((ret = mf_init_encoder(avctx)) == 0) { + return 0; + } + } + mf_close(avctx); + return ret; +} +#endif + #define OFFSET(x) offsetof(MFContext, x) #define MF_ENCODER(MEDIATYPE, NAME, ID, OPTS, EXTRA) \ -- 2.36.1