2017-04-06 61 views
3

我試圖在Windows Phone 8.1中使用Media Foundation庫和接收器編碼器對視頻進行編碼。Windows Phone 8.1媒體基金會H264最高分辨率

我已經能夠通過我的媒體輸出設置MFVideoFormat_H264MF_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())); 
} 

爲什麼你認爲我得到了異常,我該如何解決這個問題?

謝謝。

+1

如何在接收器編寫器的AddStream中設置媒體類型?你有沒有嘗試在其中指定高配置文件? – VuVirt

+1

我添加了所有與此問題相關的代碼。不,我不知道該怎麼做。 –

+1

您可以嘗試添加:spvideoTypeOut-> SetUINT32(MF_MT_MPEG2_PROFILE,eAVEncH264VProfile_High); – VuVirt

回答

2

通過搜索用於每個分辨率默認的比特率實測值的溶液,

1080以5.0 Mbps的比特率工作,

1600x900的作品具有2.5 Mbps的比特率,

720p的作品1.25比特率Mbps ...