[FFmpeg-devel] [PATCH 2/3] avformat: add support to force specific AVCodecs

Paul B Mahol onemda at gmail.com
Wed Oct 2 18:29:52 CEST 2013


On 9/28/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> previously only codec_ids could be forced, which did not allow
> forcing a specific implementation like libopenjpeg vs jpeg2000.
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavformat/avformat.h |   30 ++++++++++++++++++++++++++++++
>  libavformat/utils.c    |   15 +++++++++++++++
>  2 files changed, 45 insertions(+)
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index b18eb3f..0ab8af6 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1315,9 +1315,39 @@ typedef struct AVFormatContext {
>       * Demuxers can use the flag to detect such changes.
>       */
>      int io_repositioned;
> +
> +    /**
> +     * Forced video codec.
> +     * This allows forcing a specific decoder, even when there are multiple
> with
> +     * the same codec_id

Missing dot

> +     * Demuxing: Set by user via av_format_set_video_codec (NO direct
> access).
> +     */
> +    AVCodec *video_codec;
> +
> +    /**
> +     * Forced audio codec.
> +     * This allows forcing a specific decoder, even when there are multiple
> with
> +     * the same codec_id

ditto

> +     * Demuxing: Set by user via av_format_set_audio_codec (NO direct
> access).
> +     */
> +    AVCodec *audio_codec;
> +
> +    /**
> +     * Forced subtitle codec.
> +     * This allows forcing a specific decoder, even when there are multiple
> with
> +     * the same codec_id

ditto

> +     * Demuxing: Set by user via av_format_set_subtitle_codec (NO direct
> access).
> +     */
> +    AVCodec *subtitle_codec;
>  } AVFormatContext;
>
>  int av_format_get_probe_score(const AVFormatContext *s);
> +AVCodec * av_format_get_video_codec(const AVFormatContext *s);
> +void      av_format_set_video_codec(AVFormatContext *s, AVCodec *c);
> +AVCodec * av_format_get_audio_codec(const AVFormatContext *s);
> +void      av_format_set_audio_codec(AVFormatContext *s, AVCodec *c);
> +AVCodec * av_format_get_subtitle_codec(const AVFormatContext *s);
> +void      av_format_set_subtitle_codec(AVFormatContext *s, AVCodec *c);
>
>  /**
>   * Returns the method used to set ctx->duration.
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index b47787a..61405d7 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -98,12 +98,27 @@ static int64_t wrap_timestamp(AVStream *st, int64_t
> timestamp)
>  }
>
>  MAKE_ACCESSORS(AVStream, stream, AVRational, r_frame_rate)
> +MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, video_codec)
> +MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, audio_codec)
> +MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, subtitle_codec)
>
>  static AVCodec *find_decoder(AVFormatContext *s, AVStream *st, enum
> AVCodecID codec_id)
>  {
>      if (st->codec->codec)
>          return st->codec->codec;
>
> +    switch(st->codec->codec_type){
> +    case AVMEDIA_TYPE_VIDEO:
> +        if(s->video_codec)    return s->video_codec;
> +        break;
> +    case AVMEDIA_TYPE_AUDIO:
> +        if(s->audio_codec)    return s->audio_codec;
> +        break;
> +    case AVMEDIA_TYPE_SUBTITLE:
> +        if(s->subtitle_codec) return s->subtitle_codec;
> +        break;
> +    }
> +
>      return avcodec_find_decoder(codec_id);
>  }

rest lgtm


More information about the ffmpeg-devel mailing list