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

How can I get the real resolution from the decoder in mft?

$
0
0

I am developing using a media foundation provided by Microsoft.
The mft (media foundation transform) h264 decoder is used.
There is a problem in getting the resolution when decoding hardware using d3d11.

Get resolution value when output stream changes
A stream that is 1920 * 1080 comes out as 1920 * 1088.
I think this part of the hardware decoder has effectively converted to a multiple of 16.

But I need a real resolution value of 1920 * 1080.
Looking through the documentation doesn't seem to tell you how to get the actual resolution in this case.

Is there anyone who can solve the problem?

  hr = mft_->GetInputCurrentType(0, &meida_type);
  CHECK_HR(hr, "mft->SetOutputType failed");

  width = 0, height = 0;
  hr = MFGetAttributeSize(meida_type, MF_MT_FRAME_SIZE, &width, &height);
  CHECK_HR(hr, "MFSetAttributeRatio(MF_MT_FRAME_SIZE) failed");
  meida_type->Release();


Class implements IMFMediaEventGenerator to listen for events in its queue and call its own callback to handle events.

$
0
0

I have a DeviceMFT for video capture in my project. Within DMFT, I have various classes I want to send custom events (like RAW_FRAME_READY etc.. ) between classes . Say ,

- I have ClassA that initiates ClassB and ClassC.

- ClassB wants to send custom event to classA.

- Based on the event, classA calls a method in ClassC.

Am thinking to use ClassA as Media event generator, thereby ClassB , ClassC can queue events. 

ClassA also implements IMFAsyncCallback and whenever any class queues event, ClassA::Invoke() handles the events and calls methods of other interfaces accordingly.

class ClassA: public IMFMediaEventGenerator , public IMFAsyncCallback

ClassA::ClassA

{

 MFCreateEventQueue(&iQueue);

BeginGetEvent(this,NULL); //>>> I want the same interface to listen for events in its queue

}

ClassA::BeginGetEvent()

{

<assume we have a working code here>

}

ClassA::EndGetEvent()

{

<assume we have a working code here>

}

ClassA::QueueEvent()

{

<assume we have a working code here>

}

ClassA::Invoke()

{

// Get callback for events in the queue

HandleEvent();

....

}

Here are my queries 

1) Can i use IMFMediaEventGenerator to queue custom events ? I see that MediaEventType is of DWORD type and I can define my own events.

2) even though ClassB, ClassC generates events, they do not implement IMFMediaEventGenerator. Instead they use ClassA event queue. Is this an acceptable design ?

3) As ClassA implements IMFMediaEventGenerator and IMFAsyncCallback , Can i call BeginGetevent(this,...) in ClassA i.e ClassA will be listening for any events in queue and then call its ::Invoke()



IMFMediaEngine stops unexpectedly

$
0
0

Hello,

I'm using IMFMediaEngine and DirectX11 to build a video player application.
Get the texture (ID3D11Texture2D) using IMFMediaEngine :: TransferVideoFrame.
Display the acquired texture on the screen.

I have one problem.
The conditions are not clear, but if you use this program to run a large size video on a low-spec PC,
the frame will be delayed while the video is playing, and then frame acquisition will stop.
In detail, IMFMediaEngine :: OnVideoStreamTick is S_OK, but no new frame is returned.pPts always returns the time at which it stopped.
Both IMFMediaEngine :: IsEnded and IMFMediaEngine :: IsPaused return false.
An error could not be obtained with IMFMediaEngine :: GetError.

The problem was confirmed on a low-spec PC of Windows 10 and Windows 8.1. The function level of each PC is “10_1”.
No problem has been confirmed on PCs with a function level of "11_0" or higher.

If you know how to avoid this problem, please let me know.

This sentence was translated by google translation.
I'm sorry if it was difficult to read.

■Video details
Format: wmv
Playing time: 1 minute 57 seconds
1600x904
30fps
File size: 316MB

■PC where the problem occurs1

ThinkPad X121e Intel 30456GJ
Windows 8.1 Pro 64-bit
DDI Version: 10.1
Feature Levels: 10.1,10.0,9.3,9.2,9.1
Driver Model: WDDM 1.2
Intel(R) HD Graphics 3000

■PC where the problem occurs2
Dell System XPS L702X
Windows 10 Home 64-bit
DDI Version: 11.1
Feature Levels: 10_1,10_0,9_3,9_2,9_1
Driver Model: WDDM 1.2
Intel(R) HD Graphics 3000

Changes in the HEVCVideoExtensions from version 1.0.21822.0 to 1.0.2276.0

$
0
0

Sometime last week, the windows store appears to have pushed an update to the HEVC decoder that has caused our application that uses it to stop playback after 7 minutes.  Media foundation using MFTrace is reporting an OutOfMemory.  Watching using any memory profiler backs and supports this.  Memory keeps climbing until our 32 bit app hits roughly 1.4 gig, then stops.

While testing this theory 2 days ago, I had a working system that would play for hours.  As soon as I installed the HEVCDecoder under an admin account instead of my user account, it updated both, and started failing.

I would simply uninstall the update, but I have not found a way to get an older version of something delivered through the Microsoft Store.

Can we sell the app which use MediaFoundation for H.264 encoding without license fee?

$
0
0
Can we sell the app which use MediaFoundation for H.264 encoding without license fee? My understanding is that license fee for H.264 is paid by Microsoft so we don’ t have responsibility for paying license fee. is it correct?

IMFMediaEngine, frame delay

$
0
0

Hello,

I'm using IMFMediaEngine and DirectX11 to build a video player application.
Get the texture (ID3D11Texture2D) using IMFMediaEngine :: TransferVideoFrame.
Display the acquired texture on the screen.

I have one problem.
When playing a large size video on a low-spec machine, the video frame will be delayed and will not be synchronized with the sound.
Is there a way to avoid the delay?

For confirmation of this issue, I can provide a minimum sample.
thanks.

■Video details
Format: wmv
Playing time: 1 minute 57 seconds
1600x904
30fps
File size: 316MB

■PC where the problem occurs
ThinkPad X121e Intel 30456GJ
Windows 8.1 Pro 64-bit
Processor: Intel(R) Core(TM) i3-2357M CPU @ 1.30GHz (4 CPUs), ~1.3GHz
Memory: 4096MB RAM
resolution:1366x768
DDI Version: 10.1
Feature Levels: 10.1,10.0,9.3,9.2,9.1
Driver Model: WDDM 1.2
Intel(R) HD Graphics 3000

Encoding a D3D Surface obtained through Desktop Duplication using Media Foundation

$
0
0

I want to encode Desktop Duplication API frames to send over the network after encoding them with Media Foundation. I'm stuck with a E_NOTIMPL error when I call IMFTransform::ProcessInput, leaving me a little in the dark.

These are the steps I've done up until now, I'm detailing them because it took me days to gather everything from the scarce scattered info across the web, so if it's resolved it will hopefully help others. Everything below is met with an S_OK:

  • I'm obtaining the surface through Duplication API, creating an IMFSample from it using MFCreateVideoSampleFromSurface
  • I'm getting a video encoder using IMFActivate::ActivateObject from an IMFActivate initialized with MFT_CATEGORY_VIDEO_ENCODER and MFVideoFormat_H264
  • I'm initializing IMFMediaType on the input with bitrate, framerate, aspect ratio, etc.. and most importantly: MFVideoFormat_NV12, seems to be the only one to work with the DXGI_FORMAT_B8G8R8A8_UNORM of Desktop Duplication API.
  • I'm setting IMFMediatype on the output with the same as the above, aside from MFVideoFormat_H264 as SUB_TYPE.
  • I'm calling the IMFTransform::SetOutputType then IMFTransform::SetInputType with the 2 above.
  • I'm setting the IMFSample time at 0 as it seems it's not being set by MFCreateVideaSampleFromSurface. Also setting the SampleDuration with MFFrameRateToAverageTimePerFrame with the input FPS.

After all of this, I call the MFTransform::ProcessInput with the IMFSample created above, and get a "E_NOTIMPL not implemented" as an HRESULT. I've read that I should set an IMFDXGIDeviceManager to my IMFTransform encoder above, so I did that using:

  • MFCreateDXGIDeviceManager from my ID3D11Device used with Desktop Duplication API and an arbitrary reset token.
  • Doing an IMFDXGIDeviceManager::ResetDevice with the device and token.
  • Calling IMFTransform::ProcessMessage(MFT_MESSAGE_SET_D3D_MANAGER, reinterpret_cast(m_pDXDeviceManager).

On this last step I get another "E_NOTIMPL not implemented" on my HRESULT, and that's where I don't know what I'm doing wrong anymore or what needs to be done.

Converting audio using MFT was successful on windows 7 but failed on windows 10

$
0
0
When we implement the conversion of  video with Audio sample rate from 16Khz to 44.1 Khz, there was a problem as follows:

- On windows 7, the program worked successful.
- On Windows 10, the program encountered a bug, the output audio is ran faster than the input audio.

Program details as below:
---------------------------------------
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>

#include <comdef.h>
#include <stdio.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <Mferror.h>
#include <mfplay.h>
#pragma comment(lib, "ole32")
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mfreadwrite")
#pragma comment(lib, "mfuuid")

int main()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = MFStartup(MF_VERSION);

IMFMediaType *pMediaType;
IMFMediaType *pMediaTypeOut;
IMFSourceReader *pSourceReader;
IMFAttributes *pAttributes;
IMFSinkWriter *pSinkWriter;
IMFMediaType *pCurrentMediaType;
LONGLONG nDruration = 412800000;

// Load souce file
hr = MFCreateSourceReaderFromURL(
L"input.mp4",
NULL,
&pSourceReader
);
pSourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_AUDIO_STREAM, TRUE);

// Create a partial media type that specifies uncompressed audio
IMFMediaType *pPartialType;
MFCreateMediaType(&pPartialType);
hr = pPartialType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
hr = pPartialType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
hr = pSourceReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM
, nullptr
, pPartialType);
hr = pSourceReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, &pPartialType);
hr = pSourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_AUDIO_STREAM, TRUE);

// set media type for output file
hr = MFCreateMediaType(&pMediaTypeOut);

// set major type for output file
hr = pMediaTypeOut->SetGUID(
MF_MT_MAJOR_TYPE,
MFMediaType_Audio
);

// Set subtype for output file
hr = pMediaTypeOut->SetGUID(
MF_MT_SUBTYPE,
MFAudioFormat_AAC
);

hr = pMediaTypeOut->SetUINT32(
MF_MT_AUDIO_SAMPLES_PER_SECOND,
44100
);

// set audio number channal for output file
hr = pMediaTypeOut->SetUINT32(
MF_MT_AUDIO_NUM_CHANNELS,
2
);

// set audio bit depth for output file
hr = pMediaTypeOut->SetUINT32(
MF_MT_AUDIO_BITS_PER_SAMPLE,
16
);

hr = pMediaTypeOut->SetUINT32(
MF_MT_AUDIO_AVG_BYTES_PER_SECOND,
12000.5
);

hr = pMediaTypeOut->SetUINT32(
MF_MT_AUDIO_BLOCK_ALIGNMENT,
1
);
pMediaTypeOut->SetUINT32(MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, 0x29);

DWORD nWriterStreamIndex = -1;
hr = MFCreateSinkWriterFromURL(
L"Output.mp4",
NULL,
NULL,
&pSinkWriter
);
hr = pSinkWriter->AddStream(pMediaTypeOut, &nWriterStreamIndex);
hr = pSinkWriter->BeginWriting();

_com_error err(hr);
LPCTSTR errMsg = err.ErrorMessage();

LONGLONG SampleDuration;
//Sets the input format for a stream on the sink writer.
hr = pSinkWriter->SetInputMediaType(nWriterStreamIndex, pPartialType, NULL);

for (;;)
{
DWORD nStreamIndex, nStreamFlags;
LONGLONG nTime;
IMFSample *pSample;

hr = pSourceReader->ReadSample(
MF_SOURCE_READER_FIRST_AUDIO_STREAM,
0,
&nStreamIndex,
&nStreamFlags,
&nTime,
&pSample);
printf("%d\n", nStreamFlags);
printf("%d\n", nTime);

//Update media type, when current media tye changed.
if (nStreamFlags & MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED) {
pSourceReader->GetNativeMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, MF_SOURCE_READER_CURRENT_TYPE_INDEX, &pCurrentMediaType);
pSourceReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM
, nullptr
, pCurrentMediaType);
pSourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_AUDIO_STREAM, TRUE);
continue;
}
pSample->GetSampleDuration(&SampleDuration);

if (nTime >= nDruration)
{
break;
}
// Calculate new timestamp of sample when this sample is written on output file
if (nTime + SampleDuration >= nDruration)
{
SampleDuration = nDruration - nTime;
pSample->SetSampleDuration(SampleDuration);
}
pSample->SetSampleTime(nTime);

if (FAILED(hr)) {
printf("ReadSample Error...\n");
return 0;
}

//write sample
if (pSample)
{
OutputDebugString(L"Write sample...\n");
hr = pSinkWriter->WriteSample(
nWriterStreamIndex,
pSample
);
if (FAILED(hr)) {
printf("WriteSample Error...\n");
return 0;
}
}

if (nStreamFlags & MF_SOURCE_READERF_ENDOFSTREAM)
{
break;
}
}
hr = pSinkWriter->Finalize();
return 0;
}
-------------------------------

When debugging, we detected the following points:
- After running through the IMFSourceReader::ReadSample funtion. On windows 7, the parameter "nStreamFlags" has resulted in 0.On windows 7, the "nStreamFlags" has resulted in "MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED".
- Bug only appear in the input audio format is AAC, with input  audio format is WMA, PCM ... it is not happen.
- When input audio format is AAC, this bug only appear in cases with input audio sample rate is less than 32Khz and converting to 44.1kHz sample rate output.

Q: Can you explain the problem, is there something wrong with the IMFSourceReader::ReadSample funtion?

Someone help to understand encoding in h.264

$
0
0

I use c#, Windows 10.

Please help me understand the sequence of actions.
I have a lot of images in ARGB32 format and I convert them to NV12 with these actions:

