3
我试图在Windows Phone 8.1中使用Media Foundation库和接收器编码器对视频进行编码。Windows Phone 8.1媒体基金会H264最高分辨率
我已经能够通过我的媒体输出设置MFVideoFormat_H264
为MF_MT_SUBTYPE
和使用像720p和480p的分辨率达到这个..
但是,当我更改分辨率1920×1080(1920×1088或)我得到一个错误Incorrect Parameter
。所以我想我的H.264编解码器的最大分辨率是1280x720。
我试着将编解码器更改为HVEC或MPEG2等......但没有运气。
这是CPP代码,我设置输出类型和它添加到流:
// Setup the output video type
ComPtr<IMFMediaType> spvideoTypeOut;
CHK(MFCreateMediaType(&spvideoTypeOut));
CHK(spvideoTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
GUID _vformat = MFVideoFormat_H264;
CHK(spvideoTypeOut->SetGUID(MF_MT_SUBTYPE, _vformat));
CHK(spvideoTypeOut->SetUINT32(MF_MT_AVG_BITRATE, _bitrate));
CHK(spvideoTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
CHK(MFSetAttributeSize(spvideoTypeOut.Get(), MF_MT_FRAME_SIZE, _width, _height));
CHK(MFSetAttributeRatio(spvideoTypeOut.Get(), MF_MT_FRAME_RATE, framerate, 1));
CHK(MFSetAttributeRatio(spvideoTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, ASPECT_NUM, ASPECT_DENOM));
CHK(_spSinkWriter->AddStream(spvideoTypeOut.Get(), &_streamIndex));
而这正是我设置输入类型:
// Setup the input video type
ComPtr<IMFMediaType> spvideoTypeIn;
CHK(MFCreateMediaType(&spvideoTypeIn));
CHK(spvideoTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
CHK(spvideoTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32));
CHK(spvideoTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
CHK(MFSetAttributeSize(spvideoTypeIn.Get(), MF_MT_FRAME_SIZE, _width, _height));
CHK(MFSetAttributeRatio(spvideoTypeIn.Get(), MF_MT_FRAME_RATE, framerate, 1));
CHK(MFSetAttributeRatio(spvideoTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, ASPECT_NUM, ASPECT_DENOM));
CHK(_spSinkWriter->SetInputMediaType(_streamIndex, spvideoTypeIn.Get(), nullptr));
CHK(_spSinkWriter->BeginWriting());
要添加样本下沉作家我使用这个功能,而这正是发生异常:
void PictureWriter::AddFrame(const Platform::Array<uint8>^ videoFrameBuffer, int imageWidth, int imageHeight)
{
// Create a media sample
ComPtr<IMFSample> spSample;
CHK(MFCreateSample(&spSample));
CHK(spSample->SetSampleDuration(_duration));
CHK(spSample->SetSampleTime(_hnsSampleTime));
_hnsSampleTime += _duration;
// Add a media buffer
ComPtr<IMFMediaBuffer> spBuffer;
CHK(MFCreateMemoryBuffer(_bufferLength, &spBuffer));
CHK(spBuffer->SetCurrentLength(_bufferLength));
CHK(spSample->AddBuffer(spBuffer.Get()));
// Copy the picture into the buffer
unsigned char *pbBuffer = nullptr;
CHK(spBuffer->Lock(&pbBuffer, nullptr, nullptr));
BYTE* buffer = (BYTE*)videoFrameBuffer->begin() + 4 * imageWidth * (imageHeight - 1);
CHK(MFCopyImage(pbBuffer + 4 * _width * (_height - imageHeight),
4 * _width, buffer, -4 * imageWidth, 4 * imageWidth, imageHeight));
CHK(spBuffer->Unlock());
// Write the media sample
CHK(_spSinkWriter->WriteSample(_streamIndex, spSample.Get()));
}
为什么你认为我得到了异常,我该如何解决这个问题?
谢谢。
如何在接收器编写器的AddStream中设置媒体类型?你有没有尝试在其中指定高配置文件? – VuVirt
我添加了所有与此问题相关的代码。不,我不知道该怎么做。 –
您可以尝试添加:spvideoTypeOut-> SetUINT32(MF_MT_MPEG2_PROFILE,eAVEncH264VProfile_High); – VuVirt