Quantcast
Channel: Media Foundation Development for Windows Desktop forum
Viewing all 1079 articles
Browse latest View live

Does sink writer on windows phone 8.1 support aac file in 22050Hz?

$
0
0

Hi

I am trying to encode raw pcm to aac file with the following code:

	m_outputAudioFormat = MFAudioFormat_AAC;
	m_sourceSamplesPerSecond = 44100;
	m_samplesPerSecond =44100;
	m_samplesRatio = 1.0;
	m_numChannels = 1;
	m_bitsPerSample = 16;

	// Create and configure the output media type.
	ThrowIfFailed(
		MFCreateMediaType(&pOutputMediaType)
		);
	ThrowIfFailed(
		pOutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)
		);
	ThrowIfFailed(
		pOutputMediaType->SetGUID(MF_MT_SUBTYPE, this->m_outputAudioFormat)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, this->m_samplesPerSecond)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 12000)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, this->m_numChannels)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, this->m_bitsPerSample)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, 1)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1)
		);
	/*ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1)
		);*/
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_COMPRESSED, 1)
		);
	ThrowIfFailed(
		pOutputMediaType->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, 1)
		);
	DWORD streamIndex;
	ThrowIfFailed(
		this->m_pSinkWriter->AddStream(pOutputMediaType, &streamIndex)
		);

	// Set the input media type.
	ThrowIfFailed(
		MFCreateMediaType(&pInMediaType)
		);
	ThrowIfFailed(
		pInMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio)
		);
	ThrowIfFailed(
		pInMediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM)
		);
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, this->m_sourceSamplesPerSecond)
		);
	this->m_sourceAverageBytesPerSecond = this->m_sourceSamplesPerSecond * this->m_blockAlign;
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, this->m_sourceAverageBytesPerSecond)
		);
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, this->m_numChannels)
		);
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, this->m_bitsPerSample)
		);
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, this->m_blockAlign)
		);
	ThrowIfFailed(
		pInMediaType->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1)
		);

	hr = this->m_pSinkWriter->SetInputMediaType(streamIndex, pInMediaType, nullptr);

This works ok on windows phone 8.1 when input and output sample rate are both 44100.

But if I set the input and output sample rate to 22050, the last line "SetInputMediaType" will fail with code 0xc00d36b4.

Does that mean media foundation do not support 22050hz aac encode on windows phone 8.1?

Or I missed anything?


Transcode Apple ProRes

$
0
0

I am working through the tutorial at https://msdn.microsoft.com/en-us/library/windows/desktop/ff819476(v=vs.85).aspx because I need to write a program to transcode Apple ProRes files to H.264. The program does not work. Can anyone advise me how to do this? The program works on an already transcoded file, but not the original ProRes files. This is what ffmpeg has to say about the format:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Pan 1-15_05_15R_14_2.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2015-05-15 17:51:39
  Duration: 00:01:34.43, start: 0.000000, bitrate: 140392 kb/s
    Stream #0:0(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2015-05-15 17:51:39
      handler_name    : Linux Alias Data Handler
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2015-05-15 17:51:39
      handler_name    : Linux Alias Data Handler
    Stream #0:2(eng): Video: prores (apcn / 0x6E637061), yuv422p10le, 1920x1080, 138086 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 2997 tbc (default)
    Metadata:
      creation_time   : 2015-05-15 17:51:39
      handler_name    : Linux Alias Data Handler
      encoder         : Apple ProRes 422
      timecode        : 17:51:39:00
    Stream #0:3(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      rotate          : 0
      creation_time   : 2015-05-15 17:51:39
      handler_name    : Libquicktime Time Code Media Handler
      reel_name       : 001
      timecode        : 17:51:39:00
Unsupported codec with id 0 for input stream 3

Thanks.

different behavior of H.264 encoder MFT on Win7 and Win8

$
0
0

Hi guys,

Several months have passed since I finished my program which uses H.264 and AAC encoder MFT to convert video files into MP4. While it works well on Win7, when I ran it on Win8 (also tried on Win10 Build 10240) yesterday, I found something different form what I saw on Win7.

My program calls MFT->ProcessInput() to send frames into encoder and calls ProcessOutput after every ProcessInput.