1.MFExtern.MFTEnumEx
2. hr = MFExtern.MFCreateMediaType(out mediaOutType);
                hr = mediaOutType.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
                hr = mediaOutType.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, outSubType);
                hr = MFExtern.MFSetAttributeSize(mediaOutType, MFAttributesClsid.MF_MT_FRAME_SIZE, Width, Height);
                hr = MFExtern.MFSetAttributeRatio(mediaOutType, MFAttributesClsid.MF_MT_FRAME_RATE, 1, 1);
                hr = MFExtern.MFSetAttributeRatio(mediaOutType, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
                hr = mediaOutType.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)VideoInterlaceMode.Progressive);
                hr = mediaOutType.SetUINT32(MFAttributesClsid.MF_MT_ALL_SAMPLES_INDEPENDENT, 1);
                hr = retTransform.SetOutputType(0, mediaOutType, 0);
                MFError.ThrowExceptionForHR(hr);

                hr = MFExtern.MFCreateMediaType(out mediaInType);
                hr = mediaInType.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
                hr = mediaInType.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, inSubType);
                hr = MFExtern.MFSetAttributeSize(mediaInType, MFAttributesClsid.MF_MT_FRAME_SIZE, Width, Height);
                hr = MFExtern.MFSetAttributeRatio(mediaInType, MFAttributesClsid.MF_MT_FRAME_RATE, 1, 1);
                hr = MFExtern.MFSetAttributeRatio(mediaInType, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
                //hr = mediaInType.SetUINT32(MFAttributesClsid.MF_MT_DEFAULT_STRIDE, Width * 2);
                hr = mediaIn

Type.SetUINT32(MFAttributesClsid.MF_SA_D3D11_AWARE, 1);
                hr = mediaInType.SetUINT32(MFAttributesClsid.MF_MT_FIXED_SIZE_SAMPLES, 1);
                hr = mediaInType.SetUINT32(MFAttributesClsid.MF_MT_SAMPLE_SIZE, Width * Height * 4 * fps);
                hr = mediaInType.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)VideoInterlaceMode.Progressive);
                hr = mediaInType.SetUINT32(MFAttributesClsid.MF_MT_ALL_SAMPLES_INDEPENDENT, 1);
                hr = retTransform.SetInputType(0, mediaInType, 0);

Everything works without errors, if I do reverse conversion and get ARGB32 I can save it to a file and it is displayed normally

