AMF support on linux #246
-
Is there an existing issue for this?
Is your issue described in the documentation?
Is your issue present in the nightly release?
Describe the BugCurrently, sunshine is not built with AMF support on linux. I didn't see any mention of that in the doc, I had to look at the code to understand why AMF wasn't working. AMF should be supported on linux, at least until vulkan video encoding is done. AMF is faster than VAAPI. I don't believe AMF need that much work to make it work on linux, someone that know a bit more than me about ffmpeg should be able to implement that quickly. For example, obs pr that implement AMF video encoding for linux: obsproject/obs-studio#7206 I tried to implement it myself with a simple patch: diff --git a/src/video.cpp b/src/video.cpp
index 0ee04ff..9314046 100644
--- a/src/video.cpp
+++ b/src/video.cpp
@@ -22,6 +21,10 @@ extern "C" {
extern "C" {
#include <libavutil/hwcontext_d3d11va.h>
}
+#else
+extern "C" {
+ #include <libavutil/hwcontext_vulkan.h>
+}
#endif
using namespace std::literals;
@@ -92,6 +95,8 @@ namespace video {
vaapi_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx);
util::Either<buffer_t, int>
cuda_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx);
+ util::Either<buffer_t, int>
+ vulkan_make_hwdevice_ctx(platf::hwdevice_t *hwdevice_ctx);
int
hwframe_ctx(ctx_t &ctx, platf::hwdevice_t *hwdevice, buffer_t &hwdevice_ctx, AVPixelFormat format);
@@ -553,12 +553,18 @@ namespace video {
PARALLEL_ENCODING | CBR_WITH_VBR | RELAXED_COMPLIANCE | NO_RC_BUF_LIMIT,
dxgi_make_hwdevice_ctx,
};
-
+#endif
static encoder_t amdvce {
"amdvce"sv,
+#ifdef _WIN32
AV_HWDEVICE_TYPE_D3D11VA, AV_HWDEVICE_TYPE_NONE,
AV_PIX_FMT_D3D11,
AV_PIX_FMT_NV12, AV_PIX_FMT_P010,
+#else
+ AV_HWDEVICE_TYPE_VULKAN, AV_HWDEVICE_TYPE_NONE,
+ AV_PIX_FMT_NONE,
+ AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P10,
+#endif
{
// Common options
{
@@ -597,9 +603,12 @@ namespace video {
"h264_amf"s,
},
PARALLEL_ENCODING,
+#ifdef _WIN32
dxgi_make_hwdevice_ctx
- };
+#else
+ vulkan_make_hwdevice_ctx
#endif
+ };
static encoder_t software {
"software"sv,
@@ -716,10 +725,10 @@ namespace video {
#endif
#ifdef _WIN32
quicksync,
- amdvce,
#endif
#ifdef __linux__
vaapi,
+ amdvce,
#endif
#ifdef __APPLE__
videotoolbox,
@@ -2031,6 +2010,8 @@ namespace video {
hwdevice->init_hwframes(frame_ctx);
if (auto err = av_hwframe_ctx_init(frame_ref.get()); err < 0) {
+ char string[AV_ERROR_MAX_STRING_SIZE];
+ BOOST_LOG(error) << "Failed to finalize context: "sv << av_make_error_string(string, AV_ERROR_MAX_STRING_SIZE, err);
return err;
}
@@ -2067,6 +2048,69 @@ namespace video {
return hw_device_buf;
}
+ util::Either<buffer_t, int>
+ vulkan_make_hwdevice_ctx(platf::hwdevice_t *base) {
+ buffer_t hw_device_buf;
+
+ auto status = av_hwdevice_ctx_create(&hw_device_buf, AV_HWDEVICE_TYPE_VULKAN, nullptr, nullptr, 0);
+ if (status < 0) {
+ char string[AV_ERROR_MAX_STRING_SIZE];
+ BOOST_LOG(error) << "Failed to create a Vulkan device: "sv << av_make_error_string(string, AV_ERROR_MAX_STRING_SIZE, status);
+ return -1;
+ }
+
+ return hw_device_buf;
+ }
+
util::Either<buffer_t, int>
cuda_make_hwdevice_ctx(platf::hwdevice_t *base) {
buffer_t hw_device_buf;
@@ -2153,6 +2197,8 @@ namespace video {
switch (type) {
case AV_HWDEVICE_TYPE_D3D11VA:
return platf::mem_type_e::dxgi;
+ case AV_HWDEVICE_TYPE_VULKAN:
+ return platf::mem_type_e::system;
case AV_HWDEVICE_TYPE_VAAPI:
return platf::mem_type_e::vaapi;
case AV_HWDEVICE_TYPE_CUDA: But sadly, it didn't work with the bundled ffmpeg, it error on Expected BehaviorNo response Additional ContextNo response Host Operating SystemLinux Operating System Versionn/a Architecture64 bit Sunshine commit or version0.20.0 Packagen/a GPU TypeAMD GPU Modeln/a GPU Driver/Mesa Versionn/a Capture Method (Linux Only)No response Confign/a AppsNo response Relevant log outputn/a |
Beta Was this translation helpful? Give feedback.
Replies: 19 comments 15 replies
-
Do you have any benchmarks/evidence to back up "AMF is faster than VAAPI"? vappi and amf are just different APIs to the same hardware I'm not sure how much faster amf could be. |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? FFMPEG has the capacity to offer AMF encoding on Linux, it would be great if this was enabled in Sunshine. I too hope that by having the option to use AMF and compare it with Vaapi I can work out some issues I'm currently having. |
Beta Was this translation helpful? Give feedback.
-
VAAPI Encoding on Linux curently is just bad experience (@2160p resolution). Here is the idea |
Beta Was this translation helpful? Give feedback.
-
it would be great, if developers add this feature to sunshine) life is not fair)) amd open linux drivers are great, but i use sunshine to stream and unfortunately nvidia codecs are better then amd |
Beta Was this translation helpful? Give feedback.
-
+1 on this, VAAPI Looks really bad for me at 1440P even at high bitrates, AMF on windows looks really good when I tried it |
Beta Was this translation helpful? Give feedback.
-
AMF should be enabled as optional, in some linux system VAAPI works really bad and slow comparing with AMF. How can I force to use AMF instead of Vaapi in sunshine ? |
Beta Was this translation helpful? Give feedback.
-
Same issue here, I have better perfs with software encoding with my 5700XT. |
Beta Was this translation helpful? Give feedback.
-
Any updates fro this request? |
Beta Was this translation helpful? Give feedback.
-
We cannot implement this until FFmpeg implements support for encoding GPU textures via the AMF encoding APIs. FFmpeg AMF encoding supports this on Windows via DX11 but there is no support on Linux. |
Beta Was this translation helpful? Give feedback.
-
FYI: AMF 1.4.33 released today, changelog mentions "experimental" RADV support:
https://github.com/GPUOpen-LibrariesAndSDKs/AMF/releases/tag/v1.4.33 UPD:
|
Beta Was this translation helpful? Give feedback.
-
Any news regarding this? The gap between Windows using AMF and Linux not using it is impressively massive for 4K gaming, which is the only viable option with 1440 for 55 inches screen. |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? Is it possible to use amdgpu-pro drivers to get AMF working on Sunshine? |
Beta Was this translation helpful? Give feedback.
-
Hi all, I'm convinced that most of the issues you're experiencing is due to VA-API not exposing AMD's low latency mode. This can be fixed (in a slightly hackish way) by recompiling mesa with a patch. All the feedback thay I've seen has been positive and the encoding times reported by Windows users are the same as those reported by Linux users with a patched mesa (10-14ms at 4k60). This is now documented in Sunshine's docs: https://docs.lizardbyte.dev/projects/sunshine/en/master/troubleshooting/linux.html#amd-encoding-latency-issues Without the patch there are definitely issues, 4k being particularly affected: https://github.com/LizardByte/Sunshine/discussions/2193 If you go this route and recompile Mesa, please consider sharing instructions for your distribution. I'll go first, here's for Ubuntu: https://gist.github.com/gschintgen/ea148962f024b1c75e3c9ad5a114afa5 (I'm not saying AMF should not be supported, but priority should lie in fixing the actual issues, independently of the api.) |
Beta Was this translation helpful? Give feedback.
-
Just wanted to chime in and mention that with the latest release of AMF on Linux, the RADV driver is now fully supported for encoding. In theory at least, this makes it seem to me that we could now have our cake and eat it too |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? |
Beta Was this translation helpful? Give feedback.
-
I have issues using VA-API encoder too while using Ubuntu, stuttering whilst streaming to moonlight. Worked fine on Windows using AMF. |
Beta Was this translation helpful? Give feedback.
-
I have the same problem with my 9070 XT. Streaming 4K is a stuttery mess. |
Beta Was this translation helpful? Give feedback.
-
Friends, The fact is:
Which ffmpeg already said:
but h264_amf doesn't suppout AV_PIX_FMT_VULKAN But fortunately |
Beta Was this translation helpful? Give feedback.
-
It seems like AMF will go away:
source: https://www.amd.com/en/resources/support-articles/release-notes/RN-AMDGPU-UNIFIED-LINUX-25-10-1.html |
Beta Was this translation helpful? Give feedback.
It seems like AMF will go away:
source: https://www.amd.com/en/resources/support-articles/release-notes/RN-AMDGPU-UNIFIED-LINUX-25-10-1.html