[vlc-devel] [PATCH] avformat: use avcodec codec_tag as original fourcc

Daniel Verkamp daniel at drv.nu
Thu Jan 30 08:31:47 CET 2014


On Thu, Jan 30, 2014 at 12:27 AM, Daniel Verkamp <daniel at drv.nu> wrote:
> Fixes Bink video playback. The Bink video decoder in libavcodec relies
> on the fourcc to determine the version of the codec.
> ---
>  modules/demux/avformat/demux.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
> index 6e8086e..6bb61f4 100644
> --- a/modules/demux/avformat/demux.c
> +++ b/modules/demux/avformat/demux.c
> @@ -96,6 +96,11 @@ static block_t *BuildSsaFrame( const AVPacket *p_pkt, unsigned i_order );
>  static void UpdateSeekPoint( demux_t *p_demux, int64_t i_time );
>  static void ResetTime( demux_t *p_demux, int64_t i_time );
>
> +static vlc_fourcc_t CodecTagToFourcc( uint32_t codec_tag )
> +{
> +    return VLC_FOURCC( codec_tag & 0xFF, (codec_tag >> 8) & 0xFF, (codec_tag >> 16) & 0xFF, codec_tag >> 24 );
> +}

Based on the usage of ffmpeg_CodecTag to convert i_original_fourcc in
the avcodec module, I added a corresponding function to convert from
codec_tag to vlc_fourcc_t; I couldn't find the equivalent function
anywhere, but if I missed one, please let me know.

I also don't have a big-endian machine to test on, but I believe the
conversion is the correct inverse of ffmpeg_CodecTag.

> +
>  /*****************************************************************************
>   * Open
>   *****************************************************************************/
> @@ -293,6 +298,7 @@ int OpenDemux( vlc_object_t *p_this )
>          {
>          case AVMEDIA_TYPE_AUDIO:
>              es_format_Init( &fmt, AUDIO_ES, fcc );
> +            fmt.i_original_fourcc = CodecTagToFourcc( cc->codec_tag );
>              fmt.i_bitrate = cc->bit_rate;
>              fmt.audio.i_channels = cc->channels;
>              fmt.audio.i_rate = cc->sample_rate;
> @@ -303,6 +309,7 @@ int OpenDemux( vlc_object_t *p_this )
>
>          case AVMEDIA_TYPE_VIDEO:
>              es_format_Init( &fmt, VIDEO_ES, fcc );
> +            fmt.i_original_fourcc = CodecTagToFourcc( cc->codec_tag );
>
>              fmt.video.i_bits_per_pixel = cc->bits_per_coded_sample;
>              /* Special case for raw video data */
> @@ -344,6 +351,7 @@ int OpenDemux( vlc_object_t *p_this )
>
>          case AVMEDIA_TYPE_SUBTITLE:
>              es_format_Init( &fmt, SPU_ES, fcc );
> +            fmt.i_original_fourcc = CodecTagToFourcc( cc->codec_tag );
>              if( strncmp( p_sys->ic->iformat->name, "matroska", 8 ) == 0 &&
>                  cc->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
>                  cc->extradata != NULL &&
> @@ -391,6 +399,7 @@ int OpenDemux( vlc_object_t *p_this )
>
>          default:
>              es_format_Init( &fmt, UNKNOWN_ES, 0 );
> +            fmt.i_original_fourcc = CodecTagToFourcc( cc->codec_tag );

I don't know if fourcc makes sense for unknown stream types, but I
don't think it should hurt (codec_tag should be initialized to 0 on
the avcodec side anyway).

Thanks,
-- Daniel Verkamp



More information about the vlc-devel mailing list