after that, I'm creating an Encoder,
MFExtern.MFTEnumEx(TransformCategoryGuids.VideoDecoder, MFT_EnumFlag.LocalMFT

Output attributes

MF_MT_MAJOR_TYPE, MFMediaType.Video

MF_MT_SUBTYPE, MFMediaType.H264

MF_MT_COMPRESSED, true

MF_MT_AVG_BITRATE, 10000000

MF_MT_FRAME_SIZE, 1440, 900

MF_MT_FRAME_RATE, 15, 1

MF_MT_PIXEL_ASPECT_RATIO, 1, 1

MF_MT_INTERLACE_MODE, (int)VideoInterlaceMode.Progressive

INPUT attributes

MF_MT_MAJOR_TYPE, MFMediaType.Video

MF_MT_SUBTYPE, MFMediaType.NV12

MF_MT_COMPRESSED, 0

MF_MT_FRAME_SIZE, 1440, 900

MF_MT_FRAME_RATE, 15, 1

MF_MT_PIXEL_ASPECT_RATIO, 1, 1

MF_MT_INTERLACE_MODE, (int)VideoInterlaceMode.Progressive

I then transfer the IMFSample in NV12 format to the IMFSample ProcessIntput.

get the result, 1 incoming frame and get 1 outgoing frame, if I write them into the file with the extension .h264 and then play them with the player. The video goes like this, the first frame is normal, the second is completely green, the third is normal, the fourth is again green and so on all the time, and I noticed such a strange thing when I encode in the video I thought every IMFSample on the output should have a different size, depending on the changes, if I give the encoder one and the same picture 1000 times I get the same size each time on GetOutputStreamInfo 2462400. I beg you to help me solve the problem... I'm not asking you to write the code for me, so please describe the correct scheme step by step what to do and why
if I missed anything.


E_UNEXPECTED in MESessionStarted event when topology has two branches

$
0
0

I am working on a session topology that records a video (with audio) while showing the video stream with an EVR. I am using SampleGrabber sinks for the video and audio streams so I can easily control when I start/end recording (using a sinkwriter) and extract sample data as I need to (for capturing stills and displaying the microphone's audio level). I am using a Tee node to split the video feed between the EVR and the video samplegrabber, and a copierMFT to deliver samples to the EVR.

Each branch of the topology work by themselves, but when I add both to the topology the media session fails to start, with a status="E_UNEXPECTED Catastrophic Error" set on the MESessionStarted event. That is the only error I find in the MFTrace logs. My camera never turns on and I don't receive any samples in my samplegrabbers. The topology seems to resolve correctly, so I'm not sure what the session didn't expect. The documentation for MediaSession::Start doesn't mention anything about this error. My current guess is that is has something to do with syncing the presentation clock, but setting the samplegrabber output nodes as rateless doesn't seem to help. After I receive the Topology Ready status event, checking the session's clock state returns MFCLOCK_STATE_INVALID.

Is there any special setup required to have a live camera source and microphone source in the same topology? Is there any way to get more info on the E_UNEXPECTED error?

Any help on getting to the bottom of this is appreciated. Here is a snippet of my mftrace log which shows the ready topology and the error:

12656,14E8 19:25:29.69496 CTopologyHelpers::Trace @02A799F8 >>>>>>>>>>>>> ready topology
12656,14E8 19:25:29.69499 CTopologyHelpers::TraceNode @ Node 0 @02A7A110 ID:317000000001, 0 inputs, 1 outputs, type 1, MF_TOPONODE_MARKIN_HERE=1;MF_TOPONODE_MARKOUT_HERE=1;MF_TOPONODE_MEDIASTART=0 (0,0);MF_TOPONODE_SOURCE=@02A95200;MF_TOPONODE_PRESENTATION_DESCRIPTOR=@02A63820;MF_TOPONODE_STREAM_DESCRIPTOR=@02A662C8;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A85698
12656,14E8 19:25:29.69500 CMFTopologyNodeDetours::GetGUID @02A7A110 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69501 CTopologyHelpers::TraceObject @ Source @02A95200 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MFCORE.DLL), MFMEDIASOURCE_CHARACTERISTICS=0x00000005
12656,14E8 19:25:29.69507 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A7A188 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69509 CTopologyHelpers::TraceNode @ Node 1 @02A7A188 ID:317000000002, 1 inputs, 2 outputs, type 3, MF_TOPONODE_PRIMARYOUTPUT=0;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A7CE00
12656,14E8 19:25:29.69509 CMFTopologyNodeDetours::GetGUID @02A7A188 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69509 CTopologyHelpers::TraceObject @ Tee @00000000 {00000000-0000-0000-0000-000000000000} ((null)), (null)
12656,14E8 19:25:29.69514 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A7A110 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69518 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A79D68 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69522 CTopologyHelpers::TraceStream @ Output stream 1, connected to node @02A7B1F0 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69524 CTopologyHelpers::TraceNode @ Node 2 @02A79D68 ID:317000000005, 1 inputs, 1 outputs, type 2, {89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A85908
12656,14E8 19:25:29.69524 CMFTopologyNodeDetours::GetGUID @02A79D68 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69526 CTopologyHelpers::TraceObject @ MFT @02A6DAE8 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MFCORE.DLL), MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE=1;{851745D5-C3D6-476D-9527-498EF2D10D18}=4
12656,14E8 19:25:29.69531 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A7A188 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69536 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A79EA0 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69538 CTopologyHelpers::TraceNode @ Node 3 @02A79DE0 ID:317000000003, 1 inputs, 0 outputs, type 0, MF_TOPONODE_STREAMID=0;MF_TOPONODE_DISABLE_PREROLL=1;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A85AE0
12656,14E8 19:25:29.69539 CMFTopologyNodeDetours::GetGUID @02A79DE0 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69539 CTopologyHelpers::TraceObject @ Sink @02A6FB28 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MFCORE.DLL), (null)
12656,14E8 19:25:29.69544 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A7B1F0 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=2560;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_GEOMETRIC_APERTURE=00 00 00 00 00 00 00 00 80 02 00 00 e0 01 00 00 ;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=42949672960333333 (10000000,333333);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_SAMPLE_SIZE=1228800;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MFVideoFormat_RGB32
12656,14E8 19:25:29.69546 CTopologyHelpers::TraceNode @ Node 4 @02A7B1F0 ID:31700000000C, 1 inputs, 1 outputs, type 2, MF_TOPONODE_TRANSFORM_OBJECTID={98230571-0087-4204-B020-3282538E57D3};{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A86040
12656,14E8 19:25:29.69546 CTopologyHelpers::TraceObject @ MFT @02A7A488 {98230571-0087-4204-B020-3282538E57D3} (C:\Windows\SYSTEM32\colorcnv.dll), <NULL>
12656,14E8 19:25:29.69551 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A7A188 stream 1, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69556 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A79DE0 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=2560;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_GEOMETRIC_APERTURE=00 00 00 00 00 00 00 00 80 02 00 00 e0 01 00 00 ;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=42949672960333333 (10000000,333333);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_SAMPLE_SIZE=1228800;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MFVideoFormat_RGB32
12656,14E8 19:25:29.69559 CTopologyHelpers::TraceNode @ Node 5 @02A79EA0 ID:317000000004, 1 inputs, 0 outputs, type 0, MF_TOPONODE_STREAMID=0;MF_TOPONODE_NOSHUTDOWN_ON_REMOVE=0;MF_TOPONODE_DISABLE_PREROLL=1;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A86218;{B8AA3129-DFC9-423A-8ACD-1D82850A3D1F}=@02A8B9E0
12656,14E8 19:25:29.69560 CMFTopologyNodeDetours::GetGUID @02A79EA0 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69560 CTopologyHelpers::TraceObject @ Sink @02A8E5D4 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MF.dll), (null)
12656,14E8 19:25:29.69565 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A79D68 stream 0, MT: MF_MT_FRAME_SIZE=2748779069920 (640,480);MF_MT_AVG_BITRATE=147456000;MF_MT_YUV_MATRIX=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_VIDEO_LIGHTING=3;MF_MT_DEFAULT_STRIDE=1280;MF_MT_VIDEO_CHROMA_SITING=6;MF_MT_AM_FORMAT_TYPE=FORMAT_VIDEOINFO2;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_VIDEO_NOMINAL_RANGE=2;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_SAMPLE_SIZE=614400;MF_MT_VIDEO_PRIMARIES=2;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2
12656,14E8 19:25:29.69568 CTopologyHelpers::TraceNode @ Node 6 @02A79F18 ID:317000000006, 0 inputs, 1 outputs, type 1, MF_TOPONODE_MARKIN_HERE=1;MF_TOPONODE_MARKOUT_HERE=1;MF_TOPONODE_MEDIASTART=0 (0,0);MF_TOPONODE_SOURCE=@02A65D40;MF_TOPONODE_PRESENTATION_DESCRIPTOR=@02A63CE8;MF_TOPONODE_STREAM_DESCRIPTOR=@02A63048;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A86370
12656,14E8 19:25:29.69568 CMFTopologyNodeDetours::GetGUID @02A79F18 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69569 CTopologyHelpers::TraceObject @ Source @02A65D40 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MFCORE.DLL), MFMEDIASOURCE_CHARACTERISTICS=0x00000005
12656,14E8 19:25:29.69571 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A7BFA0 stream 0, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=384000;MF_MT_AUDIO_BLOCK_ALIGNMENT=8;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_CHANNEL_MASK=3;MF_MT_AUDIO_SAMPLES_PER_SECOND=48000;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=32;MF_MT_SUBTYPE=MFAudioFormat_Float
12656,14E8 19:25:29.69573 CTopologyHelpers::TraceNode @ Node 7 @02A7BDC0 ID:317000000007, 1 inputs, 0 outputs, type 0, MF_TOPONODE_STREAMID=0;MF_TOPONODE_DISABLE_PREROLL=1;{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02A864E0
12656,14E8 19:25:29.69573 CMFTopologyNodeDetours::GetGUID @02A7BDC0 attribute not found guidKey = MF_TOPONODE_TRANSFORM_OBJECTID
12656,14E8 19:25:29.69574 CTopologyHelpers::TraceObject @ Sink @02A70410 {00000000-0000-0000-0000-000000000000} (C:\WINDOWS\SYSTEM32\MFCORE.DLL), (null)
12656,14E8 19:25:29.69575 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A7BFA0 stream 0, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=88200;MF_MT_AUDIO_BLOCK_ALIGNMENT=2;MF_MT_AUDIO_NUM_CHANNELS=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_CHANNEL_MASK=4;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
12656,14E8 19:25:29.69577 CTopologyHelpers::TraceNode @ Node 8 @02A7BFA0 ID:317000000010, 1 inputs, 1 outputs, type 2, MF_TOPONODE_TRANSFORM_OBJECTID={F447B69E-1884-4A7E-8055-346F74D6EDB3};{89485B85-2FFA-4547-B269-B82C79EE197C}=1;{9C86CC4E-68CE-4CFF-AA1E-9A5A40D5B4E0}=@02AAA068
12656,14E8 19:25:29.69578 CTopologyHelpers::TraceObject @ MFT @02A7C4AC {F447B69E-1884-4A7E-8055-346F74D6EDB3} (C:\Windows\SYSTEM32\resampledmo.dll), <NULL>
12656,14E8 19:25:29.69581 CTopologyHelpers::TraceStream @ Input stream 0, connected to node @02A79F18 stream 0, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=384000;MF_MT_AUDIO_BLOCK_ALIGNMENT=8;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_CHANNEL_MASK=3;MF_MT_AUDIO_SAMPLES_PER_SECOND=48000;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=32;MF_MT_SUBTYPE=MFAudioFormat_Float
12656,14E8 19:25:29.69583 CTopologyHelpers::TraceStream @ Output stream 0, connected to node @02A7BDC0 stream 0, MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=88200;MF_MT_AUDIO_BLOCK_ALIGNMENT=2;MF_MT_AUDIO_NUM_CHANNELS=1;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_PCM
12656,14E8 19:25:29.69584 CTopologyHelpers::Trace @02A799F8 MF_TOPOLOGY_RESOLUTION_STATUS = 0
12656,14E8 19:25:29.69584 CTopologyHelpers::Trace @02A799F8 <<<<<<<<<<<<< ready topology
12656,14E8 19:25:29.69590 CKernel32ExportDetours::OutputDebugStringA @ TOPOLOGY READY 
12656,14E8 19:25:29.69600 CMFTopologyDetours::GetUINT32 @02A799F8 attribute not found guidKey = {9C27891A-ED7A-40E1-88E8-B22727A024EE}
12656,14E8 19:25:29.69612 CMFMediaSessionDetours::EndGetEvent @02A6DDC0 Met=103 MESessionStarted, value (empty), failed HrStatus=8000FFFF E_UNEXPECTED, 


Decoding at lower resolution than full frame

$
0
0

Hi all,

Read this : https://docs.microsoft.com/en-us/windows/win32/medfound/video-quality-management

Did this :

    // Create a new topology.
    IMFTopology *topology = nullptr;
    HRESULT hr = MFCreateTopology(&topology);

       // EXPERIMENTAL: Not currently doing anything.
       HRESULT hr = topology->SetUINT32(MF_TOPOLOGY_STATIC_PLAYBACK_OPTIMIZATIONS, TRUE);
       hr = MFSetAttributeSize(topology, MF_TOPOLOGY_PLAYBACK_MAX_DIMS, 64, 64);
 
      // Rest of topology build code ...


In something derived from the MFPlayer app sample code.

At stated, video continues to render full resolution. looking for ways I can reduce load on low end systems.

Input welcome if it's possible to achieve this.

Cheers,
Steve

Transcode asf file with MJPG codec to mp4/avi

$
0
0

I've been trying to transcode an asf video clip with MJPG codec to mp4 or avi.

I'm getting an error saying "The operation failed because no samples were processed by the sink".

I tried the sample code from  Win7Samples/multimedia/mediafoundation/Transcode and MFCopy. Both failed with the same error

I've set the output video sub type as MFVideoFormat_H264 and the container as MFTranscodeContainerType_ASF.

Could anyone please point me in the right direction on how to convert an asf file with mjpg codec info to mp4/avi?



Intel graphics hardware H264 MFT ProcessInput call fails after feeding few input samples, the same works fine with Nvidia hardware MFT

$
0
0

I'm capturing the desktop using DesktopDuplication API and converting the samples from RGBA to NV12 in GPU and feeding the same to MediaFoundation hardware H264 MFT. This works fine with Nvidia graphics, and also with software encoders but fails when only intel graphics hardware MFT is available. The code works fine on the same intel graphics machine if I fallback to Software MFT. I also have ensured that the encoding is actually done in hardware on Nvidia graphics machines.

On Intel graphics MFT, I'm getting the error code "The callee is currently not accepting further input" all the time, and sometimes, MFT returns MEError ("Unspecified error"). Mostly this problem occurs immediately after the first sample has been fed to the encoder (through ProcessInput), it's rare that MFT consumes few more samples before returning this error. This behavior is confusing, I'm feeding a sample only when the event generator triggers METransformNeedInput asynchronously through IMFAsyncCallback, and also checking properly whether METransformHaveOutput is triggered as soon as a sample is fed. This really baffles me when the same asynchronous logic works fine with Nvidia hardware MFT & Microsoft software encoders.

Method to set d3d manager:

void SetD3dManager() {

    HRESULT hr = S_OK;

    if (!deviceManager) {

        // Create device manager
        hr = MFCreateDXGIDeviceManager(&resetToken, &deviceManager);
    }

    if (SUCCEEDED(hr)) 
    {
        if (!pD3dDevice) {

            pD3dDevice = GetDeviceDirect3D(0);
        }
    }

    if (pD3dDevice) {

        // NOTE: Getting ready for multi-threaded operation
        const CComQIPtr<ID3D10Multithread> pMultithread = pD3dDevice;
        pMultithread->SetMultithreadProtected(TRUE);

        hr = deviceManager->ResetDevice(pD3dDevice, resetToken);
        CHECK_HR(_pTransform->ProcessMessage(MFT_MESSAGE_SET_D3D_MANAGER, reinterpret_cast<ULONG_PTR>(deviceManager.p)), "Failed to set device manager.");
    }
    else {
        cout << "Failed to get d3d device";
    }
}

Getd3ddevice:

CComPtr<ID3D11Device> GetDeviceDirect3D(UINT idxVideoAdapter)
{
    // Create DXGI factory:
    CComPtr<IDXGIFactory1> dxgiFactory;
    DXGI_ADAPTER_DESC1 dxgiAdapterDesc;

    // Direct3D feature level codes and names:

    struct KeyValPair { int code; const char* name; };

    const KeyValPair d3dFLevelNames[] =
    {
        KeyValPair{ D3D_FEATURE_LEVEL_9_1, "Direct3D 9.1" },
        KeyValPair{ D3D_FEATURE_LEVEL_9_2, "Direct3D 9.2" },
        KeyValPair{ D3D_FEATURE_LEVEL_9_3, "Direct3D 9.3" },
        KeyValPair{ D3D_FEATURE_LEVEL_10_0, "Direct3D 10.0" },
        KeyValPair{ D3D_FEATURE_LEVEL_10_1, "Direct3D 10.1" },
        KeyValPair{ D3D_FEATURE_LEVEL_11_0, "Direct3D 11.0" },
        KeyValPair{ D3D_FEATURE_LEVEL_11_1, "Direct3D 11.1" },
    };

    // Feature levels for Direct3D support
    const D3D_FEATURE_LEVEL d3dFeatureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3,
        D3D_FEATURE_LEVEL_9_2,
        D3D_FEATURE_LEVEL_9_1,
    };

    constexpr auto nFeatLevels = static_cast<UINT> ((sizeof d3dFeatureLevels) / sizeof(D3D_FEATURE_LEVEL));

    CComPtr<IDXGIAdapter1> dxgiAdapter;
    D3D_FEATURE_LEVEL featLevelCodeSuccess;
    CComPtr<ID3D11Device> d3dDx11Device;

    std::wstring_convert<std::codecvt_utf8<wchar_t>> transcoder;

    HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
    CHECK_HR(hr, "Failed to create DXGI factory");

    // Get a video adapter:
    dxgiFactory->EnumAdapters1(idxVideoAdapter, &dxgiAdapter);

    // Get video adapter description:
    dxgiAdapter->GetDesc1(&dxgiAdapterDesc);

    CHECK_HR(hr, "Failed to retrieve DXGI video adapter description");

    std::cout << "Selected DXGI video adapter is \'"<< transcoder.to_bytes(dxgiAdapterDesc.Description) << '\'' << std::endl;

    // Create Direct3D device:
    hr = D3D11CreateDevice(
        dxgiAdapter,
        D3D_DRIVER_TYPE_UNKNOWN,
        nullptr,
        (0 * D3D11_CREATE_DEVICE_SINGLETHREADED) | D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
        d3dFeatureLevels,
        nFeatLevels,
        D3D11_SDK_VERSION,
        &d3dDx11Device,&featLevelCodeSuccess,
        nullptr
    );

    // Might have failed for lack of Direct3D 11.1 runtime:
    if (hr == E_INVALIDARG)
    {
        // Try again without Direct3D 11.1:
        hr = D3D11CreateDevice(
            dxgiAdapter,
            D3D_DRIVER_TYPE_UNKNOWN,
            nullptr,
            (0 * D3D11_CREATE_DEVICE_SINGLETHREADED) | D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
            d3dFeatureLevels + 1,
            nFeatLevels - 1,
            D3D11_SDK_VERSION,&d3dDx11Device,&featLevelCodeSuccess,
            nullptr
        );
    }

    // Get name of Direct3D feature level that succeeded upon device creation:
    std::cout << "Hardware device supports " << std::find_if(
        d3dFLevelNames,
        d3dFLevelNames + nFeatLevels,
        [featLevelCodeSuccess](const KeyValPair& entry)
        {
            return entry.code == featLevelCodeSuccess;
        }
    )->name << std::endl;

done:

    return d3dDx11Device;
}
Async callback implementation:
struct EncoderCallbacks : IMFAsyncCallback
{
    EncoderCallbacks(IMFTransform* encoder)
    {
        TickEvent = CreateEvent(0, FALSE, FALSE, 0);
        _pEncoder = encoder;
    }

