PDA

View Full Version : Problem by choosing a codec



Viper220679
June 20, 2007, 12:16:53
Hello!

I want to record an image stream by using a codec.
The sample "\\vc71\CreateVideoFile.cpp" shows how to choose a codec:

// Get a list of all available video compressors (codecs)
tCodecListPtr pCodecList = Codec::getAvailableCodecs();
if( pCodecList == 0 )
{
std::cerr << "No codecs found." << std::endl;
return 1;
}

int Compressor_idx = presentUserChoice( toStringArrayPtrListPtr( pCodecList ) );
if( Compressor_idx == -1 )
{
std::cerr << "No compressor chosen." << std::endl;
return 1;
}


My problem is that my program doesn´t return the message "No codecs found." but it says "No compressor chosen.".
It seems that codecs were found, but I can´t choose any codec.
The integer "compressor_idx" is "-1" anytime.

Maybe someone can help me... :confused: :confused:

Regards

Viper220679

Stefan Geissler
June 20, 2007, 12:41:56
Hello Viper220679,

I suppose pCodecList is not 0, but is is empty. Thus you should enhance the "if" statement as


if( pCodecList == 0 || pCodecList->empty() )

Viper220679
June 21, 2007, 07:29:56
Hello Stefan,

thank you for the fast reply.
I tried your suggestion but the result is the same.

Maybe you´ve got another idea?!

Best regards

Viper220679

Stefan Geissler
June 21, 2007, 08:03:25
Hi,

Do you get a list of codecs?

Also the presentUserChoice() function uses printf(). It works in a console only. It can not be used e.g. in a MFC dialog. Also if you debug and step in this function, you should be able to see the listed codecs in the debug session.

Viper220679
June 21, 2007, 09:03:37
OK, I think there is the problem.
Actually, I´m using the MFC dialog.

Is there another method to display the available codecs by using the MFC dialog?

Maybe you´ve got an example for me?!

Thanks for your help.

Viper220679

Stefan Geissler
June 21, 2007, 10:06:40
Hi,

Yes, there is a sample. Please search for "FillCodecComboBox" in following sample:
http://www.imagingcontrol.com/library/cpp/section/image-aquisition/example/image-and-avi-capture/

You will find sample code to fill a combobox with the available codecs in there:


void CImageandAVICaptureDlg::FillCodecComboBox()
{
m_CodecListPtr = Codec::getAvailableCodecs();
unsigned int i = 0;
for( i = 0; i < m_CodecListPtr->size();i++ )
{
m_ComboCodecs.AddString( m_CodecListPtr->at(i)->getName().c_str());
if( i == 0 ) // Select the first codec.
{
m_ComboCodecs.SetCurSel(i);
m_pAVISink = MediaStreamSink::create( MediaStreamContainer::create( MSC_AviContainer ), m_CodecListPtr->at(i));

// If the currently selected codec has a dialog, the codec properties button will be enabled.
if(m_CodecListPtr->at(i)->hasDialog())
m_cButtonCodecProperties.EnableWindow(true);
else
m_cButtonCodecProperties.EnableWindow(true);
}
}

// Add the uncompressed formats.
m_ComboCodecs.AddString("Y800");
m_ComboCodecs.AddString("RGB24");
m_ComboCodecs.AddString("RGB32");
}