I am using MediaTranscoder with GraphicsCaptureItem to capture screen and record to a compressed video file.
I have Radeon 860M (built into Ryzen AI 7 350), that supports hardware encoding of H.264 and AV1. Both hardware codecs are listed when I call
var codecQuery = new CodecQuery();
var videoEncoders = await codecQuery
.FindAllAsync(CodecKind.Video, CodecCategory.Encoder, "");
Specifically, I get AMDav1Encoder with subtype {31305641-0000-0010-8000-00AA00389B71}.
So I create a MediaEncodingProfile like this:
var encodingProfile = MediaEncodingProfile.CreateAv1(VideoEncodingQuality.Auto);
encodingProfile.Video = VideoEncodingProperties.CreateAv1();
encodingProfile.Video.Bitrate = 10_000_000;
encodingProfile.Video.FrameRate.Numerator = 20;
encodingProfile.Video.FrameRate.Denominator = 1;
encodingProfile.Video.PixelAspectRatio.Numerator = 1;
encodingProfile.Video.PixelAspectRatio.Denominator = 1;
encodingProfile.Video.ProfileId = 0;
// Describe audio input
encodingProfile.Audio = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Low).Audio;
encodingProfile.Audio.SampleRate = 48000;
await _transcoder.PrepareMediaStreamSourceTranscodeAsync(_mediaStreamSource, destination, encodingProfile);
This last call fails with COMException 0xC00DA412, which seems to map to MF_E_TRANSCODE_NO_MATCHING_ENCODER, which seems to indicate transcoder is unable to find AV1 encoder. Just to be clear _transcoder.HardwareAccelerationEnabled is set to true.
What I tried so far:
- Using H.264: replacing both
CreateAv1withCreateMp4andCreateH264works, but the it does not use AV1. - Setting
ProfileIdto 0 (default value was 1, and it produced the same error) - same error. - When creating source from the screen, pretend that it is actually NV12 (which was Bgra8). I thought maybe encoder only supports NV12 input. However, this still failed with
MF_E_TRANSCODE_NO_MATCHING_ENCODER.
This is what I get when I inspect the encodingProfile.Video.Properties:
- {23e5cad8-a3fc-4f0f-97c3-dff51d03bc92} - 1 (uint)
- {c6376a1e-8d0a-4027-be45-6d9a0ad39bb6} - 4294967297 (ulong)
- {48eba18e-f8c9-4687-bf11-0a74c9f96a8f} - {73646976-0000-0010-8000-00aa00389b71} (System.Guid)
- {c459a2e8-3d2c-4e44-b132-fee5156c7bb0} - 42949672961 (ulong)
- {20332624-fb0d-4d9e-bd0d-cbf6786c102e} - 10000000 (uint)
- {1652c33d-d6b2-4012-b834-72030849a37d} - 16492674418800 (ulong)
- {f7e34c9a-42e8-4714-b74b-cb29d72c35e5} - {31305641-0000-0010-8000-00aa00389b71} (this is the AV1 subtype)
- {ad76a80b-2d5c-4e0b-b375-64e520137036} - 1 (uint, this is the profile)
Trying HEVC (by replacing CreateAv1 with CreateHEVC) also fails, but with 0xC00D6D60 MF_E_TRANSFORM_TYPE_NOT_SET which does not seem directly related, but suspicious because exact same HEVC code works on a machine with Nvidia GPU.