mediafoundation: Introduce Media Foundation-based encoding support on WoA
Description
This PR introduces the media foundation plugin to OBS Studio, enabling Media Foundation-based encoding for H264, HEVC and AV1. This plugin supports hardware-accelerated encoding on Windows on ARM (WoA) devices, specifically those utilizing Qualcomm hardware encoders. The Key changes include:
- mediafoundation: Add base files for MFT encoders support on WoA
- mediafoundation: Add MFT H264 encoder for WoA
- mediafoundation: Add MFT HEVC encoder for WoA
- mediafoundation: Add MFT AV1 encoder for WoA
- cmake: Add mediafoundation plugin to OBS windows build
Motivation and Context
The primary motivation for these changes is to enable hardware-accelerated encoding on Windows on ARM (WoA) devices by reintroducing the win-mf plugin in OBS Studio. With the growing adoption of WoA devices, ensuring OBS Studio can leverage hardware encoders on this platform improves performance and efficiency, reducing CPU load while maintaining high-quality encoding.
By integrating the mediafoundation plugin into the build system, we enable native support for Media Foundation-based encoding on WoA, ensuring users on this platform can leverage hardware acceleration for streaming and recording. This change ensures better utilization of Qualcomm hardware encoders, providing a more efficient and optimized encoding experience.
How Has This Been Tested?
The changes have been tested by building OBS Studio on a Windows on ARM (WoA) device with Qualcomm hardware. The build completed successfully, and basic functionality tests confirmed that OBS Studio runs as expected with the media foundation plugin. Media Foundation-based encoding for H264, HEVC and AV1 was verified to function correctly, ensuring proper hardware acceleration on WoA devices utilizing Qualcomm hardware.
Types of changes
- New feature (non-breaking change which adds functionality)
Checklist:
- [x] My code has been run through clang-format.
- [x] I have read the contributing document.
- [x] My code is not on the master branch.
- [x] The code has been tested.
- [x] All commit messages are properly formatted and commits squashed where appropriate.
- [ ] I have included updates to all appropriate documentation.
I tested this on my Snapdragon X laptop and it does work as expected.
But Ideally this plugin should be either rewritten from the ground up, or replaced wholesale with just using the FFmpeg implemenation. At the very least, the AAC encoder could probably be removed. Of course since this is ancient it also doesn't support AV1 (which the X Elite chips do support).
Aside from what Pat mentioned, the naming also conflicts with #10471 right now.
Will this work with my older Surface Pro X (SQ2)?
If it works I can help test it.
Will this work with my older Surface Pro X (SQ2)? If it works I can help test it.
@dd-han Thanks for offering to help.
I believe it should work with your Surface Pro X [SQ2] which is based on the Snapdragon 8cx, If you get a change to try it out, please let me know how it goes.
Hi, I tried using version 31.1.0 beta 1 on my pc with 8cx Gen 3, and I got 2 problems with MF based encoding:
-
When using h264_mf encoder, it seems to be using CPU to encode the video.
-
When I tried to use hevc_mf encoder, OBS immediately crashed when I click the Start Recording button. The corresponding log files are attached below.
2025-05-31 21-12-18.txt Crash 2025-05-31 21-14-41.txt
Hi, I tried using version 31.1.0 beta 1 on my pc with 8cx Gen 3, and I got 2 problems with MF based encoding:
- When using h264_mf encoder, it seems to be using CPU to encode the video.
You are using the Media Foundation encoder via FFmpeg. That is not what is in this PR, and this PR has not been merged, so it is not in OBS Studio 31.1.0 Beta 1. Please use our forums or Discord for assistance.
@SA-Root When using h264_mf encoder, it seems to be using CPU to encode the video.
You need to pass additional flags to make hardware encoding work with the ffmpeg backend. See https://driver1998.github.io/posts/ffmpeg-hardware-video-encoding-on-qualcomm-woa/ (Chinese only)
Couple more notes:
- You should remove the AAC encoder, it was removed due to glitches and we don't really have a reason to reintroduce it
- If you insist on keeping it, add the
.codecsproperty so it is correctly recognised by the encoder selectors, currently it's not selectable due to missing codec information
- If you insist on keeping it, add the
- MediaFoundation does support DirectX textures as encoder input since Windows 8.1 and that should be preferred over copying data to system RAM
Couple more notes:
You should remove the AAC encoder, it was removed due to glitches and we don't really have a reason to reintroduce it
- If you insist on keeping it, add the
.codecsproperty so it is correctly recognised by the encoder selectors, currently it's not selectable due to missing codec informationMediaFoundation does support DirectX textures as encoder input since Windows 8.1 and that should be preferred over copying data to system RAM
@thirumalai-qcom did you have a chance to review these notes as well?
I tested this on my Snapdragon X laptop and it does work as expected.
@derrod Thanks for Confirming.
At the very least, the AAC encoder could probably be removed.
Apologies for the delayed response, there were some internal discussions on this. The AAC related changes have been dropped from this PR.
Of course since this is ancient it also doesn't support AV1 (which the X Elite chips do support).
There are also plans to add AV1 support. I'll get back on this shortly.
- MediaFoundation does support DirectX textures as encoder input since Windows 8.1 and that should be preferred over copying data to system RAM
@PatTheMav @derrod Got this preference confirmed from @Fenrirthviti , will keep you posted on this. 👍
I tested this on my Snapdragon X laptop and it does work as expected.
@derrod Thanks for Confirming.
At the very least, the AAC encoder could probably be removed.
Apologies for the delayed response, there were some internal discussions on this. The AAC related changes have been dropped from this PR.
Of course since this is ancient it also doesn't support AV1 (which the X Elite chips do support).
There are also plans to add AV1 support. I'll get back on this shortly.
- MediaFoundation does support DirectX textures as encoder input since Windows 8.1 and that should be preferred over copying data to system RAM
@PatTheMav @derrod Got this preference confirmed from @Fenrirthviti , will keep you posted on this. 👍
Just as a heads-up, because there's another PR that introduces support for Media Foundation-based capture devices, we have a potential conflict between both using the win-mf subdirectory.
I suggested a solution to this on the other PR that I'd recommend this PR leans into as well: https://github.com/obsproject/obs-studio/pull/10471#discussion_r2319454992
@derrod Of course since this is ancient it also doesn't support AV1 (which the X Elite chips do support). There are also plans to add AV1 support. I'll get back on this shortly.
Happy to announce, AV1 support has now been successfully integrated into this PR. 🥳 The CI-generated binaries of this PR include AV1 functionality.
Just as a heads-up, because there's another PR that introduces support for Media Foundation-based capture devices, we have a potential conflict between both using the
win-mfsubdirectory.I suggested a solution to this on the other PR that I'd recommend this PR leans into as well: #10471 (comment)
@PatTheMav, Thanks for the heads-up regarding the potential conflict with the win-mf subdirectory. I've reviewed your suggestion and applied the recommended changes. Please take a look and let me know if any further improvements are needed.
@PatTheMav, Thanks for the heads-up regarding the potential conflict with the win-mf subdirectory. I've reviewed your suggestion and applied the recommended changes. Please take a look and let me know if any further improvements are needed.
Sorry for the delayed response - I saw that, much appreciated.
I'll have to look into both PRs a bit more closely as both initially wanted to "be" win-mf, but that's not possible as they would clobber each other. So I need to figure out what the correct way is for this scenario and come up with a naming scheme you could follow.
Hi @RytoEX & @PatTheMav All comments from the previous review rounds have been addressed and resolved. Could you please take a moment to review and let us know if there are any additional comments or if we’re good to proceed with approval? Thanks in advance.