[FFmpeg-devel] [PATCH] avformat/rawenc: check stream type

Michael Niedermayer michael at niedermayer.cc
Tue Apr 10 02:19:39 EEST 2018


On Fri, Apr 06, 2018 at 08:34:12PM +0530, Gyan Doshi wrote:
> 
> On 4/5/2018 12:09 AM, Michael Niedermayer wrote:
> >
> >This does not work
> >breaks fate-unknown_layout-ac3
> >
> >also the tests mayb too strict, there are similar codec_ids like mpeg1/2
> >or jpeg variants which are all basically the same from a muxers point of view
> 
> Revised patch passes FATE. Set looser conditions for mpeg-1/2/4 and jpeg
> muxer.
> 
> Regards,
> Gyan

>  rawenc.c |   36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 5aaae3c1bf40a983cff15bc2fc603ac214d9437a  v2-0001-avformat-rawenc-check-stream-type.patch
> From a4ae3eb20af9a4c6e5feb201347b5b044541c59b Mon Sep 17 00:00:00 2001
> From: Gyan Doshi <gyandoshi at gmail.com>
> Date: Fri, 6 Apr 2018 20:21:57 +0530
> Subject: [PATCH v2] avformat/rawenc: check stream type
> 
> Validate codec of stream to be muxed except for data muxer.
> ---
>  libavformat/rawenc.c | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
> index 809ca23b1a..19028329f7 100644
> --- a/libavformat/rawenc.c
> +++ b/libavformat/rawenc.c
> @@ -34,12 +34,48 @@ int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
>  
>  static int force_one_stream(AVFormatContext *s)
>  {
> +enum AVCodecID id;
> +const char *idname;

indention is wrong


> +
>      if (s->nb_streams != 1) {
>          av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
>                 s->oformat->name);
>          return AVERROR(EINVAL);
>      }
> +
> +    if (!strcmp("data", s->oformat->name))
> +        return 0;
> +
> +id = s->streams[0]->codecpar->codec_id;
> +idname = avcodec_get_name(id);

same


> +
> +    switch(s->streams[0]->codecpar->codec_type) {
> +        case AVMEDIA_TYPE_AUDIO:
> +            if (s->oformat->audio_codec != id)
> +                goto fail;
> +            break;
> +        case AVMEDIA_TYPE_VIDEO:
> +            if (strstr(s->oformat->name, "mpeg") != NULL) {
> +                if (strstr(idname, "mpeg") == NULL)
> +                    goto fail;
> +            } else if (strstr(s->oformat->name, "m4v") != NULL) {
> +                       if (strstr(idname, "mpeg4") == NULL)
> +                           goto fail;
> +            } else if (strstr(s->oformat->name, "jpeg") != NULL) {
> +                       if (strstr(idname, "jpeg") == NULL)
> +                           goto fail;
> +            } else if (s->oformat->video_codec != id)
> +                       goto fail;
> +            break;

iam not sure these cross similarity stuff should be hardcoded here.
It seems painfull to have to maintain this.
also the ones i mentioned might not be all cases

To implement generic "codec supported" checks, muxers would have to
list what they support.
There are 3 ways i know how this can be done in the current API
1. the audio_codec / video_codec / ... fields
2. the codec_tag array (this was in fact IIRC one of the intended uses of it)
3. the querry_format callback

thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180410/94bce4dd/attachment.sig>


More information about the ffmpeg-devel mailing list