    ~EncoderCallbacks()
    {
        eventGen = nullptr;
        CloseHandle(TickEvent);
    }

    bool Initialize() {

        _pEncoder->QueryInterface(IID_PPV_ARGS(&eventGen));

        if (eventGen) {

            eventGen->BeginGetEvent(this, 0);
            return true;
        }

        return false;
    }

    // dummy IUnknown impl
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override { return E_NOTIMPL; }
    virtual ULONG STDMETHODCALLTYPE AddRef(void) override { return 1; }
    virtual ULONG STDMETHODCALLTYPE Release(void) override { return 1; }

    virtual HRESULT STDMETHODCALLTYPE GetParameters(DWORD* pdwFlags, DWORD* pdwQueue) override
    {
        // we return immediately and don't do anything except signaling another thread
        *pdwFlags = MFASYNC_SIGNAL_CALLBACK;
        *pdwQueue = MFASYNC_CALLBACK_QUEUE_IO;
        return S_OK;
    }

    virtual HRESULT STDMETHODCALLTYPE Invoke(IMFAsyncResult* pAsyncResult) override
    {
        IMFMediaEvent* event = 0;
        eventGen->EndGetEvent(pAsyncResult, &event);
        if (event)
        {
            MediaEventType type;
            event->GetType(&type);
            switch (type)
            {
            case METransformNeedInput: InterlockedIncrement(&NeedsInput); break;
            case METransformHaveOutput: InterlockedIncrement(&HasOutput); break;
            }
            event->Release();
            SetEvent(TickEvent);
        }

        eventGen->BeginGetEvent(this, 0);
        return S_OK;
    }