Below is the log generated when I convert a file on Win7. Every time ProcessInput is called, ProcessOutput returns a frame.

	Line 178: 00:00:24.562  MAIN  encoding time = 0, duration = 420000
	Line 180: 00:00:24.828  MAIN                   sample returned, sample time = 0
	Line 185: 00:00:24.875  MAIN  encoding time = 420000, duration = 420000
	Line 187: 00:00:25.234  MAIN                   sample returned, sample time = 420000
	Line 192: 00:00:25.359  MAIN  encoding time = 840000, duration = 420000
	Line 194: 00:00:25.469  MAIN                   sample returned, sample time = 840000
	Line 199: 00:00:25.484  MAIN  encoding time = 1260000, duration = 410000
	Line 201: 00:00:25.562  MAIN                   sample returned, sample time = 1260000
	Line 206: 00:00:25.578  MAIN  encoding time = 1670000, duration = 420000
	Line 208: 00:00:25.656  MAIN                   sample returned, sample time = 1670000
	Line 213: 00:00:25.672  MAIN  encoding time = 2090000, duration = 420000
	Line 215: 00:00:25.781  MAIN                   sample returned, sample time = 2090000
	Line 220: 00:00:25.859  MAIN  encoding time = 2510000, duration = 420000
	Line 222: 00:00:26.015  MAIN                   sample returned, sample time = 2510000

Below is what I saw when converting same file on Windows 8.1 64bits and Windows 10

	Line 196: 00:00:21.187  MAIN  encoding time = 0, duration = 420000
	Line 200: 00:00:21.203  MAIN  encoding time = 420000, duration = 420000
	Line 204: 00:00:21.234  MAIN  encoding time = 840000, duration = 420000
	Line 208: 00:00:21.265  MAIN  encoding time = 1260000, duration = 410000
	Line 210: 00:00:21.281  MAIN                   sample returned, sample time = 420000
	Line 215: 00:00:21.297  MAIN  encoding time = 1670000, duration = 420000
	Line 217: 00:00:21.312  MAIN                   sample returned, sample time = 1260000
	Line 222: 00:00:21.343  MAIN  encoding time = 2090000, duration = 420000
	Line 224: 00:00:21.359  MAIN                   sample returned, sample time = 840000
	Line 230: 00:00:21.375  MAIN  encoding time = 2510000, duration = 420000
	Line 232: 00:00:21.406  MAIN                   sample returned, sample time = 2090000
	Line 237: 00:00:21.422  MAIN  encoding time = 2930000, duration = 410000
	Line 239: 00:00:21.437  MAIN                   sample returned, sample time = 1670000
	Line 245: 00:00:21.468  MAIN  encoding time = 3340000, duration = 420000
	Line 247: 00:00:21.484  MAIN                   sample returned, sample time = 2930000
	Line 252: 00:00:21.515  MAIN  encoding time = 3760000, duration = 420000
	Line 254: 00:00:21.515  MAIN                   sample returned, sample time = 2510000

It doesn't matter first frame returns until 4 frames are sent to encoder, what matters to me is that the timestamps of returned frames are not monotonically increasing. (42, 126, 84, 209 ... timestamps is get by calling IMFSample->GetSampleTime()).

After that I ran mftrace on Windows 10 and get this

MFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @08379F88, Time 0ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 42ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 84ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 126ms, Duration 41ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 167ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 209ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 42ms, Duration 42ms, Buffers 1, Size 24841B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=0 (0,0);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=0;MFSampleExtension_CleanPoint=1;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 251ms, Duration 42ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 126ms, Duration 42ms, Buffers 1, Size 1152B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=420000 (0,420000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=1;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessInput @0845899C Stream ID 0, Sample @0C16F1B8, Time 293ms, Duration 41ms, Buffers 1, Size 345600B,
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 84ms, Duration 42ms, Buffers 1, Size 20B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=840000 (0,840000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=2;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT

Lets check ProcessOutput only

CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 42ms, Duration 42ms, Buffers 1, Size 24841B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=0 (0,0);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=0;MFSampleExtension_CleanPoint=1;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 126ms, Duration 42ms, Buffers 1, Size 1152B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=420000 (0,420000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=1;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT
CMFTransformDetours::ProcessOutput @0845899C Stream ID 0, Sample @08379F88, Time 84ms, Duration 42ms, Buffers 1, Size 20B, {73A954D4-09E2-4861-BEFC-94BD97C08E6E}=840000 (0,840000);{9154733F-E1BD-41BF-81D3-FCD918F71332}=65535;{973704E6-CD14-483C-8F20-C9FC0928BAD5}=2;MFSampleExtension_CleanPoint=0;{B2EFE478-F979-4C66-B95E-EE2B82C82F36}=29 (0,29)
CMFTransformDetours::ProcessOutput @0845899C failed hr=0xC00D6D72 MF_E_TRANSFORM_NEED_MORE_INPUT

we can see that the returned timestamps are  42, 126, 84 ...

Because in my program, the muxer (which muxes encoded video and audio data and write them into files) requires monotonically increasing timestamps, the behavior of H.264 encoder MFT on Win8/10 breaks the file conversion.

If anyone is interested in whole mftrace log, I've put it here https://dl.dropboxusercontent.com/u/89678527/mfrelease.log

Thanks for any idea.

AAC Decoder cannot handle 16000 Hz since Win10

$
0
0

CMSAACDecMFT decoder filter fails to decode AAC audio with 16.000 Hz since Win10. Works fine with 48 and 44.1 kHz and works fine with 16 kHz in Win 8.1

Since Win10 I get a

MF_E_TRANSFORM_TYPE_NOT_SET

error while

ProcessOutput()

Transform type is properly set.

AAC Decoder cannot handle 16000 Hz since Win10

$
0
0

CMSAACDecMFT decoder filter fails to decode AAC audio with 16.000 Hz since Win10. Works fine with 48 and 44.1 kHz and works fine with 16 kHz in Win 8.1.

Since Win10 I get a MF_E_TRANSFORM_TYPE_NOT_SET error while ProcessOutput().

Transform type is however properly set.

Program is blocked at ProcessOutput of H264 decoder MFT.

$
0
0

Hello,

We are trying to use MFT to decode H264 stream.

To take advantage of hardware decode, I pass a Direct3DManager pointer to the MFT and set output type with NV12 successfully. An output queue with 3 elements is created to store output data. Every time the output queue gets full, the first element is consumed (send to display) and released. Then new output data is produced and added to output queue.

The mechanism works well in Windows 7, however something goes wrong in Windows 8. After a few output samples were produced using ProcessOutput successfully, program is blocked at ProcessOutput and never return. I suspend that the output samples were not released properly but the program runs well in Windows 7.

What is the difference between Windows 7 and Windows 8 that contributes to the misbehavior described above?

Thanks.

Get black image using IMFVideoDisplayControl GetCurrentImage

$
0
0

I am using the method GetCurrentImage of the IMFVideoDisplayInterface to capture a screenshot of a video. The video displays OK and, when I tries to capture the screenshot and call to GetCurrentImage, I obtain an array with all its values zero.

The result of calling the mehod is S_OK, and the width and height of the obtained image are reasonable values (590x349). Also, these values coincide with the size of the array of bytes got from the GetCurrentImage method.

My code is like this:

  HRESULT hr = S_OK;
  BITMAPINFOHEADER infoHeader;
  infoHeader.biSize = sizeof(BITMAPINFOHEADER);
  BYTE* pDib = NULL;
  DWORD cbDib = 0;
  LONGLONG timeStamp = 0;
  hr = m_pVideoDisplay->GetCurrentImage(&infoHeader, &pDib, &cbDib, &timeStamp);

As commented before, hr is S_OK, the timestamp gives a reasonable value as well as the values of the BITMAPINFOHEADER.

Has anyone an idea of what is happening? Help will be appreciated.

midiOutOpen fails with MMSYSERR_ERROR for the Microsoft GS Wavetable Synth in Windows 10

$
0
0
Has anyone else encountered this or found a workaround? - see https://stackoverflow.com/questions/31752786/midioutopen-on-windows-10-using-microsoft-gs-wavetable-synth-fails

ffmpeg VS Media Foundation.

$
0
0

Hi All,

I have a little experience with Media Foundation and I know how to use it. But I don't know about the ffmpeg. Could someone tell me which is the best one. Actaully, I am not a huge fan of Open Source but currious to know about it. Move on the right way is hard because there's lot of File Format and Container.

Thanks,

Weera

Program is blocked at ProcessOutput method of H264 decoder MFT.

$
0
0

Hello,

We are trying to use MFT to decode H264 stream.

To take advantage of hardware decode, I pass a Direct3DManager pointer to the MFT and set output type with NV12 successfully. An output queue with 3 elements is created to store output data. Every time the output queue gets full, the first element is consumed (send to display) and released. Then new output data is produced and added to output queue.

The mechanism works well in Windows 7, however something goes wrong in Windows 8. After a few output samples were produced using ProcessOutput successfully, program is blocked at ProcessOutput and never return. I suspend that the output samples were not released properly but the program runs well in Windows 7.

What is the difference between Windows 7 and Windows 8 that contributes to the misbehavior described above?

Thanks.

2015-9-6

--------------------------------------------------------------------------------------------------------

I built a small project to test the H264 decoder's (CLSID_Microsoft H264 Video Decoder MFT) behavior. A Direct3DManager pointer is passed to the decoder thus it can perform hardware decode. Output type is set to MFVideoFormat_NV12 successfully. Then I feed the decoder with I and P frames using ProcessInput method. As expected, I get output data with ProcessOutput method successfully. Everytime I get an output sample, I retrieve the surface from it and write the data to a file. Then I release the surface and the sample. All things go well. 

Back to my application, I deleted the display part to narrow down the region bug may reside. When new output sample is produced with ProcessOutput method, I just release it. However, after 6 successful output, program still gets blocked at ProcessOutput method. This is what I do in the trial project described above. I don't understand why it's not working.

Is there anything I missed?

I still suspend that some resource is not released properly. Is it enough to release the output sample? 

2015-9-11

--------------------------------------------------------------------------------------------------------


MP4 H.264 seeking problem

$
0
0

Hi,

I have a seeking problem with some mp4 video files. Using the SetCurrentPosition method of the SourceReader and after that the ReadSample method, sometimes you get the correct previous keyframe, sometimes you get the keyframe before the previous keyframe and sometimes you get any other frame (which is no keyframe). I don`t know what happens here. I know that the description says, that seeking is not always accurate... but within a MP4 video file, it is pretty simple to acchieve this-.

When I read out the stbl atom with my own parser, I get all sync frames and when I use ReadSample to read every frame from the start to the end of the video file and check if it is a sync frame by using the "MFSampleExtension_CleanPoint" attribute, I get the same result.

Is there a known bug? During my search in the forum I found this interesting question, where the opener is talking about the same problem using WMV files.

https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/572a4d0b-6217-4732-ac6d-26f8b9f83bce/in-some-wmv-movies-when-seeking-to-a-position-the-media-source-seeks-to-the-nearest-next-key-frame?forum=mediafoundationdevelopment&prof=required

best regards and thanks for your feedback

saoirse

Why does Trancoder IMFMediaSession result in truncated output files in Azure VM?

$
0
0

Hello

I am using The MF Transcoder API (this SDK sample). Its a simple console app whose job is to convert a bunch of compressed WAV files to M4A (MP4) in a multithread fashion. n threads are spun, and on each thread, exactly one transcoder operation (consisting of 1 mf source + 1 mf transcoder profile + 1 mf session). The threads don't share any state. These are my findings:

1. Windows 8.1 desktop - The system scales to # of cores, and transcoding is flawless.

2. Windows 2012 R2 server - The system scales to # of cores, and transcoding is flawless.

3. Windows 2012 R2 server in Azure VM role - The system scales but transcoded files are clipped.

I investigated #3 further and found that serial operation works fine but output file clipping worsens with load. The MF event and interface do not result any error code. Tracking transcoder completion (through IMFPresentationClock obtain from IMFMediaSession) indicates that the full file was transcoded. But the file written the disk is clipped. Additionally, introducing a Sleep() of 1 secs between MESessionEnded and IMFMediaSession::Close() helps a bit, but doesn't solve the problem.

I was wondering if somebody could help understand what is happening here? Why does MF truncate output files on Win2012R2/Azure?

Thx in advance.

-Vishal

Play audio from file to speaker with Media Foundation

$
0
0

I'm attempting to play the audio track from an mp4 file to my speaker. I know Media Foundation is able to decode the audio stream as I can play it with the TopoEdit tool.

In the sample code below I'm not using a media session or topology. I'm attempting to manually connect the media source to the sink writer. The reason I want to do this is that I ultimately intend to be getting the source samples from the network rather than from a file.

The error I get on the pSinkWriter->WriteSample line when running the sample below is MF_E_INVALIDREQUEST (0xC00D36B2). So I suspect there's something I haven't wired up correctly.

#include <stdio.h>
#include <tchar.h>
#include <mfapi.h>
#include <mfplay.h>
#include <mfreadwrite.h>

#pragma comment(lib, "mf.lib")
#pragma comment(lib, "mfplat.lib")
#pragma comment(lib, "mfplay.lib")
#pragma comment(lib, "mfreadwrite.lib")
#pragma comment(lib, "mfuuid.lib")

#define CHECK_HR(hr, msg) if (hr != S_OK) { printf(msg); printf("Error: %.2X.\n", hr); goto done; }

int _tmain(int argc, _TCHAR* argv[])
{
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    MFStartup(MF_VERSION);

    IMFSourceResolver *pSourceResolver = NULL;
    IUnknown* uSource = NULL;
    IMFMediaSource *mediaFileSource = NULL;
    IMFSourceReader *pSourceReader = NULL;
    IMFMediaType *pAudioOutType = NULL;
    IMFMediaType *pFileAudioMediaType = NULL;
    MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
    IMFMediaSink *pAudioSink = NULL;
    IMFStreamSink *pStreamSink = NULL;
    IMFMediaTypeHandler *pMediaTypeHandler = NULL;
    IMFMediaType *pMediaType = NULL;
    IMFMediaType *pSinkMediaType = NULL;
    IMFSinkWriter *pSinkWriter = NULL;

    // Set up the reader for the file.
    CHECK_HR(MFCreateSourceResolver(&pSourceResolver), "MFCreateSourceResolver failed.\n");

    CHECK_HR(pSourceResolver->CreateObjectFromURL(
        L"big_buck_bunny.mp4",      // URL of the source.
        MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
        NULL,                       // Optional property store.&ObjectType,                // Receives the created object type.&uSource                    // Receives a pointer to the media source.
        ), "Failed to create media source resolver for file.\n");

    CHECK_HR(uSource->QueryInterface(IID_PPV_ARGS(&mediaFileSource)), "Failed to create media file source.\n");

    CHECK_HR(MFCreateSourceReaderFromMediaSource(mediaFileSource, NULL, &pSourceReader), "Error creating media source reader.\n");

    CHECK_HR(pSourceReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &pFileAudioMediaType), "Error retrieving current media type from first audio stream.\n");

    // printf("File Media Type:\n");
    // Dump pFileAudioMediaType.

    // Set the audio output type on the source reader.
    CHECK_HR(MFCreateMediaType(&pAudioOutType), "Failed to create audio output media type.\n");
    CHECK_HR(pAudioOutType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio), "Failed to set audio output media major type.\n");
    CHECK_HR(pAudioOutType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float), "Failed to set audio output audio sub type (Float).\n");

    CHECK_HR(pSourceReader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, NULL, pAudioOutType), "Error setting reader audio output type.\n");

    // printf("Source Reader Output Type:");
    // Dump pAudioOutType.

    CHECK_HR(MFCreateAudioRenderer(NULL, &pAudioSink), "Failed to create audio sink.\n");

    CHECK_HR(pAudioSink->GetStreamSinkByIndex(0, &pStreamSink), "Failed to get audio renderer stream by index.\n");

    CHECK_HR(pStreamSink->GetMediaTypeHandler(&pMediaTypeHandler), "Failed to get media type handler.\n");

    // My speaker has 3 audio types of which I got the furthesr with the third one.
    CHECK_HR(pMediaTypeHandler->GetMediaTypeByIndex(2, &pSinkMediaType), "Failed to get sink media type.\n");

    CHECK_HR(pMediaTypeHandler->SetCurrentMediaType(pSinkMediaType), "Failed to set current media type.\n");

    // printf("Sink Media Type:\n");
    // Dump pSinkMediaType.

    CHECK_HR(MFCreateSinkWriterFromMediaSink(pAudioSink, NULL, &pSinkWriter), "Failed to create sink writer from audio sink.\n");

    printf("Read audio samples from file and write to speaker.\n");

    IMFSample *audioSample = NULL;
    DWORD streamIndex, flags;
    LONGLONG llAudioTimeStamp;

    for (int index = 0; index < 10; index++)
    //while (true)
    {
        // Initial read results in a null pSample??
        CHECK_HR(pSourceReader->ReadSample(
            MF_SOURCE_READER_FIRST_AUDIO_STREAM,
            0,                              // Flags.&streamIndex,                   // Receives the actual stream index.&flags,                         // Receives status flags.&llAudioTimeStamp,              // Receives the time stamp.&audioSample                    // Receives the sample or NULL.
            ), "Error reading audio sample.");

        if (flags & MF_SOURCE_READERF_ENDOFSTREAM)
        {
            printf("End of stream.\n");
            break;
        }
        if (flags & MF_SOURCE_READERF_STREAMTICK)
        {
            printf("Stream tick.\n");
            pSinkWriter->SendStreamTick(0, llAudioTimeStamp);
        }

        if (!audioSample)
        {
            printf("Null audio sample.\n");
        }
        else
        {
            CHECK_HR(audioSample->SetSampleTime(llAudioTimeStamp), "Error setting the audio sample time.\n");

            CHECK_HR(pSinkWriter->WriteSample(0, audioSample), "The stream sink writer was not happy with the sample.\n");
        }
    }

done:

    printf("finished.\n");
    getchar();

    return 0;
}

I've omitted the code that dumps the media types for brevity but their output is shown below. It could well be that I haven't got the media types connected properly.

File Media Type:
Audio: MAJOR_TYPE=Audio, PREFER_WAVEFORMATEX=1, {BFBABE79-7434-4D1C-94F0-72A3B9E17188}=0, {7632F0E6-9538-4D61-ACDA-EA29C8C14456}=0, SUBTYPE={00001610-0000-0010-8000-00AA00389B71}, NUM_CHANNELS=2, SAMPLES_PER_SECOND=22050, BLOCK_ALIGNMENT=1, AVG_BYTES_PER_SECOND=8000, BITS_PER_SAMPLE=16, USER_DATA=<BLOB>, {73D1072D-1870-4174-A063-29FF4FF6C11E}={05589F81-C356-11CE-BF01-00AA0055595A}, ALL_SAMPLES_INDEPENDENT=1, FIXED_SIZE_SAMPLES=1, SAMPLE_SIZE=1, MPEG4_SAMPLE_DESCRIPTION=<BLOB>, MPEG4_CURRENT_SAMPLE_ENTRY=0, AVG_BITRATE=64000, 

Source Reader Output Type:
Audio: MAJOR_TYPE=Audio, SUBTYPE=Float, 

Sink Media Type:
Audio: MAJOR_TYPE=Audio, SUBTYPE=Float, NUM_CHANNELS=2, SAMPLES_PER_SECOND=48000, BLOCK_ALIGNMENT=8, AVG_BYTES_PER_SECOND=384000, BITS_PER_SAMPLE=32, ALL_SAMPLES_INDEPENDENT=1, CHANNEL_MASK=3, 

Any hints as to where I could look next would be appreciated.


FLAC metadata/tags being read incorrectly in Windows Media Player on Windows 10

$
0
0

I recently converted my lossless music to FLAC now that Windows 10 supports it natively. But when viewing these FLAC files in Windows Media Player, the year of the songs show up as "unknown year" despite having the year correctly labelled. I've noticed that compared to mp3 files, when you go to the details tab in the properties of a FLAC file, there's an extra tag option called "Date released" below the Year tag which when filled in allows the year to be displayed within WMP, although this is quite a tedious solution.

From what it looks like, WMP isn't able to read the Vorbis tag DATE. There's also a problem with the Artists name not showing up in the contributing artist section, probably for the same reason. I'm not sure how well WMP is able to read the vorbis tagging system but the ability to do so seems to be poorly implemented.

On a side note, there doesn't appear to be any standard windows media player FLAC icon for when WMP is the default media player, instead it uses the M4A file.




IMFTransform::SetInput failing with MF_E_ATTRIBUTENOTFOUND on Windows 8.1

$
0
0

I am trying to configure a IMFTransform instance to convert between YUY2 and RGB24. I can get the pointer to the IMFTransform but attempts to call SetInput always ends with a MF_E_ATTRIBUTENOTFOUND error. This particular error is not documented on MSDN for that method so I'm not clear on what the problem is. I've tried two approaches, manually creating the IMFMediaType to specify and iterating over GetInputAvailableType's results and using the one that was directly provided and both result in a MF_E_ATTRIBUTENOTFOUND error. Is there something that I'm not aware of or not doing with respect the transform? Or is YUY2 to RGB24 somehow impossible? Below is the code relevant to the issue.

MFT_REGISTER_TYPE_INFO inputFormat;
MFT_REGISTER_TYPE_INFO outputFormat;

inputFormat.guidMajorType = MFMediaType_Video;
inputFormat.guidSubtype = MFVideoFormat_YUY2;
outputFormat.guidMajorType = MFMediaType_Video;
outputFormat.guidSubtype = MFVideoFormat_RGB24;

hr = MFTEnumEx(
  MFT_CATEGORY_VIDEO_PROCESSOR,
  MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_LOCALMFT | MFT_ENUM_FLAG_SORTANDFILTER,
  &inputFormat,&outputFormat,&transformFilters,&filterCount);

// Only one transform is found.
transformFilters[0]->ActivateObject(IID_PPV_ARGS(&pTransformer));

// This particular transform has only one stream for both input and output as GetStreamCount returns a not implemented error.
DWORD typeIndex = 0;
do {
  hr = pTransformer->GetInputAvailableType(0, typeIndex, &currentMediaType);
  currentMediaType->GetGUID(MF_MT_SUBTYPE, &mediaSubGUID);
  if (mediaSubGUID == MFVideoFormat_YUY2)
  {
    // This call is always failing with MF_E_ATTRIBUTENOTFOUND
    hr = pTransformer->SetInputType(0, currentMediaType, 0);
    currentMediaType->Release();
    break;
  }
  currentMediaType->Release();++typeIndex;
} while (hr != MF_E_NO_MORE_TYPES);


Windows 10 support for HLS/DASH playback

multichannel support for AAC encoder

$
0
0

Hi,

I'm writing a program using Windows Media Foundation AAC encoder to encode audio. According to documentation here https://msdn.microsoft.com/en-us/library/windows/desktop/dd742785(v=vs.85).aspx 6 channels is supported.

But in my program when I set it to 6, I'll get a MF_E_INVALIDMEIDATYPE error.

Below is my code

CLSID* pCLSIDs = NULL;// Pointer to an array of CLISDs.
UINT32 nCount = 0;
MFT_REGISTER_TYPE_INFO encoderInfo;
encoderInfo.guidMajorType = MFMediaType_Audio; 
encoderInfo.guidSubtype = MFAudioFormat_AAC;// AAC Encoder class id is not exposed, so we have to enumerate     

HRESULT hr = fpMFTEnum(MFT_CATEGORY_AUDIO_ENCODER, 0, NULL, &encoderInfo, NULL, &pCLSIDs, &nCount);
ciEncoder.CreateObject(pCLSIDs[0], IID_IMFTransform);
LComObject<IMFMediaType> ciInputType;  // Input media type of the encoder
hr = fpMFCreateMediaType((IMFMediaType**)(ciInputType.GetAssignablePtrRef()));
hr = ciInputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
hr = ciInputType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
hr = ciInputType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16); // must be 16
hr = ciInputType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, Samplerate);
hr = ciInputType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, Channels); //Must be 1 (mono)or 2 (stereo), or 6 (5.1).
hr = ciEncoder->SetInputType(0, ciInputType.get(), 0);      if (FAILED(hr)) {
   LDEBUG("Failed to set encoder input meida type"); 
   break;     
}

I've removed all error handling code.

ciEncoder->SetInputType will fail if Channels == 6, when Channels == 1 or 2, SetInputType succeeds. It happens on both 32 and 64 bit Win7 Professional.

Thanks for your help


How to create a H.264 Media Type for the AVI File Sink ?

$
0
0

Hi,

it was like 2 years ago when the "MFCreateAVIMediaSink" function popped up. Back then my program needed Windows 7 support so it was out of the question. I tryed the method anyway but had no luck then. Today i am in a different situation as my program now has a minimum requirement of Windows 8.1, so i could make use of the function, so i think lets give it a try.

The video format i want to store in the AVI container is H264. An ordinary media type like the following is working flawless on the ASF and MPEG4 File Sink :

-

MF_MT_MAJOR_TYPE = MFMediaType_Video

MF_MT_SUBTYPE = MFVideoFormat_H264

MF_MT_AVG_BITRATE = 2000000

MF_MT_FRAME_RATE = 60, 1

MF_MT_FRAME_SIZE = 1920, 1080

MF_MT_INTERLACE_MODE = MFVideoInterlace_Progressive

MF_MT_MPEG2_PROFILE = eAVEncH264VProfile_High

MF_MT_PIXEL_ASPECT_RATIO = 1, 1

-

This type and nearly every other Media Type i got to work on other Sinks are rejected. Of course i read into the format and header structure of the AVI format, but i couldnt get it to work. At some point i thought maybe the Microsoft implementation uses DirectShow internally, so i tryed setting several additional attributes like described here under Format Mappings :

-

MF_MT_ALL_SAMPLES_INDEPENDENT = FALSE

MF_MT_FIXED_SIZE_SAMPLES = FALSE

MF_MT_SAMPLE_SIZE = 0

-

The values are exactly as they have to be according to the AM_MEDIA_TYPE documentation. I also tryed setting up a DirectShow Media Type and then use "MFInitMediaTypeFromAMMediaType". Well that the AVI Sink would use DirectShow internally was realy just a guess ...

I think it has something to do with passing the right header structure, maybe a VIDEOINFOHEADER ? I couldnt find any info at all about AVI in the Media Foundation documentation on all classes, attributes and functions. I also searched through everything in DirectShow but still cant get it to work.

Any help is appreciated

Regards

co0Kie


this is not notepc

$
0
0

Hi,

What does error - this is not notepc mean? I have just upgraded to windows 10.

Writing H264 videos larger than 2048x2048?

$
0
0

I used code from the SinkWriter sample to write a H264 MP4 file. That worked well until I tried to go over 2048x2048, at which point I get a MF_E_INVALIDMEDIATYPE error when calling SetInputMediaType on the sink writer. How do I overcome this problem?

I'm running on Windows 8.1 and developing in VS2013.

Here's the code I use to create the sink writer:

	hr = MFCreateSinkWriterFromURL(wfile, NULL, NULL, &m_sinkWriter);

	// Set the output media type
	hr = MFCreateMediaType(&mediaTypeOut);
	hr = mediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
	hr = mediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
	hr = mediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH264VProfile_High); // Default is Base, High requires Windows 8
	hr = mediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, bitrate);
	hr = mediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); // No interlacing
	hr = mediaTypeOut->SetUINT32(MF_MT_DEFAULT_STRIDE, width * 4);
	hr = MFSetAttributeSize(mediaTypeOut, MF_MT_FRAME_SIZE, width, height);
	hr = MFSetAttributeRatio(mediaTypeOut, MF_MT_FRAME_RATE, c_fps, 1);
	hr = MFSetAttributeRatio(mediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
	hr = m_sinkWriter->AddStream(mediaTypeOut, &m_videoStream);

	// Set the input media type
	hr = MFCreateMediaType(&mediaTypeIn);
	hr = mediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
	hr = mediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32);
	hr = mediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive); // No interlacing
	hr = mediaTypeIn->SetUINT32(MF_MT_DEFAULT_STRIDE, width * 4);
	hr = MFSetAttributeSize(mediaTypeIn, MF_MT_FRAME_SIZE, width, height);
	hr = MFSetAttributeRatio(mediaTypeIn, MF_MT_FRAME_RATE, c_fps, 1);
	hr = MFSetAttributeRatio(mediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
	hr = m_sinkWriter->SetInputMediaType(m_videoStream, mediaTypeIn, NULL);

	// Tell the sink writer to start accepting data
	hr = m_sinkWriter->BeginWriting();

Viewing all 1079 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>