0

I have an application that needs to encode some audio files in MP3 format, 320 kbps bitrate. I'm using DirectShow to accomplish this task and lameDS-3.99.5 DirectShow filter.

The problem is that even if I set lameDS-3.99.5 DirectShow filter in GraphEdit to use Constant Birate - 320 kbps, the encoding is made all the time at 128 kbps.

What I need is an way to set the bitrate of the lameDS-3.99.5 DirectShow filter grammatically.

I have investigated all the web but I didn't found an example of doing this.

Some advice that I have found is to use IAMStreamConfig Interface on the output pin of the filter, but I didn't found any code examples in achieves this.

Thank you for helping me.

@Roman

Thank you very much for your reply.

Please find my function:

HRESULT CDShowGraph::AddLAMEMP3EncoderFilter( CComPtr<IBaseFilter>& spCodec )
{
   HRESULT hr = spCodec.CoCreateInstance( IID_LAMEAudioEncoder_Filter );
   if (FAILED(hr) )
    {
      return hr;
    }

   IEnumPins *pEnum = NULL;
   IPin *pPin = NULL;
   hr = spCodec->EnumPins(&pEnum);
   if (FAILED(hr))
   {
   }
   while (S_OK == pEnum->Next(1, &pPin, NULL))
   {
        PIN_DIRECTION pinDir;
        PIN_DIRECTION dir = PINDIR_OUTPUT;
        hr = pPin->QueryDirection(&pinDir);
        if (SUCCEEDED(hr))
        {
            if(pinDir == dir)
            {
                 IAMStreamConfig * pamconfig = 0;   
                 hr = pPin->QueryInterface(IID_IAMStreamConfig, (void **)&pamconfig);   
                 if(FAILED(hr)) {}   
                 else 
                 {
                     AM_MEDIA_TYPE *pmt={0};   
                     hr = pamconfig->GetFormat(&pmt);
                     if(FAILED(hr)) {}   
                     else 
                     { 
                        //audio_set_capformat(pmt);
                        WAVEFORMATEX *format = (WAVEFORMATEX *) pmt->pbFormat;
                        format->nAvgBytesPerSec = 320*1024;
                        hr = pamconfig->SetFormat(pmt);               
                        DeleteMediaType(pmt);
                     }
                 }
                 pamconfig->Release();   
            }
        }
   }

   hr = m_ptrGraph->m_pGraphBuilder->AddFilter( spCodec, NULL );
   return hr;
}

It goes till here:

AM_MEDIA_TYPE *pmt={0};   
hr = pamconfig->GetFormat(&pmt);

For pmt I get 0x00000000 Bad Ptr and after it execute the next code with success:

AM_MEDIA_TYPE *pmt={0};   
hr = pamconfig->GetFormat(&pmt);

for the all fields in the format I get:

wFormatTag CXX0030: Error: expression cannot be evaluated

nChannels CXX0030: Error: expression cannot be evaluated

nSamplesPerSec CXX0030: Error: expression cannot be evaluated

nAvgBytesPerSec CXX0030: Error: expression cannot be evaluated

nBlockAlign CXX0030: Error: expression cannot be evaluated

wBitsPerSample CXX0030: Error: expression cannot be evaluated

cbSize CXX0030: Error: expression cannot be evaluated

Claudiu
  • 11
  • 3

1 Answers1

0
Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158