    CComQIPtr<IMFMediaEventGenerator> eventGen = nullptr;
    HANDLE TickEvent;
    IMFTransform* _pEncoder = nullptr;

    unsigned int NeedsInput = 0;
    unsigned int HasOutput = 0;
};
Generate Sample method:
bool GenerateSampleAsync() {

    DWORD processOutputStatus = 0;
    HRESULT mftProcessOutput = S_OK;
    bool frameSent = false;

    // Create sample
    CComPtr<IMFSample> currentVideoSample = nullptr;

    MFT_OUTPUT_STREAM_INFO StreamInfo;

    // wait for any callback to come in
    WaitForSingleObject(_pEventCallback->TickEvent, INFINITE);

    while (_pEventCallback->NeedsInput) {

        if (!currentVideoSample) {

            (pDesktopDuplication)->releaseBuffer();
            (pDesktopDuplication)->cleanUpCurrentFrameObjects();

            bool bTimeout = false;

            if (pDesktopDuplication->GetCurrentFrameAsVideoSample((void**)& currentVideoSample, waitTime, bTimeout, deviceRect, deviceRect.Width(), deviceRect.Height())) {

                prevVideoSample = currentVideoSample;
            }
            // Feed the previous sample to the encoder in case of no update in display
            else {
                currentVideoSample = prevVideoSample;
            }
        }

        if (currentVideoSample)
        {
            InterlockedDecrement(&_pEventCallback->NeedsInput);
            _frameCount++;

            CHECK_HR(currentVideoSample->SetSampleTime(mTimeStamp), "Error setting the video sample time.");
            CHECK_HR(currentVideoSample->SetSampleDuration(VIDEO_FRAME_DURATION), "Error getting video sample duration.");

            CHECK_HR(_pTransform->ProcessInput(inputStreamID, currentVideoSample, 0), "The resampler H264 ProcessInput call failed.");

            mTimeStamp += VIDEO_FRAME_DURATION;
        }
    }

    while (_pEventCallback->HasOutput) {

        CComPtr<IMFSample> mftOutSample = nullptr;
        CComPtr<IMFMediaBuffer> pOutMediaBuffer = nullptr;

        InterlockedDecrement(&_pEventCallback->HasOutput);

        CHECK_HR(_pTransform->GetOutputStreamInfo(outputStreamID, &StreamInfo), "Failed to get output stream info from H264 MFT.");

        CHECK_HR(MFCreateSample(&mftOutSample), "Failed to create MF sample.");
        CHECK_HR(MFCreateMemoryBuffer(StreamInfo.cbSize, &pOutMediaBuffer), "Failed to create memory buffer.");
        CHECK_HR(mftOutSample->AddBuffer(pOutMediaBuffer), "Failed to add sample to buffer.");

        MFT_OUTPUT_DATA_BUFFER _outputDataBuffer;
        memset(&_outputDataBuffer, 0, sizeof _outputDataBuffer);
        _outputDataBuffer.dwStreamID = outputStreamID;
        _outputDataBuffer.dwStatus = 0;
        _outputDataBuffer.pEvents = nullptr;
        _outputDataBuffer.pSample = mftOutSample;

        mftProcessOutput = _pTransform->ProcessOutput(0, 1, &_outputDataBuffer, &processOutputStatus);

        if (mftProcessOutput != MF_E_TRANSFORM_NEED_MORE_INPUT)
        {
            if (_outputDataBuffer.pSample) {

                CComPtr<IMFMediaBuffer> buf = NULL;
                DWORD bufLength;
                CHECK_HR(_outputDataBuffer.pSample->ConvertToContiguousBuffer(&buf), "ConvertToContiguousBuffer failed.");

                if (buf) {

                    CHECK_HR(buf->GetCurrentLength(&bufLength), "Get buffer length failed.");
                    BYTE* rawBuffer = NULL;

                    fFrameSize = bufLength;
                    fDurationInMicroseconds = 0;
                    gettimeofday(&fPresentationTime, NULL);

                    buf->Lock(&rawBuffer, NULL, NULL);
                    memmove(fTo, rawBuffer, fFrameSize > fMaxSize ? fMaxSize : fFrameSize);

                    bytesTransfered += bufLength;

                    FramedSource::afterGetting(this);

                    buf->Unlock();

                    frameSent = true;
                }
            }

            if (_outputDataBuffer.pEvents)
                _outputDataBuffer.pEvents->Release();
        }
        else if (MF_E_TRANSFORM_STREAM_CHANGE == mftProcessOutput) {

            // some encoders want to renegotiate the output format. 
            if (_outputDataBuffer.dwStatus & MFT_OUTPUT_DATA_BUFFER_FORMAT_CHANGE)
            {
                CComPtr<IMFMediaType> pNewOutputMediaType = nullptr;
                HRESULT res = _pTransform->GetOutputAvailableType(outputStreamID, 1, &pNewOutputMediaType);

                res = _pTransform->SetOutputType(0, pNewOutputMediaType, 0);//setting the type again
                CHECK_HR(res, "Failed to set output type during stream change");
            }
        }
        else {
            HandleFailure();
        }
    }

    return frameSent;
}
Create video sample & color conversion:
bool GetCurrentFrameAsVideoSample(void **videoSample, int waitTime, bool &isTimeout, CRect &deviceRect, int surfaceWidth, int surfaceHeight)
{

FRAME_DATA currentFrameData;

m_LastErrorCode = m_DuplicationManager.GetFrame(&currentFrameData, waitTime, &isTimeout);

if (!isTimeout && SUCCEEDED(m_LastErrorCode)) {

    m_CurrentFrameTexture = currentFrameData.Frame;

    if (!pDstTexture) {

        D3D11_TEXTURE2D_DESC desc;
        ZeroMemory(&desc, sizeof(D3D11_TEXTURE2D_DESC));

        desc.Format = DXGI_FORMAT_NV12;
        desc.Width = surfaceWidth;
        desc.Height = surfaceHeight;
        desc.MipLevels = 1;
        desc.ArraySize = 1;
        desc.SampleDesc.Count = 1;
        desc.CPUAccessFlags = 0;
        desc.Usage = D3D11_USAGE_DEFAULT;
        desc.BindFlags = D3D11_BIND_RENDER_TARGET;

        m_LastErrorCode = m_Id3d11Device->CreateTexture2D(&desc, NULL, &pDstTexture);
    }

    if (m_CurrentFrameTexture && pDstTexture) {

        // Copy diff area texels to new temp texture
        //m_Id3d11DeviceContext->CopySubresourceRegion(pNewTexture, D3D11CalcSubresource(0, 0, 1), 0, 0, 0, m_CurrentFrameTexture, 0, NULL);

        HRESULT hr = pColorConv->Convert(m_CurrentFrameTexture, pDstTexture);

        if (SUCCEEDED(hr)) { 

            CComPtr<IMFMediaBuffer> pMediaBuffer = nullptr;

            MFCreateDXGISurfaceBuffer(__uuidof(ID3D11Texture2D), pDstTexture, 0, FALSE, (IMFMediaBuffer**)&pMediaBuffer);

            if (pMediaBuffer) {

                CComPtr<IMF2DBuffer> p2DBuffer = NULL;
                DWORD length = 0;
                (((IMFMediaBuffer*)pMediaBuffer))->QueryInterface(__uuidof(IMF2DBuffer), reinterpret_cast<void**>(&p2DBuffer));
                p2DBuffer->GetContiguousLength(&length);
                (((IMFMediaBuffer*)pMediaBuffer))->SetCurrentLength(length);

                //MFCreateVideoSampleFromSurface(NULL, (IMFSample**)videoSample);
                MFCreateSample((IMFSample * *)videoSample);

                if (videoSample) {

                    (*((IMFSample **)videoSample))->AddBuffer((((IMFMediaBuffer*)pMediaBuffer)));
                }

                return true;
            }
        }
    }
}

return false;
}

