Volume Manipulation in MediaFoundation

Asked 2 years ago, Updated 2 years ago, 45 views

I asked the TeraTails site before, but they didn't respond at all, so I'll ask them again.

I wanted to control the video with C#, so I hesitated between DirectShow and MediaFoundation, but I decided to use MediaFoundation.NET because it is late for MS and has a .NET library.

https://sourceforge.net/projects/mfnet/

Actually, I put the NuGet package in VS2017.

I will skip the details, but I used samples (MFSamples-2016-09) for most of the parts related to video playback.

What I want to do strictly is fine control of the video (frame feed, playback speed change, synchronous playback after changing the playback position of the two videos, etc.), but now I can display, play, pause, and change the playback position in TrackBar.

However, I thought I looked at various samples, but I don't know how to control the volume.
I think it's the same thing to create from MediaSession, but I found that IFSimpleAudioVolume was an easy-to-understand name, but when I looked it up, I found a discussion that MS didn't even use it as a sample.

After all, I don't know what to do as a royal road.

To be honest, the volume doesn't require detailed operation, so I didn't think it would take long to go to a place like this, and it's withering quite a bit.
(Extremely, it's okay to just switch between the original volume and mute the original volume, but it's not possible to mute the Windows volume itself.)

It would be best if you have a sample, but do you have any reference materials?

Thank you for your cooperation.

==Added September 5==

Refer to the site you commented on (C++)

object ppvObject;
MFExtern.MFGetService(m_pSession, MFServices.MR_STREAM_VOLUME_SERVICE, type of (IMFAudioStreamVolume).GUID, out ppvObject);
m_pAudioStreamVolume=(IMFAudioStreamVolume)ppvObject;

I tried, but m_pAudioStreamVolume becomes null...
(To be exact, ppvObject returned null)

I came all the way here by groping, but I got stuck.
What's wrong...
There is no problem with video playback, playback speed change, playback position change, etc., so all I have to do is sound...
There is not much information on overseas websites, so it is quite difficult...

c#

2022-09-30 21:33

2 Answers

IMFAudioStreamVolume seems to be used for volume manipulation.

There seems to be a series of articles in C++, so please refer to them.
Summary of articles using MediaFoundation

If you extract the relevant parts, you will see the following:

Use MediaFoundation (2) Declaration of MediaFoundation Management Class

Which interface do you want to use?
The MediaFoundation interface used for this playback is as follows:
Interface Name   Role
Manage the overall health of the IMFMediaSession media.

when exchanging byte-byte data within the IMFByteStream MediaFoundation              Interface to use.

Managing the source portion of the IMFMediaSource media (including ByteStream) Manage the reference time when playing IMFPresentationClock media.
Manage the IMFVideoDisplayControl video state.
Manage IMFAudioStreamVolume audio volume.

MediaFoundation Management Class Implementation No.2

Volume System Processing
// Set bread changes
BOOL CMFSession::SetPan(intnAbsolutePan)
// Set volume
BOOL CMFSession::SetVolume(intnAbsoluteVolume)
I just leave it to the support function InnerSetVolume, so I'll do it there.

MediaFoundation Management Class Implementation No.3

Internal Volume Settings
// Set volume
HRESULT CMFSession::InnerSetVolume (void)


2022-09-30 21:33

Additional parts

I tried, but m_pAudioStreamVolume becomes null...

For IMFAudioStreamVolume has

The streaming audio render (SAR) exports this interface as a service. To get a pointer to the interface, call IMFGetService::GetService with the service identifier MR_STREAM_VOLUME_SERVICE.

The first argument in MFExtern.MFGetService() must pass the streaming audio render (SAR) object.


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.