当前位置: 首页>>代码示例>>C++>>正文


C++ CComPtr::AddStream方法代码示例

本文整理汇总了C++中CComPtr::AddStream方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::AddStream方法的具体用法?C++ CComPtr::AddStream怎么用?C++ CComPtr::AddStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CComPtr的用法示例。


在下文中一共展示了CComPtr::AddStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Init

void MfVideoEncoder::Init(int width, int height, int fps) {
    mWidth = width;
    mHeight = height;
    mFps = fps;
    mFrameTime = 10 * 1000 * 1000 / fps;

    CComPtr<IMFMediaType> pMediaTypeOut;
    CComPtr<IMFMediaType> pMediaTypeIn;

    HRESULT hr = MFCreateSinkWriterFromURL(mFilename.c_str(), NULL, NULL, &mSinkWriter);

    // 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)) {
        hr = pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
    }
    if (SUCCEEDED(hr)) {
        hr = pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, 8000000);
    }
    if (SUCCEEDED(hr)) {
        hr = pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, width, height);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, fps, 1);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
    }
    pMediaTypeOut->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1);

    if (SUCCEEDED(hr)) {
        hr = mSinkWriter->AddStream(pMediaTypeOut, (DWORD*)&mStreamIndex);
    }

    // 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)) {
        hr = pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32);
    }
    if (SUCCEEDED(hr)) {
        hr = pMediaTypeIn->SetUINT32(MF_MT_MPEG2_PROFILE, 77);
    }
    if (SUCCEEDED(hr)) {
        hr = pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, width, height);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, fps, 1);
    }
    if (SUCCEEDED(hr)) {
        hr = MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
    }
    if (SUCCEEDED(hr)) {
        hr = mSinkWriter->SetInputMediaType(mStreamIndex, pMediaTypeIn, nullptr);
    }
    
    // Tell the sink writer to start accepting data.
    if (SUCCEEDED(hr)) {
        hr = mSinkWriter->BeginWriting();
    }
    
    CComPtr<ICodecAPI> encoder;
    hr = mSinkWriter->GetServiceForStream(0, GUID_NULL, IID_PPV_ARGS(&encoder));
    if (SUCCEEDED(hr)) {
        CComVariant quality((UINT32)eAVEncCommonRateControlMode_CBR, VT_UI4);
        hr = encoder->SetValue(&CODECAPI_AVEncCommonRateControlMode, &quality);
    }	
    if (SUCCEEDED(hr)) {
        CComVariant quality((UINT32)80000000, VT_UI4);
        hr = encoder->SetValue(&CODECAPI_AVEncCommonMeanBitRate, &quality);
    }
    
    // Return the pointer to the caller.
    if (!SUCCEEDED(hr)) {
        mSinkWriter.Release();
        throw TempleException("Unable to begin writing to the video stream");
    }
}
开发者ID:ema29,项目名称:TemplePlus,代码行数:93,代码来源:video_mf.cpp


注:本文中的CComPtr::AddStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。