Only the TransformNeedInput event is getting triggered all the time yet the encoder complains that it couldn't accept any more input. TransformHaveOutput event has never been triggered.

I have tried to mock just the input source (By programmatically creating an animating rectangle NV12 sample) leaving everything else untouched. This time, the intel encoder doesn't complain anything, I have even got output samples. Except the fact that the output video of intel encoder is distorted whereas Nvidia encoder works perfectly fine.

Furthermore, I'm still getting the ProcessInput error for my original NV12 source with intel encoder. I have no issues with Nvidia MFT and software encoders.

Adding media information like title to mp4 file via SinkWriter

$
0
0

Hi,

I'm using the SinkWriter example from docs.microsoft.com/en-us/windows/win32/medfound/tutorial--using-the-sink-writer-to-encode-video. I would like to add a title to the mp4 file generated similar to the following.

_bstr_t strTitle =L"dksldk";

CComPtr<IWMHeaderInfo> pHeaderInfo;
ComCheck(m_pWriter->QueryInterface( IID_IWMHeaderInfo, (void**)&pHeaderInfo ));
ComCheck(pHeaderInfo->SetAttribute( 0,  g_wszWMTitle, 
WMT_TYPE_STRING, (BYTE*)(wchar_t *)strTitle, 2*(strTitle.length()+1)));

Could someone please help me with this?

Regards,

Shyamala

H264 decoder does not give output with high quality frames

$
0
0

Hi,

We are developing an application to stream H264 frames from a camera using Media Topology. The media pipeline is as follows,

                                                 Camera Source --> H264 decoder --> EVRPresenter

We separately have an extension unit for the camera to control the quality of H264 data. The decoder does not provide any output and the frames are discarded when the stream is started with high detailed scene with high H264 quality set in the extension unit. When we reduce the H264 quality with the extension unit, the size of the frames gets reduced and eventually the decoder provides the output and the rendering starts. Also, the decoder provides the output when the scene is not of much details, even though the H264 quality is set at the maximum. The resolution we are facing this issue is 1920*1080.

These things state that the decoder is not capable of handling big amount of data. If this is the case, is there any limitation for the data size the decoder can handle (or) any other suggestions?


Disable Video Auto-processing with EVR

$
0
0
My program uses Media Foundation to play video. It uses a Media Foundation session, topology, media source and the Enhanced Video Renderer (EVR) to play video in a window, as described in "How to Play Media Files with Media Foundation" in the docs. It works great except for one issue.

Unless the user changes the default graphics driver settings, some graphics drivers automatically introduce additional video processing, such as "contrast enhancement" and "skin tone mapping." While this processing might be desirable in some programs, my program is a video editor used for color grading so it is essential that these effects be disabled. This Microsoft note describes one way of disabling these effects:

"Windows 8 tries to provide a consistent, high-quality video experience across devices (desktop and portable computers, tablet devices, and other devices). This is achieved by disabling auto-processing in the video driver by using the VideoProcessorSetStreamAutoProcessingMode method when the DX11 Video Processor is initialized. This makes sure of a consistent video playback experience and also consistent battery life expectations across Windows 8 devices and Microsoft Store apps.

Note Applications that depend on DX9 (for example, Windows Media Player) are not affected by this design and will continue to operate with auto-processing turned on."

I have experimented with the DX11 Video Processor and it does seem that these effects can be enabled and disabled using the VideoProcessorSetStreamAutoProcessingMode function as described. However, I'm not sure what to do about the EVR, which I believe might be DX9 based.

My question is how to disable video auto-processing using Media Foundation to play video with the EVR?

I have looked for a way to configure the EVR to use DX11. I have looked through all the interfaces and services retrievable from Media Foundation sessions that might be used to disable auto-processing. I have looked at Microsoft's DX11VideoRenderer sample code to see if it might be used instead of the EVR but it does not support all the Media Foundation features my program uses.

I notice that the Windows Movies & TV application is able to play video without auto-processing so hold out hope that this is possible.

Redirected audio streams faster than associated video resulting in unwanted large decoded buffer build up

$
0
0

Hi all,

     I've worked from WavSink samp
le code which emits a decoded audio bytestream in chunks.

Rather than save to a fi
le as per the sample's original purpose, I direct the PCM stream at an audio engine (FMOD).

The audio engine consumes buffers at rea
l-time rate as it plays, however WavSink sends buffers way ahead of when they're required resulting on alarge buildup of decoded buffers that aren't yet needed and so are consuming excess amounts of memory.

I've tried various approaches to manage the Media &
Stream Sink output but can't get it quite right.

My most successfu
l does halt the audio stream intermittantly to 'hold it back', with a release to continue when I want more data, but this results in video glitching.

I tried creating a seperate c
lock for the audio to attempt to decouple it to address this. Got that working but it doesn't resolve the glitch.

Best I've got so far is to queue up  IMFSample instances at stream Output, but that just pushes the buffer buildup further back - they're still there.

Wanting a way to ask the audio Stream/Sink to stop sending me more data for a while when I have enough, then ask it to continue when I want some more without causing the video to glitch.

