简体   繁体   English

如何从 DirectShow 获取未压缩的字节数组?

[英]How to get uncompressed byte array from DirectShow?

I am trying to use DirectShow https://docs.microsoft.com/en-us/windows/win32/directshow/directshow in order to get uncompressed byte array from .mp3 stream.我正在尝试使用 DirectShow https://docs.microsoft.com/en-us/windows/win32/directshow/directshow以便从.mp3流中获取未压缩的字节数组。 I have an implementation that can playback .mp3 byte stream我有一个可以播放.mp3字节流的实现

bool coAudioPlayer::LoadImp(SoundDataType dataType, std::string const & filename, unsigned char const * pData, int64_t dataLen, bool bOnlyIfFilenameChanged)
{
...
    m_pMemReader = new CMemReader(m_pMemStream, m_pMediaType, &hr);

    m_pMemReader->AddRef();


    hr = CoCreateInstance(CLSID_FilterGraph,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IGraphBuilder,
        (void **)&this->m_pigb);

    hr = m_pigb->AddFilter(m_pMemReader, NULL);
    if (FAILED(hr))
    {
        return false;
    }

    m_pigb->QueryInterface(IID_IMediaControl, (void **)&m_pimc);
    m_pigb->QueryInterface(IID_IMediaEventEx, (void **)&m_pimex);
    m_pigb->QueryInterface(IID_IBasicAudio, (void**)&m_piba);
    m_pigb->QueryInterface(IID_IMediaSeeking, (void**)&m_pims);

    /*  Render our output pin */
    hr = m_pigb->Render(m_pMemReader->GetPin(0));
    if (!SUCCEEDED(hr))
    {
        return false;
    }

    HRESULT hr = m_pimc->Run();

    return m_bReady;
}

But I need to extend this functional and add approach to get uncompressed byte array (sound frames).但是我需要扩展这个功能并添加方法来获取未压缩的字节数组(声音帧)。 As far as I understand under the hood DirectShow decodes it, but I don't see any way to retrieve this decoded array.据我了解, DirectShow解码,但我看不到任何方法来检索此解码后的数组。

Is there a way to do it?有没有办法做到这一点?

"uncompressed byte array" is quite a wrong definition of desired data. “未压缩的字节数组”是对所需数据的错误定义。 There is no such thing as media data in byte array format.没有字节数组格式的媒体数据之类的东西。 MP3 audio would typically be decompressed by MP3 Decoder media object wrapper into DirectShow filter into audio of MEDIASUBTYPE_PCM format with certain properties (sampling rate, channel count, bits per sample). MP3 音频通常会被 MP3 解码器媒体对象包装器解压缩到 DirectShow 过滤器中,成为具有某些属性(采样率、通道数、每个样本的位数)的MEDIASUBTYPE_PCM格式的音频。 Specifically, selected bit depth (and this decoder does support multiple bit depth options!) defines directly the representation of audio data as byte array.具体来说,选定的位深(并且此解码器确实支持多个位深选项!)直接将音频数据的表示定义为字节数组。

You don't need or want to access the data when you build a playback pipeline, such as in scenario with Render method you mention and do you don't have the data.在构建播放管道时,您不需要或不想访问数据,例如在您提到的带有Render方法的场景中,您是否没有数据。

A typical way to access the content is to build a pipeline around Sample Grabber Filter .访问内容的典型方法是围绕Sample Grabber Filter构建管道。 There is a huge amount of code and questions explaining the approach.有大量代码和问题解释了该方法。 The relevant keyword is SampleCB standing for ISampleGrabberCB::SampleCB method.相关的关键字是SampleCB代表ISampleGrabberCB::SampleCB方法。 For example: ffmpeg audio frame from directshow sampleCB imediasample .例如:来自 directshow sampleCB imediasample 的 ffmpeg 音频帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM