IMFSinkWriter无法导出mp4的大尺寸视频 [英] IMFSinkWriter can't export a large size video of mp4
问题描述
我的Windows MFC应用程序具有导出视频文件的功能.
并且可以选择编码格式(通过 WMV 或 MP4 )和帧大小.
但是,不幸的是,当我尝试导出设置为大帧大小的 MP4 文件时,每次发生 MF_E_INVALIDMEDIATYPE .
My Windows MFC application has a function to export a video file.
And it can select encoding format (via WMV or MP4) and frame size.
But, Unfortunately when i tried to export MP4 file which is set large frame size, everytime MF_E_INVALIDMEDIATYPE happened.
简单地说,这是我在每种情况下进行测试时的结果.
Simply put, here is the result when i tested in each case.
- 640 x 480 ...确定
- 640 x 576 ...确定
- 1280 x 720 ...确定
- 1280 x 720 ...确定
- 1920 x 1080 ...确定
- 2048 x 1556 ...确定
- 4096 x 2160 ...确定
- 640 x 480 ...确定
- 640 x 576 ...确定
- 1280 x 720 ...确定
- 1280 x 720 ...确定
- 1920 x 1080 ...确定
- 2048 x 1556 ... MF_E_INVALIDMEDIATYPE
- 4096 x 2160 ... MF_E_INVALIDMEDIATYPE
这是我的代码.
HRESULT hr = S_OK;
TIFF *out;
IMFSinkWriter *pWriter = NULL;
IMFMediaType *pMediaTypeOut = NULL;
IMFMediaType *pMediaTypeIn = NULL;
DWORD streamIndex;
hr = MFCreateSinkWriterFromURL(filename, NULL, NULL, &pWriter);
// Set the output media type.
if (SUCCEEDED(hr))
{
hr = MFCreateMediaType(&pMediaTypeOut);
}
if (SUCCEEDED(hr))
{
hr = pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
}
if (SUCCEEDED(hr))
{
if (exportMethod == ExportFormatWAV) {
hr = pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_WVC1);
}
else if (exportMethod == ExportFormatMP4) {
hr = pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
}
}
if (SUCCEEDED(hr))
{
hr = pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, 12 * 1000 * 1000); // 12M
}
if (SUCCEEDED(hr))
{
hr = pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, m_width, m_height); // e.g. 4096 x 2160
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, m_fps * 100, 100);
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
}
if (SUCCEEDED(hr))
{
hr = pWriter->AddStream(pMediaTypeOut, &streamIndex);
}
// Set the input media type.
if (SUCCEEDED(hr))
{
hr = MFCreateMediaType(&pMediaTypeIn);
}
if (SUCCEEDED(hr))
{
hr = pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
}
if (SUCCEEDED(hr))
{
if (exportMethod == ExportFormatWAV) {
hr = pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB24);
}
else if (exportMethod == ExportFormatMP4) {
hr = pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32); // Because H264 requires
}
}
if (SUCCEEDED(hr))
{
hr = pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, m_width, m_height); // e.g. 4096 x 2160
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, m_fps * 100, 100);
}
if (SUCCEEDED(hr))
{
hr = MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
}
if (SUCCEEDED(hr))
{
hr = pWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL); // This line returns MF_E_INVALIDMEDIATYPE
}
// Tell the sink writer to start accepting data.
if (SUCCEEDED(hr))
{
hr = pWriter->BeginWriting();
}
我也要导出 MP4 的大尺寸视频.
有人知道解决此问题的方法吗?
I want to export a large sized video of MP4 as well.
Does anyone know a solution against this problem?
参考文献
https://msdn.microsoft. com/zh-CN/library/windows/desktop/ff819477(v = vs.85).aspx
https://msdn.microsoft. com/en-us/library/windows/desktop/ff819476(v = vs.85).aspx
References
https://msdn.microsoft.com/en-us/library/windows/desktop/ff819477(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ff819476(v=vs.85).aspx
同一问题已经发布了msdn.
https://social.msdn.microsoft.com/Forums/zh-CN/ac5b71e4-e94a-4d18-bc92-8b44fa5280b6/the-max-resolution-for-mp4h264-encoder
Same question has already posted msdn.
https://social.msdn.microsoft.com/Forums/en-US/ac5b71e4-e94a-4d18-bc92-8b44fa5280b6/the-max-resolution-for-mp4h264-encoder
推荐答案
Media Foundation's MPEG-4 File Sink has no resolution restrictions. It multiplexes already encoded data and is not sensitive to video resolution.
如果/当您在编码H.264上下文时,编码器通常确实具有局限性.例如,英特尔®HD Graphics 4600的英特尔®快速同步视频H.264编码器MFT可以产生4096 x 4096 H.264内容,而MP4接收器将其正确写入文件中.
If/when you, however, are encoding H.264 context, the encoders typically do have the limitations. For example, Intel(R) HD Graphics 4600's Intel® Quick Sync Video H.264 Encoder MFT can produce 4096 x 4096 H.264 content, and MP4 sink writes it correctly to file.
在您的情况下,您可能会达到编码器中的分辨率极限,并且由于编码器拒绝带有通用错误代码的不支持的分辨率,因此您没有比MF_E_INVALIDMEDIATYPE
有用的东西了.使用备用编码器可能会更好.
In your case you are likely to hit resolution limit in encoder, and since encoder rejects unsupported resolution with generic error code, you don't have anything more helpful than MF_E_INVALIDMEDIATYPE
. You might have better luck with an alternate encoder.
这篇关于IMFSinkWriter无法导出mp4的大尺寸视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!