Does anyone know how to achieve this, p
lease.

Cheers,
Steve.



Media foundation multiple videos playback results in memory-leak & crash after undefined timeframe

$
0
0

So we are using a stack consisting of c++ media foundation code in order to playback video files. An important requirement is the ability to play these videos in constantly repeating sequences, so every single video slot will periodically change the video it is playing. In our current example we are creating 16 HWNDs to render video into and 16 corresponding player objects. The main application loops over all of them one after another and does the following:

Shutdown the last player
Release the object
CoCreateinstance for a new player
Initialize the player with the (old) HWND
Start Playback

The media player is called "MediaPlayer2", this needs to be built and registered as COM (regsvr32). The main application is to be found in the TAPlayer2 Project. It searches for the CLSID of the player in the registry and instantiates it. As current test file we use a test.mp4 that has to reside on the disk like C:\test.mp4

Now everything goes fine initially. The program loops through the players and the video keeps restarting and playing. The memory footprint is normal and all goes smooth. After a timeframe of anything between 20 minutes and 4 days, all of the sudden things will get weird. At this point it seems as if calls to "InitializeRenderer" by the EVR slow down and eventually don't go through anymore at all. With this, also thread count and memory footprint will start to increase drastically and after a certain amount of time depending on existing RAM all the memory will be exhausted and our application crashes, usually somewhere in the GPU driver or near the EVR DLL.


I am happy to try out any other code examples that propose to solve my issue: displaying multiple video windows at the same time, and looping through them like in a playlist. Needs to be running on Windows 10!

I have been going at this for quite a while now and am pretty hard stuck. I uploaded the above mentioned code example and added the link to this post. This should work out of the box afaik. I can also provide code excerpts in here in the thread if that is preferred.

Any help is appreciated, thanks

Thomas

filebin_net_93f7v00a6gtul3ih ( replace "_" with "." and "/", I cannot yet post links in here)


Try RAW Decode h.264 IMFSample

$
0
0

HI All

I use windows 10 x64. c# http://mfnet.sourceforge.net/

I described the H.264 encoder, I get the IMFSample output with frames, which I immediately send to the Microsoft Microsoft H264 Video Decoder MFT Software Decoder for verification. All the IMFSample that I send are received by the system well, but I haven’t received the long-awaited SampleReady on it, I waited and 20 and 30 seconds.

Below settings Output transform settings:

LastError = MFExtern.MFCreateMediaType(out mediaTypeOut);

LastError = mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);

LastError = mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.H264);
LastError = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_AVG_BITRATE, profileInfo.Bitrate);
LastError = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_MPEG2_PROFILE, profileInfo.Profile);
LastError = MFExtern.MFSetAttributeSize(mediaTypeOut, MFAttributesClsid.MF_MT_FRAME_SIZE, Width, Height);
LastError = MFExtern.MFSetAttributeRatio(mediaTypeOut, MFAttributesClsid.MF_MT_FRAME_RATE, 15, 1);
LastError = MFExtern.MFSetAttributeRatio(mediaTypeOut, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
LastError = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (uint)MFVideoInterlaceMode.Progressive);
LastError = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_ALL_SAMPLES_INDEPENDENT, 1u);
LastError = retTransform.SetOutputType(0, mediaTypeOut, MFTSetTypeFlags.None);

I copy the settings and transfer them to the Decoder’s Input MediaType

And Output MediaType for decoder

_lasterror = _transform.GetOutputAvailableType(0, 0, out IMFMediaType ppType);
_lasterror = MFExtern.MFCreateMediaType(out IMFMediaType mediaOutType);
_lasterror = mediaOutType.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
_lasterror = mediaOutType.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.NV12);
_lasterror = mediaOutType.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (uint)MFVideoInterlaceMode.Progressive);
_lasterror = MFExtern.MFSetAttributeRatio(mediaOutType, MFAttributesClsid.MF_MT_FRAME_RATE, 15, 1);
_lasterror = MFExtern.MFSetAttributeRatio(mediaOutType, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
_lasterror = MFExtern.MFSetAttributeSize(mediaOutType, MFAttributesClsid.MF_MT_FRAME_SIZE, Width, Height);
_lasterror = mediaOutType.SetUINT32(MFAttributesClsid.MF_MT_AVG_BITRATE, profileInfo.Bitrate);
_lasterror = mediaOutType.SetUINT32(MFAttributesClsid.MF_MT_ALL_SAMPLES_INDEPENDENT, 1u);
_lasterror = retTransform.SetOutputType(0, mediaOutType, MFTSetTypeFlags.None);

But nothing happens, decoding does not work. If you write the resulting IMFSample to a file in h264 format, then you can watch it as a regular video.

Tell me what I'm missing or if there is not enough code, I can lay out more.

Encoding PCM audio to an MP4/avi file

$
0
0

Hi,

I'm trying to encode audio into an mp4/avi file using sinkwriter. 

I've used the example from /social.msdn.microsoft.com/Forums/windowsdesktop/en-US/55e14d46-053e-4cd5-b069-adfa4cd60207/sinkwriter-and-audio-encoding?forum=mediafoundationdevelopment for this purpose.

My input audio details are

const UINT32 SAMPLES_PER_SECOND = 8000;

const UINT32 NUM_CHANNELS = 1;
const UINT32 BITS_PER_SAMPLE = 16;
const UINT32 BLOCK_ALIGNMENT = BITS_PER_SAMPLE / 8 * NUM_CHANNELS;
const UINT32 ONE_SECOND = 10; // number of buffers per second  
const UINT32 AVG_BYTES_PER_SECOND = BITS_PER_SAMPLE / 8 * NUM_CHANNELS * SAMPLES_PER_SECOND;

hr = MFCreateSinkWriterFromURL(L"outputPCM.avi", NULL, NULL, &pSinkWriter);
////audio stream settings
CHECK_HR(MFCreateMediaType(&spMFTypeOut));
CHECK_HR(spMFTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio));
CHECK_HR(spMFTypeOut->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_MPEG));
CHECK_HR(spMFTypeOut->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, BITS_PER_SAMPLE));
UINT32 samplePerSec = 32000;
CHECK_HR(spMFTypeOut->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, SAMPLES_PER_SECOND));
CHECK_HR(spMFTypeOut->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, NUM_CHANNELS));
    CHECK_HR(spMFTypeOut->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, AVG_BYTES_PER_SECOND));

CHECK_HR(spMFTypeOut->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, BLOCK_ALIGNMENT));
CHECK_HR(pSinkWriter->AddStream(spMFTypeOut, &sindex));

CHECK_HR(MFCreateMediaType(&spMFTypeIn));
CHECK_HR(spMFTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio));
CHECK_HR(spMFTypeIn->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, BITS_PER_SAMPLE));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, SAMPLES_PER_SECOND));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, NUM_CHANNELS));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, BLOCK_ALIGNMENT));
CHECK_HR(spMFTypeIn->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, AVG_BYTES_PER_SECOND));

CHECK_HR(pSinkWriter->SetInputMediaType(sindex, spMFTypeIn, NULL));<-Fails here


I've tried MFAudioFormat_MPEG with 8000 but it fails with error "The data specified for the media type is invalid, inconsistent, or not supported by this object"

I'm not able to find an encoder that would take a sample rate of 8000.

Could anyone please help me with this?

Regards,

Shyamala

Viewing all 1079 articles
Browse latest View live


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