[FFmpeg-devel] [PATCH 19/23] avformat/matroskaenc: Improve mimetype search

James Almer jamrial at gmail.com
Wed Nov 6 16:33:00 EET 2019


On 11/5/2019 11:49 PM, Andreas Rheinhardt wrote:
> Use the mime_types of the corresponding AVCodecDescriptor instead of own
> arrays. The former are more encompassing.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/codec_desc.c   |  1 +
>  libavformat/matroskaenc.c | 14 +++-----------
>  2 files changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 0602ecb1b5..837b09e7f4 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -3020,6 +3020,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
>          .name      = "text",
>          .long_name = NULL_IF_CONFIG_SMALL("raw UTF-8 text"),
>          .props     = AV_CODEC_PROP_TEXT_SUB,
> +        .mime_types= MT("text/plain"),
>      },
>      {
>          .id        = AV_CODEC_ID_XSUB,
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 19d9b0bc66..f2c8a66a03 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -1694,17 +1694,9 @@ static int mkv_write_attachments(AVFormatContext *s)
>          if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
>              mimetype = t->value;
>          else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {
> -            int i;
> -            for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
> -                if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) {
> -                    mimetype = ff_mkv_mime_tags[i].str;
> -                    break;
> -                }
> -            for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
> -                if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) {
> -                    mimetype = ff_mkv_image_mime_tags[i].str;
> -                    break;
> -                }
> +            const AVCodecDescriptor *desc = avcodec_descriptor_get(st->codecpar->codec_id);
> +            if (desc && desc->mime_types)
> +                mimetype = desc->mime_types[0];

This will change the value written for AV_CODEC_ID_BIN_DATA from
"binary" to "application/octet-stream". Is that intended and/or desirable?

>          }
>          if (!mimetype) {
>              av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and "
> 



More information about the ffmpeg-devel mailing list