[FFmpeg-devel] [PATCH]Print an error if an unexpected pix_fmt is written to rawvideo in general purpose containers

Michael Niedermayer michaelni at gmx.at
Thu Apr 10 17:07:34 CEST 2014


On Thu, Apr 10, 2014 at 09:23:40AM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch tries to address ticket #3545.
> 
> Please comment, Carl Eugen

>  libavcodec/raw.c     |   27 +++++++++++++++++++++++++++
>  libavcodec/raw.h     |    3 +++
>  libavcodec/rawdec.c  |   33 +++------------------------------
>  libavformat/avienc.c |   10 ++++++++++
>  libavformat/movenc.c |    9 +++++++++
>  5 files changed, 52 insertions(+), 30 deletions(-)
> ad5729e174659bc28c6f73b664a168aca2cc9c37  patchavimovraw.diff
> diff --git a/libavcodec/raw.c b/libavcodec/raw.c
> index 16b1b39..ff0dec0 100644
> --- a/libavcodec/raw.c
> +++ b/libavcodec/raw.c
> @@ -234,3 +234,30 @@ unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat fmt)
>      }
>      return 0;
>  }
> +
> +const PixelFormatTag avpriv_pix_fmt_bps_avi[] = {
> +    { AV_PIX_FMT_MONOWHITE, 1 },
> +    { AV_PIX_FMT_PAL8,    2 },
> +    { AV_PIX_FMT_PAL8,    4 },
> +    { AV_PIX_FMT_PAL8,    8 },
> +    { AV_PIX_FMT_RGB444LE, 12 },
> +    { AV_PIX_FMT_RGB555LE, 15 },
> +    { AV_PIX_FMT_RGB555LE, 16 },
> +    { AV_PIX_FMT_BGR24,  24 },
> +    { AV_PIX_FMT_BGRA,   32 },
> +    { AV_PIX_FMT_NONE,    0 },
> +};
> +
> +const PixelFormatTag avpriv_pix_fmt_bps_mov[] = {
> +    { AV_PIX_FMT_MONOWHITE, 1 },
> +    { AV_PIX_FMT_PAL8,      2 },
> +    { AV_PIX_FMT_PAL8,      4 },
> +    { AV_PIX_FMT_PAL8,      8 },
> +    // FIXME swscale does not support 16 bit in .mov, sample 16bit.mov
> +    // http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
> +    { AV_PIX_FMT_RGB555BE, 16 },
> +    { AV_PIX_FMT_RGB24,    24 },
> +    { AV_PIX_FMT_ARGB,     32 },
> +    { AV_PIX_FMT_MONOWHITE,33 },
> +    { AV_PIX_FMT_NONE,      0 },
> +};

> diff --git a/libavcodec/raw.h b/libavcodec/raw.h
> index 3e59f28..3cc6ac0 100644
> --- a/libavcodec/raw.h
> +++ b/libavcodec/raw.h
> @@ -41,4 +41,7 @@ enum AVPixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int four
>  #endif
>  enum AVPixelFormat avpriv_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc);
>  
> +extern const PixelFormatTag avpriv_pix_fmt_bps_avi[];
> +extern const PixelFormatTag avpriv_pix_fmt_bps_mov[];

you need av_export somewhere


> +
>  #endif /* AVCODEC_RAW_H */
> diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
> index 790a4db..a03b1be 100644
> --- a/libavcodec/rawdec.c
> +++ b/libavcodec/rawdec.c
> @@ -62,33 +62,6 @@ static const AVClass rawdec_class = {
>      .version    = LIBAVUTIL_VERSION_INT,
>  };
>  
> -static const PixelFormatTag pix_fmt_bps_avi[] = {
> -    { AV_PIX_FMT_MONOWHITE, 1 },
> -    { AV_PIX_FMT_PAL8,    2 },
> -    { AV_PIX_FMT_PAL8,    4 },
> -    { AV_PIX_FMT_PAL8,    8 },
> -    { AV_PIX_FMT_RGB444LE, 12 },
> -    { AV_PIX_FMT_RGB555LE, 15 },
> -    { AV_PIX_FMT_RGB555LE, 16 },
> -    { AV_PIX_FMT_BGR24,  24 },
> -    { AV_PIX_FMT_BGRA,   32 },
> -    { AV_PIX_FMT_NONE,    0 },
> -};
> -
> -static const PixelFormatTag pix_fmt_bps_mov[] = {
> -    { AV_PIX_FMT_MONOWHITE, 1 },
> -    { AV_PIX_FMT_PAL8,      2 },
> -    { AV_PIX_FMT_PAL8,      4 },
> -    { AV_PIX_FMT_PAL8,      8 },
> -    // FIXME swscale does not support 16 bit in .mov, sample 16bit.mov
> -    // http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html
> -    { AV_PIX_FMT_RGB555BE, 16 },
> -    { AV_PIX_FMT_RGB24,    24 },
> -    { AV_PIX_FMT_ARGB,     32 },
> -    { AV_PIX_FMT_MONOWHITE,33 },
> -    { AV_PIX_FMT_NONE,      0 },
> -};
> -
>  #if LIBAVCODEC_VERSION_MAJOR < 55
>  enum AVPixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc)
>  {
> @@ -105,15 +78,15 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
>  
>      if (   avctx->codec_tag == MKTAG('r','a','w',' ')
>          || avctx->codec_tag == MKTAG('N','O','1','6'))
> -        avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_mov,
> +        avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_mov,
>                                        avctx->bits_per_coded_sample);
>      else if (avctx->codec_tag == MKTAG('W', 'R', 'A', 'W'))
> -        avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_avi,
> +        avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
>                                        avctx->bits_per_coded_sample);
>      else if (avctx->codec_tag && (avctx->codec_tag & 0xFFFFFF) != MKTAG('B','I','T', 0))
>          avctx->pix_fmt = avpriv_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag);
>      else if (avctx->pix_fmt == AV_PIX_FMT_NONE && avctx->bits_per_coded_sample)
> -        avctx->pix_fmt = avpriv_find_pix_fmt(pix_fmt_bps_avi,
> +        avctx->pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
>                                        avctx->bits_per_coded_sample);
>  
>      desc = av_pix_fmt_desc_get(avctx->pix_fmt);
> diff --git a/libavformat/avienc.c b/libavformat/avienc.c
> index 24a3821..d9d8f25 100644
> --- a/libavformat/avienc.c
> +++ b/libavformat/avienc.c
> @@ -32,6 +32,8 @@
>  #include "libavutil/dict.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/timestamp.h"
> +#include "libavutil/pixdesc.h"
> +#include "libavcodec/raw.h"
>  
>  /*
>   * TODO:
> @@ -296,6 +298,7 @@ static int avi_write_header(AVFormatContext *s)
>  
>          if (stream->codec_type != AVMEDIA_TYPE_DATA) {
>              int ret;
> +            enum AVPixelFormat pix_fmt;
>  
>              strf = ff_start_tag(pb, "strf");
>              switch (stream->codec_type) {

    > @@ -306,6 +309,13 @@ static int avi_write_header(AVFormatContext *s)
>                      break;
>              case AVMEDIA_TYPE_VIDEO:
>                  ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0, 0);
> +                pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
> +                                              stream->bits_per_coded_sample);
> +                if (   !stream->codec_tag
> +                    && stream->codec_id == AV_CODEC_ID_RAWVIDEO
> +                    && pix_fmt != stream->pix_fmt)

i think its not mandatory that pix_fmt is set by the application
so a unset pix_fmt should probably be allowed to pass

same for mov

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140410/9b76e982/attachment.asc>


More information about the ffmpeg-devel mailing list