[FFmpeg-cvslog] libavcodec/amfenc: Vulkan initialization support for encoder.

OvchinnikovDmitrii git at videolan.org
Wed Aug 28 04:33:23 EEST 2019


ffmpeg | branch: master | OvchinnikovDmitrii <ovchinnikov.dmitrii at gmail.com> | Thu Aug  8 21:33:25 2019 +0300| [f8ad2ddd7a51df5d6e768ba2a6f65ee64b94e29b] | committer: Philip Langdale

libavcodec/amfenc: Vulkan initialization support for encoder.

Added linux support for amf encoder through vulkan.

To use h.264(AMD VCE) encoder on linux amdgru-pro version 19.20+ and
amf-amdgpu-pro package(amdgru-pro contains, but does not install
automatically) are required.

This driver can be installed using amdgpu-pro-install script in
official amd driver archive.

Initialization of amf encoder occurs in this order:
1) trying to initialize through dx11(only windows)
2) trying to initialize through dx9(only windows)
3) trying to initialize through vulkan

Only Vulkan initialization available on linux.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f8ad2ddd7a51df5d6e768ba2a6f65ee64b94e29b
---

 Changelog            |  1 +
 doc/general.texi     | 16 +++++++++++++---
 libavcodec/amfenc.c  | 17 +++++++++++++++--
 libavcodec/version.h |  2 +-
 4 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Changelog b/Changelog
index efdc65610f..f1cddc4274 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ version <next>:
 - Intel QSV-accelerated MJPEG decoding
 - Intel QSV-accelerated VP9 decoding
 - support for TrueHD in mp4
+- Supoort AMD AMF encoder on Linux (via Vulkan)
 
 
 version 4.2:
diff --git a/doc/general.texi b/doc/general.texi
index 3c0c803449..d0c3525e02 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -27,16 +27,26 @@ enable it.
 
 @section AMD AMF/VCE
 
-FFmpeg can use the AMD Advanced Media Framework library under Windows
-for accelerated H.264 and HEVC encoding on hardware with Video Coding Engine (VCE).
+FFmpeg can use the AMD Advanced Media Framework library
+for accelerated H.264 and HEVC(only windows) encoding on hardware with Video Coding Engine (VCE).
 
-To enable support you must obtain the AMF framework header files from
+To enable support you must obtain the AMF framework header files(version 1.4.9+) from
 @url{https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git}.
 
 Create an @code{AMF/} directory in the system include path.
 Copy the contents of @code{AMF/amf/public/include/} into that directory.
 Then configure FFmpeg with @code{--enable-amf}.
 
+Initialization of amf encoder occurs in this order:
+1) trying to initialize through dx11(only windows)
+2) trying to initialize through dx9(only windows)
+3) trying to initialize through vulkan
+
+To use h.264(AMD VCE) encoder on linux amdgru-pro version 19.20+ and amf-amdgpu-pro
+package(amdgru-pro contains, but does not install automatically) are required.
+
+This driver can be installed using amdgpu-pro-install script in official amd driver archive.
+
 @section AviSynth
 
 FFmpeg can read AviSynth scripts as input. To enable support, pass
diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 384d8efc92..f66b95645e 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -213,6 +213,7 @@ static int amf_init_from_dxva2_device(AVCodecContext *avctx, AVDXVA2DeviceContex
 static int amf_init_context(AVCodecContext *avctx)
 {
     AmfContext *ctx = avctx->priv_data;
+    AMFContext1 *context1 = NULL;
     AMF_RESULT  res;
     av_unused int ret;
 
@@ -311,8 +312,20 @@ static int amf_init_context(AVCodecContext *avctx)
             if (res == AMF_OK) {
                 av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via D3D9.\n");
             } else {
-                av_log(avctx, AV_LOG_ERROR, "AMF initialisation failed via D3D9: error %d.\n", res);
-                return AVERROR(ENOSYS);
+                AMFGuid guid = IID_AMFContext1();
+                res = ctx->context->pVtbl->QueryInterface(ctx->context, &guid, (void**)&context1);
+                AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res);
+
+                res = context1->pVtbl->InitVulkan(context1, NULL);
+                context1->pVtbl->Release(context1);
+                if (res != AMF_OK) {
+                    if (res == AMF_NOT_SUPPORTED)
+                        av_log(avctx, AV_LOG_ERROR, "AMF via Vulkan is not supported on the given device.\n");
+                    else
+                        av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given Vulkan device: %d.\n", res);
+                    return AVERROR(ENOSYS);
+                }
+                av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via Vulkan.\n");
             }
         }
     }
diff --git a/libavcodec/version.h b/libavcodec/version.h
index e70ebc0c70..cda6dbae47 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR  58
 #define LIBAVCODEC_VERSION_MINOR  55
-#define LIBAVCODEC_VERSION_MICRO 101
+#define LIBAVCODEC_VERSION_MICRO 102
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list