CString MovieTexture_FFMpeg::CreateDecoder()
{
	RegisterProtocols();

	int ret = avcodec::av_open_input_file( &decoder->m_fctx, "rage://" + GetID().filename, NULL, 0, NULL );
	if( ret < 0 )
		return ssprintf( averr_ssprintf(ret, "AVCodec: Couldn't open \"%s\"", GetID().filename.c_str()) );

	ret = avcodec::av_find_stream_info( decoder->m_fctx );
	if ( ret < 0 )
		return ssprintf( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", GetID().filename.c_str()) );

	avcodec::AVStream *stream = FindVideoStream( decoder->m_fctx );
	if ( stream == NULL )
		return ssprintf( "AVCodec (%s): Couldn't find any video streams", GetID().filename.c_str() );

	if( stream->codec.codec_id == avcodec::CODEC_ID_NONE )
		return ssprintf( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), stream->codec.codec_tag );

	avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( stream->codec.codec_id );
	if( codec == NULL )
		return ssprintf( "AVCodec (%s): Couldn't find decoder %i", GetID().filename.c_str(), stream->codec.codec_id );

	LOG->Trace("Opening codec %s", codec->name );
	ret = avcodec::avcodec_open( &stream->codec, codec );
	if ( ret < 0 )
		return ssprintf( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", GetID().filename.c_str(), codec->name) );

	/* Don't set this until we successfully open stream->codec, so we don't try to close it
	 * on an exception unless it was really opened. */
	decoder->m_stream = stream;

	return "";
}
Esempio n. 2
0
RString MovieDecoder_FFMpeg::Open( RString sFile )
{
	MovieTexture_FFMpeg::RegisterProtocols();

	int ret = avcodec::av_open_input_file( &m_fctx, "rage://" + sFile, NULL, 0, NULL );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "AVCodec: Couldn't open \"%s\"", sFile.c_str()) );

	ret = avcodec::av_find_stream_info( m_fctx );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", sFile.c_str()) );

	avcodec::AVStream *pStream = FindVideoStream( m_fctx );
	if( pStream == NULL )
		return "Couldn't find any video streams";
	m_pStream = pStream;

	if( m_pStream->codec->codec_id == avcodec::CODEC_ID_NONE )
		return ssprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag );

	RString sError = OpenCodec();
	if( !sError.empty() )
		return ssprintf( "AVCodec (%s): %s", sFile.c_str(), sError.c_str() );

	LOG->Trace( "Bitrate: %i", m_pStream->codec->bit_rate );
	LOG->Trace( "Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(m_pStream->codec->pix_fmt) );

	return RString();
}
CString FFMpeg_Helper::Open(CString what)
{
	int ret = avcodec::av_open_input_file( &this->m_fctx, "rage://" + what, NULL, 0, NULL );
	if ( ret < 0 )
	{
		return ssprintf( averr_ssprintf(ret, "AVCodec: Couldn't open \"%s\"", what.c_str()) );
	}

	ret = avcodec::av_find_stream_info( this->m_fctx );
	if ( ret < 0 )
	{
		return ssprintf( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", what.c_str()) );
	}

	avcodec::AVStream *stream = FindVideoStream( this->m_fctx );
	if ( stream == NULL )
	{
		return ssprintf( "AVCodec (%s): Couldn't find any video streams", what.c_str() );
	}

#if (LIBAVCODEC_BUILD >= 4754)
	if( stream->codec->codec_id == avcodec::CODEC_ID_NONE )
	{
		return ssprintf( "AVCodec (%s): Unsupported codec %08x", what.c_str(), stream->codec->codec_tag );
	}

	avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( stream->codec->codec_id );
	if( codec == NULL )
	{
		return ssprintf( "AVCodec (%s): Couldn't find decoder %i", what.c_str(), stream->codec->codec_id );
	}

	LOG->Trace("Opening codec %s", codec->name );
	ret = avcodec::avcodec_open( stream->codec, codec );
#else
	if( stream->codec.codec_id == avcodec::CODEC_ID_NONE )
	{
		return ssprintf( "AVCodec (%s): Unsupported codec %08x", what.c_str(), stream->codec.codec_tag );
	}

	avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( stream->codec.codec_id );
	if( codec == NULL )
	{
		return ssprintf( "AVCodec (%s): Couldn't find decoder %i", what.c_str(), stream->codec.codec_id );
	}

	LOG->Trace("Opening codec %s", codec->name );
	ret = avcodec::avcodec_open( &stream->codec, codec );
#endif
	if ( ret < 0 )
	{
		return ssprintf( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", what.c_str(), codec->name) );
	}

#if (LIBAVCODEC_BUILD >= 4754)
	m_width  = stream->codec->width;
	m_height = stream->codec->height;
#else
	m_width  = stream->codec.width;
	m_height = stream->codec.height;
#endif
	/* Don't set this until we successfully open stream->codec, so we don't try to close it
	 * on an exception unless it was really opened. */
	m_stream = stream;

#if (LIBAVCODEC_BUILD >= 4754)
	LOG->Trace("Bitrate: %i", this->m_stream->codec->bit_rate );
	LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(this->m_stream->codec->pix_fmt) );
#else
	LOG->Trace("Bitrate: %i", this->m_stream->codec.bit_rate );
	LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(this->m_stream->codec.pix_fmt) );
#endif

	return "";
}