Exemplo n.º 1
0
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 "";
}
Exemplo 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();
}
Exemplo n.º 3
0
RString MovieDecoder_FFMpeg::Open( RString sFile )
{
	MovieTexture_FFMpeg::RegisterProtocols();
    
	m_fctx = avcodec::avformat_alloc_context();
	if( !m_fctx )
		return "AVCodec: Couldn't allocate context";
    
	RageFile *f = new RageFile;

	if( !f->Open(sFile, RageFile::READ) )
	{
		RString errorMessage = f->GetError();
		RString error = ssprintf("MovieDecoder_FFMpeg: Error opening \"%s\": %s", sFile.c_str(), errorMessage.c_str() );
		delete f;
		return error;
	}

	m_buffer = (unsigned char *)avcodec::av_malloc(STEPMANIA_FFMPEG_BUFFER_SIZE);
	m_avioContext = avcodec::avio_alloc_context(m_buffer, STEPMANIA_FFMPEG_BUFFER_SIZE, 0, f, AVIORageFile_ReadPacket, NULL, AVIORageFile_Seek);
	m_fctx->pb = m_avioContext;
	int ret = avcodec::avformat_open_input( &m_fctx, sFile.c_str(), NULL, NULL );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "AVCodec: Couldn't open \"%s\"", sFile.c_str()) );

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

	int stream_idx = avcodec::av_find_best_stream( m_fctx, avcodec::AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0 );
	if ( stream_idx < 0 ||
		static_cast<unsigned int>(stream_idx) >= m_fctx->nb_streams ||
		m_fctx->streams[stream_idx] == NULL )
		return "Couldn't find any video streams";
	m_pStream = m_fctx->streams[stream_idx];

	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::av_get_pix_fmt_name(m_pStream->codec->pix_fmt) );

	return RString();
}
Exemplo n.º 4
0
RString MovieDecoder_FFMpeg::OpenCodec()
{
	Init();

	ASSERT( m_pStream != NULL );
	if( m_pStream->codec->codec )
		avcodec::avcodec_close( m_pStream->codec );

	avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStream->codec->codec_id );
	if( pCodec == NULL )
		return ssprintf( "Couldn't find decoder %i", m_pStream->codec->codec_id );

	m_pStream->codec->workaround_bugs   = 1;
	m_pStream->codec->idct_algo         = FF_IDCT_AUTO;
	m_pStream->codec->error_concealment = 3;

	if( pCodec->capabilities & CODEC_CAP_DR1 )
		m_pStream->codec->flags |= CODEC_FLAG_EMU_EDGE;

	LOG->Trace("Opening codec %s", pCodec->name );

	int ret = avcodec::avcodec_open2( m_pStream->codec, pCodec, NULL );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "Couldn't open codec \"%s\"", pCodec->name) );
	ASSERT( m_pStream->codec->codec != NULL );

	return RString();
}
Exemplo n.º 5
0
RString MovieDecoder_FFMpeg::OpenCodec()
{
	Init();

	ASSERT( m_pStream );
	if( m_pStream->codec->codec )
		avcodec::avcodec_close( m_pStream->codec );

	avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStream->codec->codec_id );
	if( pCodec == NULL )
		return ssprintf( "Couldn't find decoder %i", m_pStream->codec->codec_id );

	LOG->Trace("Opening codec %s", pCodec->name );

	if( !m_bHadBframes )
	{
		LOG->Trace("Setting CODEC_FLAG_LOW_DELAY" );
		m_pStream->codec->flags |= CODEC_FLAG_LOW_DELAY;
	}

	int ret = avcodec::avcodec_open( m_pStream->codec, pCodec );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "Couldn't open codec \"%s\"", pCodec->name) );
	ASSERT( m_pStream->codec->codec );

	/* This is set to true when we find a B-frame, to use on the next loop. */
	m_bHadBframes = false;

	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 "";
}