Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-02-22 Thread James Almer




On 2/22/2022 3:40 PM, Vignesh Venkatasubramanian wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specifiation: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
animated AVIF yet).
3) Verfied to be valid by Compliance Warden:
https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure|   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 300 +++
  libavformat/movenc.h |   5 +
  4 files changed, 283 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 1535dc3c5b..87b380fe3a 100755
--- a/configure
+++ b/configure
@@ -3393,6 +3393,7 @@ asf_stream_muxer_select="asf_muxer"
  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
  avi_demuxer_select="riffdec exif"
  avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
  caf_demuxer_select="iso_media"
  caf_muxer_select="iso_media"
  dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d066a7745b..400c17afbd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
  extern const AVInputFormat  ff_av1_demuxer;
  extern const AVInputFormat  ff_avi_demuxer;
  extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
  extern const AVInputFormat  ff_avisynth_demuxer;
  extern const AVOutputFormat ff_avm2_muxer;
  extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 1a746a67fd..05537d1e78 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)
  
  avio_wb32(pb, 0);

  ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
MODE_AVIF);
  return update_size(pb, pos);
  }
  
@@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track, int prefer_icc)

  }
  }
  
-/* We should only ever be called by MOV or MP4. */

-av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+/* We should only ever be called for MOV, MP4 and AVIF. */
+av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);
  
  avio_wb32(pb, 0); /* size */

  ffio_wfourcc(pb, "colr");
-if (track->mode == MODE_MP4)
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
  ffio_wfourcc(pb, "nclx");
  else
  ffio_wfourcc(pb, "nclc");
@@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
  avio_wb16(pb, track->par->color_primaries);
  avio_wb16(pb, track->par->color_trc);
  avio_wb16(pb, track->par->color_space);
-if (track->mode == MODE_MP4) {
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
  avio_w8(pb, full_range << 7);
  }
@@ -2103,6 +2104,8 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
  av_strlcatf(compressor_name, len, " %d%c", track->par->height, 
interlaced ? 'i' : 'p');
  
  av_strlcatf(compressor_name, len, "%d", rate * (interlaced + 1));

+} else if (track->par->codec_id == AV_CODEC_ID_AV1 && track->mode == 
MODE_AVIF) {
+av_strlcatf(compressor_name, len, "libaom Encoder");
libaom is not the only AV1 encoder supported by libavcodec, a 
libavformat user could even not use a libavcodec based encoder to begin 
with, and then there's also the codec copy scenario where no encoder is 
used at all.


This should probably use the same path as MODE_MOV above if there's a 
key "encoder" in track->st->metadata, and write it.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-02-22 Thread Vignesh Venkatasubramanian
On Tue, Feb 22, 2022 at 12:03 PM James Almer  wrote:

>
>
> On 2/22/2022 3:40 PM, Vignesh Venkatasubramanian wrote:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> > animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> > https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >   configure|   1 +
> >   libavformat/allformats.c |   1 +
> >   libavformat/movenc.c | 300 +++
> >   libavformat/movenc.h |   5 +
> >   4 files changed, 283 insertions(+), 24 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 1535dc3c5b..87b380fe3a 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3393,6 +3393,7 @@ asf_stream_muxer_select="asf_muxer"
> >   av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >   avi_demuxer_select="riffdec exif"
> >   avi_muxer_select="riffenc"
> > +avif_muxer_select="mov_muxer"
> >   caf_demuxer_select="iso_media"
> >   caf_muxer_select="iso_media"
> >   dash_muxer_select="mp4_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index d066a7745b..400c17afbd 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >   extern const AVInputFormat  ff_av1_demuxer;
> >   extern const AVInputFormat  ff_avi_demuxer;
> >   extern const AVOutputFormat ff_avi_muxer;
> > +extern const AVOutputFormat ff_avif_muxer;
> >   extern const AVInputFormat  ff_avisynth_demuxer;
> >   extern const AVOutputFormat ff_avm2_muxer;
> >   extern const AVInputFormat  ff_avr_demuxer;
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 1a746a67fd..05537d1e78 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb,
> MOVTrack *track)
> >
> >   avio_wb32(pb, 0);
> >   ffio_wfourcc(pb, "av1C");
> > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode
> != MODE_AVIF);
> >   return update_size(pb, pos);
> >   }
> >
> > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb,
> MOVTrack *track, int prefer_icc)
> >   }
> >   }
> >
> > -/* We should only ever be called by MOV or MP4. */
> > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > +   track->mode == MODE_AVIF);
> >
> >   avio_wb32(pb, 0); /* size */
> >   ffio_wfourcc(pb, "colr");
> > -if (track->mode == MODE_MP4)
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >   ffio_wfourcc(pb, "nclx");
> >   else
> >   ffio_wfourcc(pb, "nclc");
> > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb,
> MOVTrack *track, int prefer_icc)
> >   avio_wb16(pb, track->par->color_primaries);
> >   avio_wb16(pb, track->par->color_trc);
> >   avio_wb16(pb, track->par->color_space);
> > -if (track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >   int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >   avio_w8(pb, full_range << 7);
> >   }
> > @@ -2103,6 +2104,8 @@ static void find_compressor(char *
> compressor_name, int len, MOVTrack *track)
> >   av_strlcatf(compressor_name, len, " %d%c", track->par->height,
> interlaced ? 'i' : 'p');
> >
> >   av_strlcatf(compressor_name, len, "%d", rate * (interlaced +
> 1));
> > +} else if (track->par->codec_id == AV_CODEC_ID_AV1 && track->mode
> == MODE_AVIF) {
> > +av_strlcatf(compressor_name, len, "libaom Encoder");
> libaom is not the only AV1 encoder supported by libavcodec, a
> libavformat user could even not use a libavcodec based encoder to begin
> with, and then there's also the codec copy scenario where no encoder is
> used at all.
>
> This should probably use the same path as MODE_MOV above if there's a
> key "encoder" in track->st->metadata, and write it.
>

Done.


> 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-02-24 Thread Vignesh Venkatasubramanian
On Tue, Feb 22, 2022 at 1:43 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 300 +++
>  libavformat/movenc.h |   5 +
>  4 files changed, 282 insertions(+), 25 deletions(-)
>
> diff --git a/configure b/configure
> index 1535dc3c5b..87b380fe3a 100755
> --- a/configure
> +++ b/configure
> @@ -3393,6 +3393,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index d066a7745b..400c17afbd 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 1a746a67fd..53258f0d11 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>
> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2123,6 +2124,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
>  avio_wb32(pb, 0); /* size */
>  if (mov->encryption_scheme != MOV_ENC_NONE) {
>  ffio_wfourcc(pb, "encv");
> +} else if (track->mode == MODE_AVIF) {
> +ffio_wfourcc(pb, "av01");
>  } else {
>  avio_wl32(pb, track->tag); // store it byteswapped
>  }
> @@ -2239,7 +2242,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
>   

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-01 Thread Vignesh Venkatasubramanian
On Thu, Feb 24, 2022 at 9:34 AM Vignesh Venkatasubramanian
 wrote:
>
> On Tue, Feb 22, 2022 at 1:43 PM Vignesh Venkatasubramanian
>  wrote:
> >
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 300 +++
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 282 insertions(+), 25 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 1535dc3c5b..87b380fe3a 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3393,6 +3393,7 @@ asf_stream_muxer_select="asf_muxer"
> >  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >  avi_demuxer_select="riffdec exif"
> >  avi_muxer_select="riffenc"
> > +avif_muxer_select="mov_muxer"
> >  caf_demuxer_select="iso_media"
> >  caf_muxer_select="iso_media"
> >  dash_muxer_select="mp4_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index d066a7745b..400c17afbd 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >  extern const AVInputFormat  ff_av1_demuxer;
> >  extern const AVInputFormat  ff_avi_demuxer;
> >  extern const AVOutputFormat ff_avi_muxer;
> > +extern const AVOutputFormat ff_avif_muxer;
> >  extern const AVInputFormat  ff_avisynth_demuxer;
> >  extern const AVOutputFormat ff_avm2_muxer;
> >  extern const AVInputFormat  ff_avr_demuxer;
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 1a746a67fd..53258f0d11 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > MOVTrack *track)
> >
> >  avio_wb32(pb, 0);
> >  ffio_wfourcc(pb, "av1C");
> > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> > MODE_AVIF);
> >  return update_size(pb, pos);
> >  }
> >
> > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  }
> >  }
> >
> > -/* We should only ever be called by MOV or MP4. */
> > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > +   track->mode == MODE_AVIF);
> >
> >  avio_wb32(pb, 0); /* size */
> >  ffio_wfourcc(pb, "colr");
> > -if (track->mode == MODE_MP4)
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >  ffio_wfourcc(pb, "nclx");
> >  else
> >  ffio_wfourcc(pb, "nclc");
> > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  avio_wb16(pb, track->par->color_primaries);
> >  avio_wb16(pb, track->par->color_trc);
> >  avio_wb16(pb, track->par->color_space);
> > -if (track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >  avio_w8(pb, full_range << 7);
> >  }
> > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >|| (track->par->width == 1440 && track->par->height == 
> > 1080)
> >|| (track->par->width == 1920 && track->par->height == 
> > 1080);
> >
> > -if (track->mode == MODE_MOV &&
> > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> >  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
> >  av_strlcpy(compressor_name, encoder->value, 32);
> >  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
> > xdcam_res) {
> > @@ -2123,6 +2124,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVMuxContex
> >  avio_wb32(pb, 0); /* size */
> >  if (mov->encryption_scheme != MOV_ENC_NONE) {
> >  

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-03 Thread James Almer

On 2/22/2022 6:43 PM, Vignesh Venkatasubramanian wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specifiation: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
animated AVIF yet).
3) Verfied to be valid by Compliance Warden:
https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure|   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 300 +++
  libavformat/movenc.h |   5 +
  4 files changed, 282 insertions(+), 25 deletions(-)


With a single frame i get no errors in that compliance tool, but when i 
encode an animated AVIF i get the following:


[heif][Rule #12] Error: CodingConstraintsBox ('ccst') shall be present once
[heif][Rule #28] Error: Wrong arity for boxes { ccst } in parents { avc1 
avc2 avc3 avc4 hev1 hev2 hvc1 hvc2 av01 }: expected in range [1-1], found 0
[heif][Rule #31] Error: 'msf1' brand: this file shall conform to HEIF 
(section 7.2)
[heif][Rule #31] Error: 'msf1' brand: 'iso8' shall be present among the 
compatible brands array
[heif][Rule #32] Error: 'mif1' brand: this file shall conform to HEIF 
section 6, check the other errors for details
[heif][Rule #33] Error: 'msf1' brand: this file shall conform to HEIF 
section 7, check the other errors for details


All but one of these should be solved by writing a ccst box after the 
av1C box in the sample entry. The missing one should be solved by 
writing the iso8 compatible brand.


The ccst box looks like it would need some bitstream information, so 
either you parse the packets to get it, or just hardcode sane defaults, 
considering it's used as a hint and it's not required for demuxing.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-03 Thread Vignesh Venkatasubramanian
On Thu, Mar 3, 2022 at 7:36 AM James Almer  wrote:
>
> On 2/22/2022 6:43 PM, Vignesh Venkatasubramanian wrote:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> > animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> > https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >   configure|   1 +
> >   libavformat/allformats.c |   1 +
> >   libavformat/movenc.c | 300 +++
> >   libavformat/movenc.h |   5 +
> >   4 files changed, 282 insertions(+), 25 deletions(-)
>
> With a single frame i get no errors in that compliance tool, but when i
> encode an animated AVIF i get the following:
>
> [heif][Rule #12] Error: CodingConstraintsBox ('ccst') shall be present once
> [heif][Rule #28] Error: Wrong arity for boxes { ccst } in parents { avc1
> avc2 avc3 avc4 hev1 hev2 hvc1 hvc2 av01 }: expected in range [1-1], found 0
> [heif][Rule #31] Error: 'msf1' brand: this file shall conform to HEIF
> (section 7.2)
> [heif][Rule #31] Error: 'msf1' brand: 'iso8' shall be present among the
> compatible brands array
> [heif][Rule #32] Error: 'mif1' brand: this file shall conform to HEIF
> section 6, check the other errors for details
> [heif][Rule #33] Error: 'msf1' brand: this file shall conform to HEIF
> section 7, check the other errors for details
>
> All but one of these should be solved by writing a ccst box after the
> av1C box in the sample entry. The missing one should be solved by
> writing the iso8 compatible brand.
>
> The ccst box looks like it would need some bitstream information, so
> either you parse the packets to get it, or just hardcode sane defaults,
> considering it's used as a hint and it's not required for demuxing.

I recently fixed these errors in libavif [1][2] (the reference AVIF
encoder). I was hoping to have a follow-up patch since i already
uploaded the existing patches. Since you have pointed this out now, i
have included the fix in this patch itself. The new patch will now
write the iso8 compatible brand and the ccst box with sane default
values. The file produced is now identical to the file produced by
libavif in terms of box structure.

Also, notice that the compliance tool still shows the following error
for animated avif:

[avif][Rule #3] Warning: [ItemId=1] still_picture flag set to 0
[avif][Rule #4] Warning: [ItemId=1] reduced_still_picture_header flag set to 0

I believe these are incorrect since it does not make sense to set
these flag to 0 for animated avif sequences. These warnings also show
up with files produced by libavif. So it is okay to ignore them. I
will file an issue with the compliance tool separately.

Please take another look, thanks!

[1] https://github.com/AOMediaCodec/libavif/pull/855
[2] https://github.com/AOMediaCodec/libavif/pull/856
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



-- 
Vignesh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-03 Thread James Almer




On 3/3/2022 4:20 PM, Vignesh Venkatasubramanian wrote:

On Thu, Mar 3, 2022 at 7:36 AM James Almer  wrote:


On 2/22/2022 6:43 PM, Vignesh Venkatasubramanian wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specifiation: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
 animated AVIF yet).
3) Verfied to be valid by Compliance Warden:
 https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
   configure|   1 +
   libavformat/allformats.c |   1 +
   libavformat/movenc.c | 300 +++
   libavformat/movenc.h |   5 +
   4 files changed, 282 insertions(+), 25 deletions(-)


With a single frame i get no errors in that compliance tool, but when i
encode an animated AVIF i get the following:

[heif][Rule #12] Error: CodingConstraintsBox ('ccst') shall be present once
[heif][Rule #28] Error: Wrong arity for boxes { ccst } in parents { avc1
avc2 avc3 avc4 hev1 hev2 hvc1 hvc2 av01 }: expected in range [1-1], found 0
[heif][Rule #31] Error: 'msf1' brand: this file shall conform to HEIF
(section 7.2)
[heif][Rule #31] Error: 'msf1' brand: 'iso8' shall be present among the
compatible brands array
[heif][Rule #32] Error: 'mif1' brand: this file shall conform to HEIF
section 6, check the other errors for details
[heif][Rule #33] Error: 'msf1' brand: this file shall conform to HEIF
section 7, check the other errors for details

All but one of these should be solved by writing a ccst box after the
av1C box in the sample entry. The missing one should be solved by
writing the iso8 compatible brand.

The ccst box looks like it would need some bitstream information, so
either you parse the packets to get it, or just hardcode sane defaults,
considering it's used as a hint and it's not required for demuxing.


I recently fixed these errors in libavif [1][2] (the reference AVIF
encoder). I was hoping to have a follow-up patch since i already
uploaded the existing patches. Since you have pointed this out now, i
have included the fix in this patch itself. The new patch will now
write the iso8 compatible brand and the ccst box with sane default
values. The file produced is now identical to the file produced by
libavif in terms of box structure.

Also, notice that the compliance tool still shows the following error
for animated avif:

[avif][Rule #3] Warning: [ItemId=1] still_picture flag set to 0
[avif][Rule #4] Warning: [ItemId=1] reduced_still_picture_header flag set to 0

I believe these are incorrect since it does not make sense to set
these flag to 0 for animated avif sequences. These warnings also show
up with files produced by libavif. So it is okay to ignore them. I
will file an issue with the compliance tool separately.


The compliance tool uses the 1.0.0 revision of the spec, and what you 
mentioned was removed in the current unfinished draft: 
https://github.com/AOMediaCodec/av1-avif/pull/112


I assume the tool will be updated once a new revision is released, so 
yes, we can ignore them.




Please take another look, thanks!


I noticed that using -still-picture 1 and passing more than one frame to 
the libaom encoder will succeed, despite you setting enccfg.g_limit to 
1, and encode every frame as key frames.
I'd expect the encoder would error out if you try to feed it more 
frames. Is it a libaom bug?




[1] https://github.com/AOMediaCodec/libavif/pull/855
[2] https://github.com/AOMediaCodec/libavif/pull/856

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".





___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-03 Thread Vignesh Venkatasubramanian
On Thu, Mar 3, 2022 at 11:46 AM James Almer  wrote:
>
>
>
> On 3/3/2022 4:20 PM, Vignesh Venkatasubramanian wrote:
> > On Thu, Mar 3, 2022 at 7:36 AM James Almer  wrote:
> >>
> >> On 2/22/2022 6:43 PM, Vignesh Venkatasubramanian wrote:
> >>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >>>
> >>> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >>>
> >>> Sample usage for still image:
> >>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >>>
> >>> Sample usage for animated AVIF image:
> >>> ffmpeg -i video.mp4 animated.avif
> >>>
> >>> We can re-use any of the AV1 encoding options that will make
> >>> sense for image encoding (like bitrate, tiles, encoding speed,
> >>> etc).
> >>>
> >>> The files generated by this muxer has been verified to be valid
> >>> AVIF files by the following:
> >>> 1) Displays on Chrome (both still and animated images).
> >>> 2) Displays on Firefox (only still images, firefox does not support
> >>>  animated AVIF yet).
> >>> 3) Verfied to be valid by Compliance Warden:
> >>>  https://github.com/gpac/ComplianceWarden
> >>>
> >>> Fixes the encoder/muxer part of Trac Ticket #7621
> >>>
> >>> Signed-off-by: Vignesh Venkatasubramanian 
> >>> ---
> >>>configure|   1 +
> >>>libavformat/allformats.c |   1 +
> >>>libavformat/movenc.c | 300 +++
> >>>libavformat/movenc.h |   5 +
> >>>4 files changed, 282 insertions(+), 25 deletions(-)
> >>
> >> With a single frame i get no errors in that compliance tool, but when i
> >> encode an animated AVIF i get the following:
> >>
> >> [heif][Rule #12] Error: CodingConstraintsBox ('ccst') shall be present once
> >> [heif][Rule #28] Error: Wrong arity for boxes { ccst } in parents { avc1
> >> avc2 avc3 avc4 hev1 hev2 hvc1 hvc2 av01 }: expected in range [1-1], found 0
> >> [heif][Rule #31] Error: 'msf1' brand: this file shall conform to HEIF
> >> (section 7.2)
> >> [heif][Rule #31] Error: 'msf1' brand: 'iso8' shall be present among the
> >> compatible brands array
> >> [heif][Rule #32] Error: 'mif1' brand: this file shall conform to HEIF
> >> section 6, check the other errors for details
> >> [heif][Rule #33] Error: 'msf1' brand: this file shall conform to HEIF
> >> section 7, check the other errors for details
> >>
> >> All but one of these should be solved by writing a ccst box after the
> >> av1C box in the sample entry. The missing one should be solved by
> >> writing the iso8 compatible brand.
> >>
> >> The ccst box looks like it would need some bitstream information, so
> >> either you parse the packets to get it, or just hardcode sane defaults,
> >> considering it's used as a hint and it's not required for demuxing.
> >
> > I recently fixed these errors in libavif [1][2] (the reference AVIF
> > encoder). I was hoping to have a follow-up patch since i already
> > uploaded the existing patches. Since you have pointed this out now, i
> > have included the fix in this patch itself. The new patch will now
> > write the iso8 compatible brand and the ccst box with sane default
> > values. The file produced is now identical to the file produced by
> > libavif in terms of box structure.
> >
> > Also, notice that the compliance tool still shows the following error
> > for animated avif:
> >
> > [avif][Rule #3] Warning: [ItemId=1] still_picture flag set to 0
> > [avif][Rule #4] Warning: [ItemId=1] reduced_still_picture_header flag set 
> > to 0
> >
> > I believe these are incorrect since it does not make sense to set
> > these flag to 0 for animated avif sequences. These warnings also show
> > up with files produced by libavif. So it is okay to ignore them. I
> > will file an issue with the compliance tool separately.
>
> The compliance tool uses the 1.0.0 revision of the spec, and what you
> mentioned was removed in the current unfinished draft:
> https://github.com/AOMediaCodec/av1-avif/pull/112
>
> I assume the tool will be updated once a new revision is released, so
> yes, we can ignore them.
>
> >
> > Please take another look, thanks!
>
> I noticed that using -still-picture 1 and passing more than one frame to
> the libaom encoder will succeed, despite you setting enccfg.g_limit to
> 1, and encode every frame as key frames.
> I'd expect the encoder would error out if you try to feed it more
> frames. Is it a libaom bug?
>

Hmm yeah it seems like libaom only uses the value to set the
still-picture sequence header values in 1-pass mode. I think in a way
it may be useful for us to be able to use AVIF output with the image2
muxer. For example, something like:

ffmpeg -i video.mp4 -still-picture 1 -c:v libaom-av1 -an -f image2
image-%02d.avif

This command does not work as of now, but I have some follow-up
patches to make the image2 muxer work with AVIF images.

> >
> > [1] https://github.com/AOMediaCodec/libavif/pull/855
> > [2] https://github.com/AOMediaCodec/libavif/pull/856
> >> ___

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-04 Thread James Almer

On 3/3/2022 4:16 PM, Vignesh Venkatasubramanian wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specifiation: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
animated AVIF yet).
3) Verfied to be valid by Compliance Warden:
https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure|   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 323 ---
  libavformat/movenc.h |   5 +
  4 files changed, 305 insertions(+), 25 deletions(-)

diff --git a/configure b/configure
index 8c69ab0c86..6d7020e96b 100755
--- a/configure
+++ b/configure
@@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
  avi_demuxer_select="riffdec exif"
  avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
  caf_demuxer_select="iso_media"
  caf_muxer_select="iso_media"
  dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d066a7745b..400c17afbd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
  extern const AVInputFormat  ff_av1_demuxer;
  extern const AVInputFormat  ff_avi_demuxer;
  extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
  extern const AVInputFormat  ff_avisynth_demuxer;
  extern const AVOutputFormat ff_avm2_muxer;
  extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 1a746a67fd..504403ab0b 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)
  
  avio_wb32(pb, 0);

  ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
MODE_AVIF);
  return update_size(pb, pos);
  }
  
@@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track, int prefer_icc)

  }
  }
  
-/* We should only ever be called by MOV or MP4. */

-av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+/* We should only ever be called for MOV, MP4 and AVIF. */
+av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);
  
  avio_wb32(pb, 0); /* size */

  ffio_wfourcc(pb, "colr");
-if (track->mode == MODE_MP4)
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
  ffio_wfourcc(pb, "nclx");
  else
  ffio_wfourcc(pb, "nclc");
@@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
  avio_wb16(pb, track->par->color_primaries);
  avio_wb16(pb, track->par->color_trc);
  avio_wb16(pb, track->par->color_space);
-if (track->mode == MODE_MP4) {
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
  avio_w8(pb, full_range << 7);
  }
@@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
|| (track->par->width == 1440 && track->par->height == 1080)
|| (track->par->width == 1920 && track->par->height == 
1080);
  
-if (track->mode == MODE_MOV &&

+if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
  av_strlcpy(compressor_name, encoder->value, 32);
  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
@@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
  }
  }
  
+static int mov_write_ccst_tag(AVIOContext *pb)

+{
+int64_t pos = avio_tell(pb);
+// Write sane defaults:
+// all_ref_pics_intra = 0 : all samples can use any type of reference.
+// intra_pred_used = 1 : intra prediction may or may not be used.
+// max_ref_per_pic = 15 : reserved value to indicate that any number of
+//reference images can be used.
+uint8_t ccstValue = (0 << 7) |  /* all_ref_pics_intra */
+(1 << 6) |  /* intra_pred_used */
+(15 << 2);  /* max_ref_p

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-04 Thread Vignesh Venkatasubramanian
On Fri, Mar 4, 2022 at 3:24 AM James Almer  wrote:
>
> On 3/3/2022 4:16 PM, Vignesh Venkatasubramanian wrote:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> > animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> > https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >   configure|   1 +
> >   libavformat/allformats.c |   1 +
> >   libavformat/movenc.c | 323 ---
> >   libavformat/movenc.h |   5 +
> >   4 files changed, 305 insertions(+), 25 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 8c69ab0c86..6d7020e96b 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> >   av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >   avi_demuxer_select="riffdec exif"
> >   avi_muxer_select="riffenc"
> > +avif_muxer_select="mov_muxer"
> >   caf_demuxer_select="iso_media"
> >   caf_muxer_select="iso_media"
> >   dash_muxer_select="mp4_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index d066a7745b..400c17afbd 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >   extern const AVInputFormat  ff_av1_demuxer;
> >   extern const AVInputFormat  ff_avi_demuxer;
> >   extern const AVOutputFormat ff_avi_muxer;
> > +extern const AVOutputFormat ff_avif_muxer;
> >   extern const AVInputFormat  ff_avisynth_demuxer;
> >   extern const AVOutputFormat ff_avm2_muxer;
> >   extern const AVInputFormat  ff_avr_demuxer;
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 1a746a67fd..504403ab0b 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > MOVTrack *track)
> >
> >   avio_wb32(pb, 0);
> >   ffio_wfourcc(pb, "av1C");
> > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> > MODE_AVIF);
> >   return update_size(pb, pos);
> >   }
> >
> > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >   }
> >   }
> >
> > -/* We should only ever be called by MOV or MP4. */
> > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > +   track->mode == MODE_AVIF);
> >
> >   avio_wb32(pb, 0); /* size */
> >   ffio_wfourcc(pb, "colr");
> > -if (track->mode == MODE_MP4)
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >   ffio_wfourcc(pb, "nclx");
> >   else
> >   ffio_wfourcc(pb, "nclc");
> > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >   avio_wb16(pb, track->par->color_primaries);
> >   avio_wb16(pb, track->par->color_trc);
> >   avio_wb16(pb, track->par->color_space);
> > -if (track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >   int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >   avio_w8(pb, full_range << 7);
> >   }
> > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> > || (track->par->width == 1440 && track->par->height == 
> > 1080)
> > || (track->par->width == 1920 && track->par->height == 
> > 1080);
> >
> > -if (track->mode == MODE_MOV &&
> > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> >   (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) 
> > {
> >   av_strlcpy(compressor_name, encoder->value, 32);
> >   } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
> > xdcam_res) {
> > @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >   }
> >   }
> >
> > +static int mov_write_ccst_tag(AVIOContext *pb)
> > +{
> > +int6

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-09 Thread Vignesh Venkatasubramanian
On Fri, Mar 4, 2022 at 9:54 AM Vignesh Venkatasubramanian
 wrote:
>
> On Fri, Mar 4, 2022 at 3:24 AM James Almer  wrote:
> >
> > On 3/3/2022 4:16 PM, Vignesh Venkatasubramanian wrote:
> > > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> > >
> > > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> > >
> > > Sample usage for still image:
> > > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> > >
> > > Sample usage for animated AVIF image:
> > > ffmpeg -i video.mp4 animated.avif
> > >
> > > We can re-use any of the AV1 encoding options that will make
> > > sense for image encoding (like bitrate, tiles, encoding speed,
> > > etc).
> > >
> > > The files generated by this muxer has been verified to be valid
> > > AVIF files by the following:
> > > 1) Displays on Chrome (both still and animated images).
> > > 2) Displays on Firefox (only still images, firefox does not support
> > > animated AVIF yet).
> > > 3) Verfied to be valid by Compliance Warden:
> > > https://github.com/gpac/ComplianceWarden
> > >
> > > Fixes the encoder/muxer part of Trac Ticket #7621
> > >
> > > Signed-off-by: Vignesh Venkatasubramanian 
> > > ---
> > >   configure|   1 +
> > >   libavformat/allformats.c |   1 +
> > >   libavformat/movenc.c | 323 ---
> > >   libavformat/movenc.h |   5 +
> > >   4 files changed, 305 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/configure b/configure
> > > index 8c69ab0c86..6d7020e96b 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> > >   av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> > >   avi_demuxer_select="riffdec exif"
> > >   avi_muxer_select="riffenc"
> > > +avif_muxer_select="mov_muxer"
> > >   caf_demuxer_select="iso_media"
> > >   caf_muxer_select="iso_media"
> > >   dash_muxer_select="mp4_muxer"
> > > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > > index d066a7745b..400c17afbd 100644
> > > --- a/libavformat/allformats.c
> > > +++ b/libavformat/allformats.c
> > > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> > >   extern const AVInputFormat  ff_av1_demuxer;
> > >   extern const AVInputFormat  ff_avi_demuxer;
> > >   extern const AVOutputFormat ff_avi_muxer;
> > > +extern const AVOutputFormat ff_avif_muxer;
> > >   extern const AVInputFormat  ff_avisynth_demuxer;
> > >   extern const AVOutputFormat ff_avm2_muxer;
> > >   extern const AVInputFormat  ff_avr_demuxer;
> > > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > > index 1a746a67fd..504403ab0b 100644
> > > --- a/libavformat/movenc.c
> > > +++ b/libavformat/movenc.c
> > > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > > MOVTrack *track)
> > >
> > >   avio_wb32(pb, 0);
> > >   ffio_wfourcc(pb, "av1C");
> > > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode 
> > > != MODE_AVIF);
> > >   return update_size(pb, pos);
> > >   }
> > >
> > > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > MOVTrack *track, int prefer_icc)
> > >   }
> > >   }
> > >
> > > -/* We should only ever be called by MOV or MP4. */
> > > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > > +   track->mode == MODE_AVIF);
> > >
> > >   avio_wb32(pb, 0); /* size */
> > >   ffio_wfourcc(pb, "colr");
> > > -if (track->mode == MODE_MP4)
> > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> > >   ffio_wfourcc(pb, "nclx");
> > >   else
> > >   ffio_wfourcc(pb, "nclc");
> > > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > MOVTrack *track, int prefer_icc)
> > >   avio_wb16(pb, track->par->color_primaries);
> > >   avio_wb16(pb, track->par->color_trc);
> > >   avio_wb16(pb, track->par->color_space);
> > > -if (track->mode == MODE_MP4) {
> > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> > >   int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> > >   avio_w8(pb, full_range << 7);
> > >   }
> > > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > > int len, MOVTrack *track)
> > > || (track->par->width == 1440 && track->par->height 
> > > == 1080)
> > > || (track->par->width == 1920 && track->par->height 
> > > == 1080);
> > >
> > > -if (track->mode == MODE_MOV &&
> > > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> > >   (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 
> > > 0))) {
> > >   av_strlcpy(compressor_name, encoder->value, 32);

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-10 Thread Andreas Rheinhardt
Vignesh Venkatasubramanian:
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> 
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> 
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> 
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
> 
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
> 
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
> 
> Fixes the encoder/muxer part of Trac Ticket #7621
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 323 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 305 insertions(+), 25 deletions(-)
> 
> diff --git a/configure b/configure
> index 8c69ab0c86..6d7020e96b 100755
> --- a/configure
> +++ b/configure
> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index d066a7745b..400c17afbd 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 1a746a67fd..504403ab0b 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>  
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>  
> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>  
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>  
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>  
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
> int len, MOVTrack *track)
>  }
>  }
>  
> +static int mov_write_ccst_tag(AVIOContext *pb)
> +{
> +int64_t pos = avio_tell(pb);
> +// Write sane defaults:
> +// all_ref_pics_intra = 0 : all samples can use any type of reference.
> +// intra_pred_used = 1 : intra prediction may or may not be used.
> +// max_ref_per_pic = 15 : reserved value to indicate that any number of
> +//reference images can be used.
> + 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-10 Thread Vignesh Venkatasubramanian
On Thu, Mar 10, 2022 at 8:01 AM Andreas Rheinhardt
 wrote:
>
> Vignesh Venkatasubramanian:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 323 ---
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 305 insertions(+), 25 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 8c69ab0c86..6d7020e96b 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> >  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >  avi_demuxer_select="riffdec exif"
> >  avi_muxer_select="riffenc"
> > +avif_muxer_select="mov_muxer"
> >  caf_demuxer_select="iso_media"
> >  caf_muxer_select="iso_media"
> >  dash_muxer_select="mp4_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index d066a7745b..400c17afbd 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >  extern const AVInputFormat  ff_av1_demuxer;
> >  extern const AVInputFormat  ff_avi_demuxer;
> >  extern const AVOutputFormat ff_avi_muxer;
> > +extern const AVOutputFormat ff_avif_muxer;
> >  extern const AVInputFormat  ff_avisynth_demuxer;
> >  extern const AVOutputFormat ff_avm2_muxer;
> >  extern const AVInputFormat  ff_avr_demuxer;
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 1a746a67fd..504403ab0b 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > MOVTrack *track)
> >
> >  avio_wb32(pb, 0);
> >  ffio_wfourcc(pb, "av1C");
> > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> > MODE_AVIF);
> >  return update_size(pb, pos);
> >  }
> >
> > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  }
> >  }
> >
> > -/* We should only ever be called by MOV or MP4. */
> > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > +   track->mode == MODE_AVIF);
> >
> >  avio_wb32(pb, 0); /* size */
> >  ffio_wfourcc(pb, "colr");
> > -if (track->mode == MODE_MP4)
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >  ffio_wfourcc(pb, "nclx");
> >  else
> >  ffio_wfourcc(pb, "nclc");
> > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  avio_wb16(pb, track->par->color_primaries);
> >  avio_wb16(pb, track->par->color_trc);
> >  avio_wb16(pb, track->par->color_space);
> > -if (track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >  avio_w8(pb, full_range << 7);
> >  }
> > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >|| (track->par->width == 1440 && track->par->height == 
> > 1080)
> >|| (track->par->width == 1920 && track->par->height == 
> > 1080);
> >
> > -if (track->mode == MODE_MOV &&
> > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> >  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
> >  av_strlcpy(compressor_name, encoder->value, 32);
> >  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
> > xdcam_res) {
> > @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >  }
> >  }
> >
> > +static int mov_write_ccst_tag(AVIOContext *pb)
> > +{
> > +int64_t pos = avio_tell(pb);
> > +// Write sane defaults:
> > +

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-15 Thread Vignesh Venkatasubramanian
On Thu, Mar 10, 2022 at 10:14 AM Vignesh Venkatasubramanian
 wrote:
>
> On Thu, Mar 10, 2022 at 8:01 AM Andreas Rheinhardt
>  wrote:
> >
> > Vignesh Venkatasubramanian:
> > > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> > >
> > > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> > >
> > > Sample usage for still image:
> > > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> > >
> > > Sample usage for animated AVIF image:
> > > ffmpeg -i video.mp4 animated.avif
> > >
> > > We can re-use any of the AV1 encoding options that will make
> > > sense for image encoding (like bitrate, tiles, encoding speed,
> > > etc).
> > >
> > > The files generated by this muxer has been verified to be valid
> > > AVIF files by the following:
> > > 1) Displays on Chrome (both still and animated images).
> > > 2) Displays on Firefox (only still images, firefox does not support
> > >animated AVIF yet).
> > > 3) Verfied to be valid by Compliance Warden:
> > >https://github.com/gpac/ComplianceWarden
> > >
> > > Fixes the encoder/muxer part of Trac Ticket #7621
> > >
> > > Signed-off-by: Vignesh Venkatasubramanian 
> > > ---
> > >  configure|   1 +
> > >  libavformat/allformats.c |   1 +
> > >  libavformat/movenc.c | 323 ---
> > >  libavformat/movenc.h |   5 +
> > >  4 files changed, 305 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/configure b/configure
> > > index 8c69ab0c86..6d7020e96b 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> > >  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> > >  avi_demuxer_select="riffdec exif"
> > >  avi_muxer_select="riffenc"
> > > +avif_muxer_select="mov_muxer"
> > >  caf_demuxer_select="iso_media"
> > >  caf_muxer_select="iso_media"
> > >  dash_muxer_select="mp4_muxer"
> > > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > > index d066a7745b..400c17afbd 100644
> > > --- a/libavformat/allformats.c
> > > +++ b/libavformat/allformats.c
> > > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> > >  extern const AVInputFormat  ff_av1_demuxer;
> > >  extern const AVInputFormat  ff_avi_demuxer;
> > >  extern const AVOutputFormat ff_avi_muxer;
> > > +extern const AVOutputFormat ff_avif_muxer;
> > >  extern const AVInputFormat  ff_avisynth_demuxer;
> > >  extern const AVOutputFormat ff_avm2_muxer;
> > >  extern const AVInputFormat  ff_avr_demuxer;
> > > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > > index 1a746a67fd..504403ab0b 100644
> > > --- a/libavformat/movenc.c
> > > +++ b/libavformat/movenc.c
> > > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > > MOVTrack *track)
> > >
> > >  avio_wb32(pb, 0);
> > >  ffio_wfourcc(pb, "av1C");
> > > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode 
> > > != MODE_AVIF);
> > >  return update_size(pb, pos);
> > >  }
> > >
> > > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > MOVTrack *track, int prefer_icc)
> > >  }
> > >  }
> > >
> > > -/* We should only ever be called by MOV or MP4. */
> > > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > > +   track->mode == MODE_AVIF);
> > >
> > >  avio_wb32(pb, 0); /* size */
> > >  ffio_wfourcc(pb, "colr");
> > > -if (track->mode == MODE_MP4)
> > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> > >  ffio_wfourcc(pb, "nclx");
> > >  else
> > >  ffio_wfourcc(pb, "nclc");
> > > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > MOVTrack *track, int prefer_icc)
> > >  avio_wb16(pb, track->par->color_primaries);
> > >  avio_wb16(pb, track->par->color_trc);
> > >  avio_wb16(pb, track->par->color_space);
> > > -if (track->mode == MODE_MP4) {
> > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> > >  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> > >  avio_w8(pb, full_range << 7);
> > >  }
> > > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > > int len, MOVTrack *track)
> > >|| (track->par->width == 1440 && track->par->height == 
> > > 1080)
> > >|| (track->par->width == 1920 && track->par->height == 
> > > 1080);
> > >
> > > -if (track->mode == MODE_MOV &&
> > > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> > >  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 
> > > 0))) {
> > >  av_strlcpy(compressor_name, encoder->value, 32);
> > >  } else if (track->par->codec_id == AV_CODEC

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-21 Thread Vignesh Venkatasubramanian
On Tue, Mar 15, 2022 at 8:59 AM Vignesh Venkatasubramanian
 wrote:
>
> On Thu, Mar 10, 2022 at 10:14 AM Vignesh Venkatasubramanian
>  wrote:
> >
> > On Thu, Mar 10, 2022 at 8:01 AM Andreas Rheinhardt
> >  wrote:
> > >
> > > Vignesh Venkatasubramanian:
> > > > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> > > >
> > > > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> > > >
> > > > Sample usage for still image:
> > > > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> > > >
> > > > Sample usage for animated AVIF image:
> > > > ffmpeg -i video.mp4 animated.avif
> > > >
> > > > We can re-use any of the AV1 encoding options that will make
> > > > sense for image encoding (like bitrate, tiles, encoding speed,
> > > > etc).
> > > >
> > > > The files generated by this muxer has been verified to be valid
> > > > AVIF files by the following:
> > > > 1) Displays on Chrome (both still and animated images).
> > > > 2) Displays on Firefox (only still images, firefox does not support
> > > >animated AVIF yet).
> > > > 3) Verfied to be valid by Compliance Warden:
> > > >https://github.com/gpac/ComplianceWarden
> > > >
> > > > Fixes the encoder/muxer part of Trac Ticket #7621
> > > >
> > > > Signed-off-by: Vignesh Venkatasubramanian 
> > > > ---
> > > >  configure|   1 +
> > > >  libavformat/allformats.c |   1 +
> > > >  libavformat/movenc.c | 323 ---
> > > >  libavformat/movenc.h |   5 +
> > > >  4 files changed, 305 insertions(+), 25 deletions(-)
> > > >
> > > > diff --git a/configure b/configure
> > > > index 8c69ab0c86..6d7020e96b 100755
> > > > --- a/configure
> > > > +++ b/configure
> > > > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> > > >  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> > > >  avi_demuxer_select="riffdec exif"
> > > >  avi_muxer_select="riffenc"
> > > > +avif_muxer_select="mov_muxer"
> > > >  caf_demuxer_select="iso_media"
> > > >  caf_muxer_select="iso_media"
> > > >  dash_muxer_select="mp4_muxer"
> > > > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > > > index d066a7745b..400c17afbd 100644
> > > > --- a/libavformat/allformats.c
> > > > +++ b/libavformat/allformats.c
> > > > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> > > >  extern const AVInputFormat  ff_av1_demuxer;
> > > >  extern const AVInputFormat  ff_avi_demuxer;
> > > >  extern const AVOutputFormat ff_avi_muxer;
> > > > +extern const AVOutputFormat ff_avif_muxer;
> > > >  extern const AVInputFormat  ff_avisynth_demuxer;
> > > >  extern const AVOutputFormat ff_avm2_muxer;
> > > >  extern const AVInputFormat  ff_avr_demuxer;
> > > > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > > > index 1a746a67fd..504403ab0b 100644
> > > > --- a/libavformat/movenc.c
> > > > +++ b/libavformat/movenc.c
> > > > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > > > MOVTrack *track)
> > > >
> > > >  avio_wb32(pb, 0);
> > > >  ffio_wfourcc(pb, "av1C");
> > > > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > > > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 
> > > > track->mode != MODE_AVIF);
> > > >  return update_size(pb, pos);
> > > >  }
> > > >
> > > > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > > MOVTrack *track, int prefer_icc)
> > > >  }
> > > >  }
> > > >
> > > > -/* We should only ever be called by MOV or MP4. */
> > > > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > > > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > > > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > > > +   track->mode == MODE_AVIF);
> > > >
> > > >  avio_wb32(pb, 0); /* size */
> > > >  ffio_wfourcc(pb, "colr");
> > > > -if (track->mode == MODE_MP4)
> > > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> > > >  ffio_wfourcc(pb, "nclx");
> > > >  else
> > > >  ffio_wfourcc(pb, "nclc");
> > > > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > > MOVTrack *track, int prefer_icc)
> > > >  avio_wb16(pb, track->par->color_primaries);
> > > >  avio_wb16(pb, track->par->color_trc);
> > > >  avio_wb16(pb, track->par->color_space);
> > > > -if (track->mode == MODE_MP4) {
> > > > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> > > >  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> > > >  avio_w8(pb, full_range << 7);
> > > >  }
> > > > @@ -2085,7 +2086,7 @@ static void find_compressor(char * 
> > > > compressor_name, int len, MOVTrack *track)
> > > >|| (track->par->width == 1440 && track->par->height 
> > > > == 1080)
> > > >|| (track->par->width == 1920 && track->par->height 
> > > > == 1080);
> > > >
> > > > -if (track->mod

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-21 Thread Andreas Rheinhardt
Vignesh Venkatasubramanian:
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> 
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> 
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> 
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
> 
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
> 
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
> 
> Fixes the encoder/muxer part of Trac Ticket #7621
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 341 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 322 insertions(+), 26 deletions(-)
> 
> diff --git a/configure b/configure
> index 8c69ab0c86..6d7020e96b 100755
> --- a/configure
> +++ b/configure
> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index d066a7745b..400c17afbd 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 1a746a67fd..ff41579300 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>  
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>  
> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>  
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>  
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>  
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
> int len, MOVTrack *track)
>  }
>  }
>  
> +static int mov_write_ccst_tag(AVIOContext *pb)
> +{
> +int64_t pos = avio_tell(pb);
> +// Write sane defaults:
> +// all_ref_pics_intra = 0 : all samples can use any type of reference.
> +// intra_pred_used = 1 : intra prediction may or may not be used.
> +// max_ref_per_pic = 15 : reserved value to indicate that any number of
> +//reference images can be used.
> + 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-22 Thread Vignesh Venkatasubramanian
On Mon, Mar 21, 2022 at 1:46 PM Andreas Rheinhardt
 wrote:
>
> Vignesh Venkatasubramanian:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 341 ---
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 322 insertions(+), 26 deletions(-)
> >
> > diff --git a/configure b/configure
> > index 8c69ab0c86..6d7020e96b 100755
> > --- a/configure
> > +++ b/configure
> > @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> >  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >  avi_demuxer_select="riffdec exif"
> >  avi_muxer_select="riffenc"
> > +avif_muxer_select="mov_muxer"
> >  caf_demuxer_select="iso_media"
> >  caf_muxer_select="iso_media"
> >  dash_muxer_select="mp4_muxer"
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index d066a7745b..400c17afbd 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >  extern const AVInputFormat  ff_av1_demuxer;
> >  extern const AVInputFormat  ff_avi_demuxer;
> >  extern const AVOutputFormat ff_avi_muxer;
> > +extern const AVOutputFormat ff_avif_muxer;
> >  extern const AVInputFormat  ff_avisynth_demuxer;
> >  extern const AVOutputFormat ff_avm2_muxer;
> >  extern const AVInputFormat  ff_avr_demuxer;
> > diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > index 1a746a67fd..ff41579300 100644
> > --- a/libavformat/movenc.c
> > +++ b/libavformat/movenc.c
> > @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > MOVTrack *track)
> >
> >  avio_wb32(pb, 0);
> >  ffio_wfourcc(pb, "av1C");
> > -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> > MODE_AVIF);
> >  return update_size(pb, pos);
> >  }
> >
> > @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  }
> >  }
> >
> > -/* We should only ever be called by MOV or MP4. */
> > -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > +/* We should only ever be called for MOV, MP4 and AVIF. */
> > +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > +   track->mode == MODE_AVIF);
> >
> >  avio_wb32(pb, 0); /* size */
> >  ffio_wfourcc(pb, "colr");
> > -if (track->mode == MODE_MP4)
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >  ffio_wfourcc(pb, "nclx");
> >  else
> >  ffio_wfourcc(pb, "nclc");
> > @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > MOVTrack *track, int prefer_icc)
> >  avio_wb16(pb, track->par->color_primaries);
> >  avio_wb16(pb, track->par->color_trc);
> >  avio_wb16(pb, track->par->color_space);
> > -if (track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >  avio_w8(pb, full_range << 7);
> >  }
> > @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >|| (track->par->width == 1440 && track->par->height == 
> > 1080)
> >|| (track->par->width == 1920 && track->par->height == 
> > 1080);
> >
> > -if (track->mode == MODE_MOV &&
> > +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> >  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
> >  av_strlcpy(compressor_name, encoder->value, 32);
> >  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
> > xdcam_res) {
> > @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
> > int len, MOVTrack *track)
> >  }
> >  }
> >
> > +static int mov_write_ccst_tag(AVIOContext *pb)
> > +{
> > +int64_t pos = avio_tell(pb);
> > +// Write sane defaults:
> > +

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-03-28 Thread Vignesh Venkatasubramanian
On Tue, Mar 22, 2022 at 9:46 AM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 337 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 319 insertions(+), 25 deletions(-)
>
> diff --git a/configure b/configure
> index dff53e88bc..5aaf198704 100755
> --- a/configure
> +++ b/configure
> @@ -3394,6 +3394,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 587ad59b3c..29e58353ee 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 1c31f48abb..b9b424bc97 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1306,7 +1306,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>
> @@ -2007,12 +2007,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2022,7 +2023,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2088,7 +2089,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2109,6 +2110,25 @@ static void find_compressor(char * compressor_name, 
> int len, MOVTrack *track)
>  }
>  }
>
> +static int mov_write_ccst_tag(AVIOContext *pb)
> +{
> +int64_t pos = avio_tell(pb);
> +// Write sane defaults:
> +// all_ref_pics_intra = 0 : all samples can use any type of reference.
> +// intra_pred_used = 1 : intra prediction may or may not be used.
> +// max_ref_per_pic = 15 : reserved value to indicate that any number of
> +//reference ima

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-07 Thread Vignesh Venkatasubramanian
On Mon, Mar 28, 2022 at 1:49 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 337 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 319 insertions(+), 25 deletions(-)
>
> diff --git a/configure b/configure
> index e4d36aa639..b9a79d8982 100755
> --- a/configure
> +++ b/configure
> @@ -3396,6 +3396,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 587ad59b3c..29e58353ee 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 70ceb0dea4..920f3dcf25 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1306,7 +1306,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>
> @@ -2007,12 +2007,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2022,7 +2023,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2088,7 +2089,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2109,6 +2110,25 @@ static void find_compressor(char * compressor_name, 
> int len, MOVTrack *track)
>  }
>  }
>
> +static int mov_write_ccst_tag(AVIOContext *pb)
> +{
> +int64_t pos = avio_tell(pb);
> +// Write sane defaults:
> +// all_ref_pics_intra = 0 : all samples can use any type of reference.
> +// intra_pred_used = 1 : intra prediction may or may not be used.
> +// max_ref_per_pic = 15 : reserved value to indicate that any number of
> +//reference ima

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread James Zern
On Mon, Mar 28, 2022 at 1:49 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
>

Specification

> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verfied to be valid by Compliance Warden:

Verified

>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 337 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 319 insertions(+), 25 deletions(-)
>

There might be some other issues, you can try tools/patcheck.

> [...]
> @@ -5068,6 +5231,31 @@ static int mov_write_ftyp_tag(AVIOContext *pb, 
> AVFormatContext *s)
>  // compatible brand a second time.
>  if (mov->mode == MODE_ISM) {
>  ffio_wfourcc(pb, "piff");
> +} else if (mov->mode == MODE_AVIF) {
> +const AVPixFmtDescriptor *pix_fmt_desc =
> +av_pix_fmt_desc_get(s->streams[0]->codecpar->format);
> +const int depth = pix_fmt_desc->comp[0].depth;
> +if (mov->is_animated_avif) {
> +// For animated AVIF, major brand is "avis". Add "avif" as a
> +// compatible brand.
> +ffio_wfourcc(pb, "avif");
> +ffio_wfourcc(pb, "msf1");
> +ffio_wfourcc(pb, "iso8");
> +}
> +ffio_wfourcc(pb, "mif1");
> +ffio_wfourcc(pb, "miaf");
> +if (depth == 8 || depth == 10) {
> +// MA1B and MA1A brands are based on AV1 profile. Short hand for
> +// computing that is based on chroma subsampling type. 420 chroma
> +// subsampling is MA1B.  444 chroma subsampling is MA1A.
> +if (pix_fmt_desc->log2_chroma_w == 0 && 
> pix_fmt_desc->log2_chroma_h == 0) {

!... is the preferred style.

> @@ -6773,12 +6983,13 @@ static int mov_init(AVFormatContext *s)
>  pix_fmt == AV_PIX_FMT_MONOWHITE ||
>  pix_fmt == AV_PIX_FMT_MONOBLACK;
>  }
> -if (track->par->codec_id == AV_CODEC_ID_VP9 ||
> -track->par->codec_id == AV_CODEC_ID_AV1) {
> -if (track->mode != MODE_MP4) {
> -av_log(s, AV_LOG_ERROR, "%s only supported in MP4.\n", 
> avcodec_get_name(track->par->codec_id));
> -return AVERROR(EINVAL);
> -}
> +if (track->par->codec_id == AV_CODEC_ID_VP9 && track->mode != 
> MODE_MP4) {
> +av_log(s, AV_LOG_ERROR, "%s only supported in MP4.\n", 
> avcodec_get_name(track->par->codec_id));
> +   return AVERROR(EINVAL);

This is indented with tabs.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread Vignesh Venkatasubramanian
On Wed, Apr 13, 2022 at 10:22 AM James Zern  wrote:
>
> On Mon, Mar 28, 2022 at 1:49 PM Vignesh Venkatasubramanian
>  wrote:
> >
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >
>
> Specification
>

Fixed.

> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verfied to be valid by Compliance Warden:
>
> Verified
>

Fixed.

> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 337 ---
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 319 insertions(+), 25 deletions(-)
> >
>
> There might be some other issues, you can try tools/patcheck.
>

Thanks, i ran this and only found a couple of other "} before else-if"
warnings. In those cases, i was just being consistent with the code
around it.

> > [...]
> > @@ -5068,6 +5231,31 @@ static int mov_write_ftyp_tag(AVIOContext *pb, 
> > AVFormatContext *s)
> >  // compatible brand a second time.
> >  if (mov->mode == MODE_ISM) {
> >  ffio_wfourcc(pb, "piff");
> > +} else if (mov->mode == MODE_AVIF) {
> > +const AVPixFmtDescriptor *pix_fmt_desc =
> > +av_pix_fmt_desc_get(s->streams[0]->codecpar->format);
> > +const int depth = pix_fmt_desc->comp[0].depth;
> > +if (mov->is_animated_avif) {
> > +// For animated AVIF, major brand is "avis". Add "avif" as a
> > +// compatible brand.
> > +ffio_wfourcc(pb, "avif");
> > +ffio_wfourcc(pb, "msf1");
> > +ffio_wfourcc(pb, "iso8");
> > +}
> > +ffio_wfourcc(pb, "mif1");
> > +ffio_wfourcc(pb, "miaf");
> > +if (depth == 8 || depth == 10) {
> > +// MA1B and MA1A brands are based on AV1 profile. Short hand 
> > for
> > +// computing that is based on chroma subsampling type. 420 
> > chroma
> > +// subsampling is MA1B.  444 chroma subsampling is MA1A.
> > +if (pix_fmt_desc->log2_chroma_w == 0 && 
> > pix_fmt_desc->log2_chroma_h == 0) {
>
> !... is the preferred style.

Done.

>
> > @@ -6773,12 +6983,13 @@ static int mov_init(AVFormatContext *s)
> >  pix_fmt == AV_PIX_FMT_MONOWHITE ||
> >  pix_fmt == AV_PIX_FMT_MONOBLACK;
> >  }
> > -if (track->par->codec_id == AV_CODEC_ID_VP9 ||
> > -track->par->codec_id == AV_CODEC_ID_AV1) {
> > -if (track->mode != MODE_MP4) {
> > -av_log(s, AV_LOG_ERROR, "%s only supported in MP4.\n", 
> > avcodec_get_name(track->par->codec_id));
> > -return AVERROR(EINVAL);
> > -}
> > +if (track->par->codec_id == AV_CODEC_ID_VP9 && track->mode != 
> > MODE_MP4) {
> > +av_log(s, AV_LOG_ERROR, "%s only supported in MP4.\n", 
> > avcodec_get_name(track->par->codec_id));
> > +   return AVERROR(EINVAL);
>
> This is indented with tabs.

Oops, fixed.

-- 
Vignesh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread Andreas Rheinhardt
Vignesh Venkatasubramanian:
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> 
> AVIF Specification: https://aomediacodec.github.io/av1-avif
> 
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> 
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
> 
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
> 
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
> 
> Fixes the encoder/muxer part of Trac Ticket #7621
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 337 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 319 insertions(+), 25 deletions(-)
> 
> +static int avif_write_trailer(AVFormatContext *s)
> +{
> +AVIOContext *pb = s->pb;
> +MOVMuxContext *mov = s->priv_data;
> +int64_t pos_backup, mdat_pos;
> +uint8_t *buf;
> +int buf_size, moov_size;
> +
> +if (mov->moov_written) return 0;

Can it happen that moov_written is true? What happens if it is? (I
presume the file to be invalid.)

> +
> +mov->is_animated_avif = s->streams[0]->nb_frames > 1;
> +mov_write_identification(pb, s);
> +mov_write_meta_tag(pb, mov, s);
> +
> +moov_size = get_moov_size(s);
> +mov->tracks[0].data_offset = avio_tell(pb) + moov_size + 8;
> +
> +if (mov->is_animated_avif) {
> +int ret;
> +if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
> +return ret;
> +}
> +
> +buf_size = avio_get_dyn_buf(mov->mdat_buf, &buf);
> +avio_wb32(pb, buf_size + 8);
> +ffio_wfourcc(pb, "mdat");
> +mdat_pos = avio_tell(pb);
> +
> +if (mdat_pos != (uint32_t)mdat_pos) {
> +av_log(s, AV_LOG_ERROR, "mdat offset does not fit in 32 bits\n");
> +return AVERROR_INVALIDDATA;
> +}
> +
> +avio_write(pb, buf, buf_size);
> +
> +// write extent offset.
> +pos_backup = avio_tell(pb);
> +avio_seek(pb, mov->avif_extent_pos, SEEK_SET);
> +avio_wb32(pb, mdat_pos); /* rewrite offset */
> +avio_seek(pb, pos_backup, SEEK_SET);
> +
> +return 0;
> +}
> +

- Andreas
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread Andreas Rheinhardt
Vignesh Venkatasubramanian:
> On Mon, Mar 21, 2022 at 1:46 PM Andreas Rheinhardt
>  wrote:
>>
>> Vignesh Venkatasubramanian:
>>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>>>
>>> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
>>>
>>> Sample usage for still image:
>>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>>>
>>> Sample usage for animated AVIF image:
>>> ffmpeg -i video.mp4 animated.avif
>>>
>>> We can re-use any of the AV1 encoding options that will make
>>> sense for image encoding (like bitrate, tiles, encoding speed,
>>> etc).
>>>
>>> The files generated by this muxer has been verified to be valid
>>> AVIF files by the following:
>>> 1) Displays on Chrome (both still and animated images).
>>> 2) Displays on Firefox (only still images, firefox does not support
>>>animated AVIF yet).
>>> 3) Verfied to be valid by Compliance Warden:
>>>https://github.com/gpac/ComplianceWarden
>>>
>>> Fixes the encoder/muxer part of Trac Ticket #7621
>>>
>>> Signed-off-by: Vignesh Venkatasubramanian 
>>> ---
>>>  configure|   1 +
>>>  libavformat/allformats.c |   1 +
>>>  libavformat/movenc.c | 341 ---
>>>  libavformat/movenc.h |   5 +
>>>  4 files changed, 322 insertions(+), 26 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 8c69ab0c86..6d7020e96b 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
>>>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>>>  avi_demuxer_select="riffdec exif"
>>>  avi_muxer_select="riffenc"
>>> +avif_muxer_select="mov_muxer"
>>>  caf_demuxer_select="iso_media"
>>>  caf_muxer_select="iso_media"
>>>  dash_muxer_select="mp4_muxer"
>>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>>> index d066a7745b..400c17afbd 100644
>>> --- a/libavformat/allformats.c
>>> +++ b/libavformat/allformats.c
>>> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>>>  extern const AVInputFormat  ff_av1_demuxer;
>>>  extern const AVInputFormat  ff_avi_demuxer;
>>>  extern const AVOutputFormat ff_avi_muxer;
>>> +extern const AVOutputFormat ff_avif_muxer;
>>>  extern const AVInputFormat  ff_avisynth_demuxer;
>>>  extern const AVOutputFormat ff_avm2_muxer;
>>>  extern const AVInputFormat  ff_avr_demuxer;
>>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
>>> index 1a746a67fd..ff41579300 100644
>>> --- a/libavformat/movenc.c
>>> +++ b/libavformat/movenc.c
>>> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
>>> MOVTrack *track)
>>>
>>>  avio_wb32(pb, 0);
>>>  ffio_wfourcc(pb, "av1C");
>>> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
>>> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
>>> MODE_AVIF);
>>>  return update_size(pb, pos);
>>>  }
>>>
>>> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
>>> MOVTrack *track, int prefer_icc)
>>>  }
>>>  }
>>>
>>> -/* We should only ever be called by MOV or MP4. */
>>> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
>>> +/* We should only ever be called for MOV, MP4 and AVIF. */
>>> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
>>> +   track->mode == MODE_AVIF);
>>>
>>>  avio_wb32(pb, 0); /* size */
>>>  ffio_wfourcc(pb, "colr");
>>> -if (track->mode == MODE_MP4)
>>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>>>  ffio_wfourcc(pb, "nclx");
>>>  else
>>>  ffio_wfourcc(pb, "nclc");
>>> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
>>> MOVTrack *track, int prefer_icc)
>>>  avio_wb16(pb, track->par->color_primaries);
>>>  avio_wb16(pb, track->par->color_trc);
>>>  avio_wb16(pb, track->par->color_space);
>>> -if (track->mode == MODE_MP4) {
>>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>>>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>>>  avio_w8(pb, full_range << 7);
>>>  }
>>> @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
>>> int len, MOVTrack *track)
>>>|| (track->par->width == 1440 && track->par->height == 
>>> 1080)
>>>|| (track->par->width == 1920 && track->par->height == 
>>> 1080);
>>>
>>> -if (track->mode == MODE_MOV &&
>>> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>>>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>>>  av_strlcpy(compressor_name, encoder->value, 32);
>>>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
>>> xdcam_res) {
>>> @@ -2106,6 +2107,25 @@ static void find_compressor(char * compressor_name, 
>>> int len, MOVTrack *track)
>>>  }
>>>  }
>>>
>>> +static int mov_write_ccst_tag(AVIOContext *pb)
>>> +{
>>> +int64_t pos = avio_tell(pb);
>>> +   

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread Vignesh Venkatasubramanian
On Wed, Apr 13, 2022 at 2:01 PM Andreas Rheinhardt
 wrote:
>
> Vignesh Venkatasubramanian:
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specification: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verified to be valid by Compliance Warden:
> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 337 ---
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 319 insertions(+), 25 deletions(-)
> >
> > +static int avif_write_trailer(AVFormatContext *s)
> > +{
> > +AVIOContext *pb = s->pb;
> > +MOVMuxContext *mov = s->priv_data;
> > +int64_t pos_backup, mdat_pos;
> > +uint8_t *buf;
> > +int buf_size, moov_size;
> > +
> > +if (mov->moov_written) return 0;
>
> Can it happen that moov_written is true? What happens if it is? (I
> presume the file to be invalid.)
>

This is more of a sanity check. I don't think this will ever happen
(as long as write_trailer is not called more than once). If you
prefer, i can remove it.

> > +
> > +mov->is_animated_avif = s->streams[0]->nb_frames > 1;
> > +mov_write_identification(pb, s);
> > +mov_write_meta_tag(pb, mov, s);
> > +
> > +moov_size = get_moov_size(s);
> > +mov->tracks[0].data_offset = avio_tell(pb) + moov_size + 8;
> > +
> > +if (mov->is_animated_avif) {
> > +int ret;
> > +if ((ret = mov_write_moov_tag(pb, mov, s)) < 0)
> > +return ret;
> > +}
> > +
> > +buf_size = avio_get_dyn_buf(mov->mdat_buf, &buf);
> > +avio_wb32(pb, buf_size + 8);
> > +ffio_wfourcc(pb, "mdat");
> > +mdat_pos = avio_tell(pb);
> > +
> > +if (mdat_pos != (uint32_t)mdat_pos) {
> > +av_log(s, AV_LOG_ERROR, "mdat offset does not fit in 32 bits\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +
> > +avio_write(pb, buf, buf_size);
> > +
> > +// write extent offset.
> > +pos_backup = avio_tell(pb);
> > +avio_seek(pb, mov->avif_extent_pos, SEEK_SET);
> > +avio_wb32(pb, mdat_pos); /* rewrite offset */
> > +avio_seek(pb, pos_backup, SEEK_SET);
> > +
> > +return 0;
> > +}
> > +
>
> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



-- 
Vignesh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-13 Thread Vignesh Venkatasubramanian
On Wed, Apr 13, 2022 at 2:04 PM Andreas Rheinhardt
 wrote:
>
> Vignesh Venkatasubramanian:
> > On Mon, Mar 21, 2022 at 1:46 PM Andreas Rheinhardt
> >  wrote:
> >>
> >> Vignesh Venkatasubramanian:
> >>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >>>
> >>> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> >>>
> >>> Sample usage for still image:
> >>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >>>
> >>> Sample usage for animated AVIF image:
> >>> ffmpeg -i video.mp4 animated.avif
> >>>
> >>> We can re-use any of the AV1 encoding options that will make
> >>> sense for image encoding (like bitrate, tiles, encoding speed,
> >>> etc).
> >>>
> >>> The files generated by this muxer has been verified to be valid
> >>> AVIF files by the following:
> >>> 1) Displays on Chrome (both still and animated images).
> >>> 2) Displays on Firefox (only still images, firefox does not support
> >>>animated AVIF yet).
> >>> 3) Verfied to be valid by Compliance Warden:
> >>>https://github.com/gpac/ComplianceWarden
> >>>
> >>> Fixes the encoder/muxer part of Trac Ticket #7621
> >>>
> >>> Signed-off-by: Vignesh Venkatasubramanian 
> >>> ---
> >>>  configure|   1 +
> >>>  libavformat/allformats.c |   1 +
> >>>  libavformat/movenc.c | 341 ---
> >>>  libavformat/movenc.h |   5 +
> >>>  4 files changed, 322 insertions(+), 26 deletions(-)
> >>>
> >>> diff --git a/configure b/configure
> >>> index 8c69ab0c86..6d7020e96b 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> >>>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >>>  avi_demuxer_select="riffdec exif"
> >>>  avi_muxer_select="riffenc"
> >>> +avif_muxer_select="mov_muxer"
> >>>  caf_demuxer_select="iso_media"
> >>>  caf_muxer_select="iso_media"
> >>>  dash_muxer_select="mp4_muxer"
> >>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> >>> index d066a7745b..400c17afbd 100644
> >>> --- a/libavformat/allformats.c
> >>> +++ b/libavformat/allformats.c
> >>> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >>>  extern const AVInputFormat  ff_av1_demuxer;
> >>>  extern const AVInputFormat  ff_avi_demuxer;
> >>>  extern const AVOutputFormat ff_avi_muxer;
> >>> +extern const AVOutputFormat ff_avif_muxer;
> >>>  extern const AVInputFormat  ff_avisynth_demuxer;
> >>>  extern const AVOutputFormat ff_avm2_muxer;
> >>>  extern const AVInputFormat  ff_avr_demuxer;
> >>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> >>> index 1a746a67fd..ff41579300 100644
> >>> --- a/libavformat/movenc.c
> >>> +++ b/libavformat/movenc.c
> >>> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> >>> MOVTrack *track)
> >>>
> >>>  avio_wb32(pb, 0);
> >>>  ffio_wfourcc(pb, "av1C");
> >>> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> >>> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode 
> >>> != MODE_AVIF);
> >>>  return update_size(pb, pos);
> >>>  }
> >>>
> >>> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> >>> MOVTrack *track, int prefer_icc)
> >>>  }
> >>>  }
> >>>
> >>> -/* We should only ever be called by MOV or MP4. */
> >>> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> >>> +/* We should only ever be called for MOV, MP4 and AVIF. */
> >>> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> >>> +   track->mode == MODE_AVIF);
> >>>
> >>>  avio_wb32(pb, 0); /* size */
> >>>  ffio_wfourcc(pb, "colr");
> >>> -if (track->mode == MODE_MP4)
> >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >>>  ffio_wfourcc(pb, "nclx");
> >>>  else
> >>>  ffio_wfourcc(pb, "nclc");
> >>> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> >>> MOVTrack *track, int prefer_icc)
> >>>  avio_wb16(pb, track->par->color_primaries);
> >>>  avio_wb16(pb, track->par->color_trc);
> >>>  avio_wb16(pb, track->par->color_space);
> >>> -if (track->mode == MODE_MP4) {
> >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> >>>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> >>>  avio_w8(pb, full_range << 7);
> >>>  }
> >>> @@ -2085,7 +2086,7 @@ static void find_compressor(char * compressor_name, 
> >>> int len, MOVTrack *track)
> >>>|| (track->par->width == 1440 && track->par->height == 
> >>> 1080)
> >>>|| (track->par->width == 1920 && track->par->height == 
> >>> 1080);
> >>>
> >>> -if (track->mode == MODE_MOV &&
> >>> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
> >>>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 
> >>> 0))) {
> >>>  av_strlcpy(compressor_name, encoder->value, 32);
> >>>  } else if (track

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-21 Thread Vignesh Venkatasubramanian
On Wed, Apr 13, 2022 at 2:35 PM Vignesh Venkatasubramanian
 wrote:
>
> On Wed, Apr 13, 2022 at 2:04 PM Andreas Rheinhardt
>  wrote:
> >
> > Vignesh Venkatasubramanian:
> > > On Mon, Mar 21, 2022 at 1:46 PM Andreas Rheinhardt
> > >  wrote:
> > >>
> > >> Vignesh Venkatasubramanian:
> > >>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> > >>>
> > >>> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> > >>>
> > >>> Sample usage for still image:
> > >>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> > >>>
> > >>> Sample usage for animated AVIF image:
> > >>> ffmpeg -i video.mp4 animated.avif
> > >>>
> > >>> We can re-use any of the AV1 encoding options that will make
> > >>> sense for image encoding (like bitrate, tiles, encoding speed,
> > >>> etc).
> > >>>
> > >>> The files generated by this muxer has been verified to be valid
> > >>> AVIF files by the following:
> > >>> 1) Displays on Chrome (both still and animated images).
> > >>> 2) Displays on Firefox (only still images, firefox does not support
> > >>>animated AVIF yet).
> > >>> 3) Verfied to be valid by Compliance Warden:
> > >>>https://github.com/gpac/ComplianceWarden
> > >>>
> > >>> Fixes the encoder/muxer part of Trac Ticket #7621
> > >>>
> > >>> Signed-off-by: Vignesh Venkatasubramanian 
> > >>> ---
> > >>>  configure|   1 +
> > >>>  libavformat/allformats.c |   1 +
> > >>>  libavformat/movenc.c | 341 ---
> > >>>  libavformat/movenc.h |   5 +
> > >>>  4 files changed, 322 insertions(+), 26 deletions(-)
> > >>>
> > >>> diff --git a/configure b/configure
> > >>> index 8c69ab0c86..6d7020e96b 100755
> > >>> --- a/configure
> > >>> +++ b/configure
> > >>> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> > >>>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> > >>>  avi_demuxer_select="riffdec exif"
> > >>>  avi_muxer_select="riffenc"
> > >>> +avif_muxer_select="mov_muxer"
> > >>>  caf_demuxer_select="iso_media"
> > >>>  caf_muxer_select="iso_media"
> > >>>  dash_muxer_select="mp4_muxer"
> > >>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > >>> index d066a7745b..400c17afbd 100644
> > >>> --- a/libavformat/allformats.c
> > >>> +++ b/libavformat/allformats.c
> > >>> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> > >>>  extern const AVInputFormat  ff_av1_demuxer;
> > >>>  extern const AVInputFormat  ff_avi_demuxer;
> > >>>  extern const AVOutputFormat ff_avi_muxer;
> > >>> +extern const AVOutputFormat ff_avif_muxer;
> > >>>  extern const AVInputFormat  ff_avisynth_demuxer;
> > >>>  extern const AVOutputFormat ff_avm2_muxer;
> > >>>  extern const AVInputFormat  ff_avr_demuxer;
> > >>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > >>> index 1a746a67fd..ff41579300 100644
> > >>> --- a/libavformat/movenc.c
> > >>> +++ b/libavformat/movenc.c
> > >>> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > >>> MOVTrack *track)
> > >>>
> > >>>  avio_wb32(pb, 0);
> > >>>  ffio_wfourcc(pb, "av1C");
> > >>> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > >>> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 
> > >>> track->mode != MODE_AVIF);
> > >>>  return update_size(pb, pos);
> > >>>  }
> > >>>
> > >>> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > >>> MOVTrack *track, int prefer_icc)
> > >>>  }
> > >>>  }
> > >>>
> > >>> -/* We should only ever be called by MOV or MP4. */
> > >>> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > >>> +/* We should only ever be called for MOV, MP4 and AVIF. */
> > >>> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > >>> +   track->mode == MODE_AVIF);
> > >>>
> > >>>  avio_wb32(pb, 0); /* size */
> > >>>  ffio_wfourcc(pb, "colr");
> > >>> -if (track->mode == MODE_MP4)
> > >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> > >>>  ffio_wfourcc(pb, "nclx");
> > >>>  else
> > >>>  ffio_wfourcc(pb, "nclc");
> > >>> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > >>> MOVTrack *track, int prefer_icc)
> > >>>  avio_wb16(pb, track->par->color_primaries);
> > >>>  avio_wb16(pb, track->par->color_trc);
> > >>>  avio_wb16(pb, track->par->color_space);
> > >>> -if (track->mode == MODE_MP4) {
> > >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> > >>>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> > >>>  avio_w8(pb, full_range << 7);
> > >>>  }
> > >>> @@ -2085,7 +2086,7 @@ static void find_compressor(char * 
> > >>> compressor_name, int len, MOVTrack *track)
> > >>>|| (track->par->width == 1440 && track->par->height 
> > >>> == 1080)
> > >>>|| (track->par->width == 1920 && track->par->height 
> > >>> == 1080);
> > >>

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-04-29 Thread Vignesh Venkatasubramanian
On Thu, Apr 21, 2022 at 9:38 AM Vignesh Venkatasubramanian
 wrote:
>
> On Wed, Apr 13, 2022 at 2:35 PM Vignesh Venkatasubramanian
>  wrote:
> >
> > On Wed, Apr 13, 2022 at 2:04 PM Andreas Rheinhardt
> >  wrote:
> > >
> > > Vignesh Venkatasubramanian:
> > > > On Mon, Mar 21, 2022 at 1:46 PM Andreas Rheinhardt
> > > >  wrote:
> > > >>
> > > >> Vignesh Venkatasubramanian:
> > > >>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> > > >>>
> > > >>> AVIF Specifiation: https://aomediacodec.github.io/av1-avif
> > > >>>
> > > >>> Sample usage for still image:
> > > >>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> > > >>>
> > > >>> Sample usage for animated AVIF image:
> > > >>> ffmpeg -i video.mp4 animated.avif
> > > >>>
> > > >>> We can re-use any of the AV1 encoding options that will make
> > > >>> sense for image encoding (like bitrate, tiles, encoding speed,
> > > >>> etc).
> > > >>>
> > > >>> The files generated by this muxer has been verified to be valid
> > > >>> AVIF files by the following:
> > > >>> 1) Displays on Chrome (both still and animated images).
> > > >>> 2) Displays on Firefox (only still images, firefox does not support
> > > >>>animated AVIF yet).
> > > >>> 3) Verfied to be valid by Compliance Warden:
> > > >>>https://github.com/gpac/ComplianceWarden
> > > >>>
> > > >>> Fixes the encoder/muxer part of Trac Ticket #7621
> > > >>>
> > > >>> Signed-off-by: Vignesh Venkatasubramanian 
> > > >>> ---
> > > >>>  configure|   1 +
> > > >>>  libavformat/allformats.c |   1 +
> > > >>>  libavformat/movenc.c | 341 
> > > >>> ---
> > > >>>  libavformat/movenc.h |   5 +
> > > >>>  4 files changed, 322 insertions(+), 26 deletions(-)
> > > >>>
> > > >>> diff --git a/configure b/configure
> > > >>> index 8c69ab0c86..6d7020e96b 100755
> > > >>> --- a/configure
> > > >>> +++ b/configure
> > > >>> @@ -3390,6 +3390,7 @@ asf_stream_muxer_select="asf_muxer"
> > > >>>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> > > >>>  avi_demuxer_select="riffdec exif"
> > > >>>  avi_muxer_select="riffenc"
> > > >>> +avif_muxer_select="mov_muxer"
> > > >>>  caf_demuxer_select="iso_media"
> > > >>>  caf_muxer_select="iso_media"
> > > >>>  dash_muxer_select="mp4_muxer"
> > > >>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > > >>> index d066a7745b..400c17afbd 100644
> > > >>> --- a/libavformat/allformats.c
> > > >>> +++ b/libavformat/allformats.c
> > > >>> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> > > >>>  extern const AVInputFormat  ff_av1_demuxer;
> > > >>>  extern const AVInputFormat  ff_avi_demuxer;
> > > >>>  extern const AVOutputFormat ff_avi_muxer;
> > > >>> +extern const AVOutputFormat ff_avif_muxer;
> > > >>>  extern const AVInputFormat  ff_avisynth_demuxer;
> > > >>>  extern const AVOutputFormat ff_avm2_muxer;
> > > >>>  extern const AVInputFormat  ff_avr_demuxer;
> > > >>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> > > >>> index 1a746a67fd..ff41579300 100644
> > > >>> --- a/libavformat/movenc.c
> > > >>> +++ b/libavformat/movenc.c
> > > >>> @@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
> > > >>> MOVTrack *track)
> > > >>>
> > > >>>  avio_wb32(pb, 0);
> > > >>>  ffio_wfourcc(pb, "av1C");
> > > >>> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> > > >>> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 
> > > >>> track->mode != MODE_AVIF);
> > > >>>  return update_size(pb, pos);
> > > >>>  }
> > > >>>
> > > >>> @@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext 
> > > >>> *pb, MOVTrack *track, int prefer_icc)
> > > >>>  }
> > > >>>  }
> > > >>>
> > > >>> -/* We should only ever be called by MOV or MP4. */
> > > >>> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> > > >>> +/* We should only ever be called for MOV, MP4 and AVIF. */
> > > >>> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> > > >>> +   track->mode == MODE_AVIF);
> > > >>>
> > > >>>  avio_wb32(pb, 0); /* size */
> > > >>>  ffio_wfourcc(pb, "colr");
> > > >>> -if (track->mode == MODE_MP4)
> > > >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> > > >>>  ffio_wfourcc(pb, "nclx");
> > > >>>  else
> > > >>>  ffio_wfourcc(pb, "nclc");
> > > >>> @@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> > > >>> MOVTrack *track, int prefer_icc)
> > > >>>  avio_wb16(pb, track->par->color_primaries);
> > > >>>  avio_wb16(pb, track->par->color_trc);
> > > >>>  avio_wb16(pb, track->par->color_space);
> > > >>> -if (track->mode == MODE_MP4) {
> > > >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
> > > >>>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
> > > >>>  avio_w8(pb, full_range << 7);
> > > >>>  }
> > > >>> @@ -2085

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-02 Thread James Zern
On Wed, Apr 13, 2022 at 1:40 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specification: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 337 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 319 insertions(+), 25 deletions(-)
>

It would be good to have a Changelog entry after the ticket is fixed.

> [...]
> @@ -2823,7 +2848,10 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
>
>  if (track) {
>  hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
> -if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> +if (track->mode == MODE_AVIF) {
> +hdlr_type = "pict";
> +descr = "ffmpeg";

Should this be PictureHandler or blank? What's written for heic?

> [...]
> +static int mov_write_ispe_tag(AVIOContext *pb, MOVMuxContext *mov, 
> AVFormatContext *s)
> +{
> +int64_t pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "ispe");
> +avio_wb32(pb, 0); /* Version & flags */
> +avio_wb32(pb, s->streams[0]->codecpar->width); /* image_width */
> +avio_wb32(pb, s->streams[0]->codecpar->height); /* image_height */
> +return update_size(pb, pos);
> +}
> +
> +

This extra line could be removed.

> [...]
> +/* AVIF output must have exactly one video stream */
> +if (mov->mode == MODE_AVIF) {
> +if (s->nb_streams > 1) {
> +av_log(s, AV_LOG_ERROR, "AVIF output requires exactly one 
> stream\n");
> +return AVERROR(EINVAL);
> +}
> +if (s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
> +av_log(s, AV_LOG_ERROR, "AVIF output requires one video 
> stream\n");
> +return AVERROR(EINVAL);
> +}
> +}
> +
> +

This one too.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-02 Thread Vignesh Venkatasubramanian
On Mon, May 2, 2022 at 10:28 AM James Zern
 wrote:
>
> On Wed, Apr 13, 2022 at 1:40 PM Vignesh Venkatasubramanian
>  wrote:
> >
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specification: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >animated AVIF yet).
> > 3) Verified to be valid by Compliance Warden:
> >https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  configure|   1 +
> >  libavformat/allformats.c |   1 +
> >  libavformat/movenc.c | 337 ---
> >  libavformat/movenc.h |   5 +
> >  4 files changed, 319 insertions(+), 25 deletions(-)
> >
>
> It would be good to have a Changelog entry after the ticket is fixed.
>

Acknowledged. Will do.

> > [...]
> > @@ -2823,7 +2848,10 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVTrack *tra
> >
> >  if (track) {
> >  hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
> > -if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> > +if (track->mode == MODE_AVIF) {
> > +hdlr_type = "pict";
> > +descr = "ffmpeg";
>
> Should this be PictureHandler or blank? What's written for heic?
>

Hmm, i used the string "ffmpeg" because libavif was writing "libavif"
[1]. But i think it makes sense to be consistent with the other types
here. I have updated the string to be "PictureHandler".

[1] 
https://github.com/AOMediaCodec/libavif/blob/45b6b1b88b54de6031c15b4f9dbee10f86244d1b/src/write.c#L456

> > [...]
> > +static int mov_write_ispe_tag(AVIOContext *pb, MOVMuxContext *mov, 
> > AVFormatContext *s)
> > +{
> > +int64_t pos = avio_tell(pb);
> > +avio_wb32(pb, 0); /* size */
> > +ffio_wfourcc(pb, "ispe");
> > +avio_wb32(pb, 0); /* Version & flags */
> > +avio_wb32(pb, s->streams[0]->codecpar->width); /* image_width */
> > +avio_wb32(pb, s->streams[0]->codecpar->height); /* image_height */
> > +return update_size(pb, pos);
> > +}
> > +
> > +
>
> This extra line could be removed.

Removed.

>
> > [...]
> > +/* AVIF output must have exactly one video stream */
> > +if (mov->mode == MODE_AVIF) {
> > +if (s->nb_streams > 1) {
> > +av_log(s, AV_LOG_ERROR, "AVIF output requires exactly one 
> > stream\n");
> > +return AVERROR(EINVAL);
> > +}
> > +if (s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
> > +av_log(s, AV_LOG_ERROR, "AVIF output requires one video 
> > stream\n");
> > +return AVERROR(EINVAL);
> > +}
> > +}
> > +
> > +
>
> This one too.

Removed.


> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



--
Vignesh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-03 Thread James Zern
On Mon, May 2, 2022 at 2:35 PM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specification: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 335 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 317 insertions(+), 25 deletions(-)
>

lgtm
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-03 Thread zhilizhao(赵志立)


> On May 3, 2022, at 5:35 AM, Vignesh Venkatasubramanian 
>  wrote:
> 
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> 
> AVIF Specification: https://aomediacodec.github.io/av1-avif
> 
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> 
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
> 
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
> 
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>   animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>   https://github.com/gpac/ComplianceWarden
> 
> Fixes the encoder/muxer part of Trac Ticket #7621
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
> configure|   1 +
> libavformat/allformats.c |   1 +
> libavformat/movenc.c | 335 ---
> libavformat/movenc.h |   5 +
> 4 files changed, 317 insertions(+), 25 deletions(-)
> 
> 

[…]

> static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, 
> MOVMuxContext *mov, MOVTrack *track)
> {
> int ret = AVERROR_BUG;
> @@ -2156,6 +2176,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> avio_wb32(pb, 0); /* size */
> if (mov->encryption_scheme != MOV_ENC_NONE) {
> ffio_wfourcc(pb, "encv");
> +} else if (track->mode == MODE_AVIF) {
> +ffio_wfourcc(pb, "av01");

Can the ‘else’ path handle the case?

> } else {
> avio_wl32(pb, track->tag); // store it byteswapped
> }
> @@ -2272,7 +2294,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> else
> av_log(mov->fc, AV_LOG_WARNING, "Not writing 'gama' atom. Format 
> is not MOV.\n");
> }
> -if (track->mode == MODE_MOV || track->mode == MODE_MP4) {
> +if (track->mode == MODE_MOV || track->mode == MODE_MP4 || track->mode == 
> MODE_AVIF) {
> int has_color_info = track->par->color_primaries != 
> AVCOL_PRI_UNSPECIFIED &&
>  track->par->color_trc != AVCOL_TRC_UNSPECIFIED &&
>  track->par->color_space != AVCOL_SPC_UNSPECIFIED;
> @@ -2324,6 +2346,9 @@ static int mov_write_video_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVMuxContex
> if (avid)
> avio_wb32(pb, 0);
> 
> +if (track->mode == MODE_AVIF)
> +mov_write_ccst_tag(pb);
> +
> return update_size(pb, pos);
> }
> 
> @@ -2825,7 +2850,10 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
> 
> if (track) {
> hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
> -if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> +if (track->mode == MODE_AVIF) {
> +hdlr_type = "pict";
> +descr = "PictureHandler";
> +} else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {

I prefer put check inside the ‘if (track->par->codec_type == 
AVMEDIA_TYPE_VIDEO)’.
It’s a special case of ‘AVMEDIA_TYPE_VIDEO’.

> hdlr_type = "vide";
> descr = "VideoHandler";
> } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) {
> @@ -2892,6 +2920,128 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> AVIOContext *pb, MOVTrack *tra
> return update_size(pb, pos);
> }
> 
> +static int mov_write_pitm_tag(AVIOContext *pb, int item_id)
> +{
> +int64_t pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "pitm");
> +avio_wb32(pb, 0); /* Version & flags */
> +avio_wb16(pb, item_id); /* item_id */
> +return update_size(pb, pos);
> +}
> +
> +static int mov_write_iloc_tag(AVIOContext *pb, MOVMuxContext *mov, 
> AVFormatContext *s)
> +{
> +int64_t pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "iloc");
> +avio_wb32(pb, 0); /* Version & flags */
> +avio_w8(pb, (4 << 4) + 4); /* offset_size(4) and length_size(4) */
> +avio_w8(pb, 0); /* base_offset_size(4) and reserved(4) */
> +avio_wb16(pb, 1); /* item_count */
> +
> +avio_wb16(pb, 1); /* item_id */
> +avio_wb16(pb, 0); /* data_reference_index */
> +avio_wb16(pb, 1); /* extent_count */
> +mov->avif_extent_pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* extent_offset (written later) */
> +// For animated AVIF, we simply write the first packet's size.
> +avio_wb32(pb, mov->avif_extent_length); /* extent_length */
> +
> +return update_size(pb, pos);
> +}
> +
> +static int mov_write_iinf_tag(AVIOContext *pb, MOVMuxContext *mov, 
> AVFormatContext *s)
> +{
> +int64_t infe_pos;
> +int64_t iinf_pos = avio_tell(pb);
> +avio_wb32(pb, 0); /* size */
> +ffio_wfourcc(pb, "iinf");
> +  

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-04 Thread Vignesh Venkatasubramanian
On Tue, May 3, 2022 at 7:46 PM "zhilizhao(赵志立)"  wrote:
>
>

Thanks for the review!

>
> > On May 3, 2022, at 5:35 AM, Vignesh Venkatasubramanian 
> >  wrote:
> >
> > Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >
> > AVIF Specification: https://aomediacodec.github.io/av1-avif
> >
> > Sample usage for still image:
> > ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
> >
> > Sample usage for animated AVIF image:
> > ffmpeg -i video.mp4 animated.avif
> >
> > We can re-use any of the AV1 encoding options that will make
> > sense for image encoding (like bitrate, tiles, encoding speed,
> > etc).
> >
> > The files generated by this muxer has been verified to be valid
> > AVIF files by the following:
> > 1) Displays on Chrome (both still and animated images).
> > 2) Displays on Firefox (only still images, firefox does not support
> >   animated AVIF yet).
> > 3) Verified to be valid by Compliance Warden:
> >   https://github.com/gpac/ComplianceWarden
> >
> > Fixes the encoder/muxer part of Trac Ticket #7621
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> > configure|   1 +
> > libavformat/allformats.c |   1 +
> > libavformat/movenc.c | 335 ---
> > libavformat/movenc.h |   5 +
> > 4 files changed, 317 insertions(+), 25 deletions(-)
> >
> >
>
> […]
>
> > static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, 
> > MOVMuxContext *mov, MOVTrack *track)
> > {
> > int ret = AVERROR_BUG;
> > @@ -2156,6 +2176,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVMuxContex
> > avio_wb32(pb, 0); /* size */
> > if (mov->encryption_scheme != MOV_ENC_NONE) {
> > ffio_wfourcc(pb, "encv");
> > +} else if (track->mode == MODE_AVIF) {
> > +ffio_wfourcc(pb, "av01");
>
> Can the ‘else’ path handle the case?
>

You are right. Removed the "else if" case.

> > } else {
> > avio_wl32(pb, track->tag); // store it byteswapped
> > }
> > @@ -2272,7 +2294,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVMuxContex
> > else
> > av_log(mov->fc, AV_LOG_WARNING, "Not writing 'gama' atom. 
> > Format is not MOV.\n");
> > }
> > -if (track->mode == MODE_MOV || track->mode == MODE_MP4) {
> > +if (track->mode == MODE_MOV || track->mode == MODE_MP4 || track->mode 
> > == MODE_AVIF) {
> > int has_color_info = track->par->color_primaries != 
> > AVCOL_PRI_UNSPECIFIED &&
> >  track->par->color_trc != AVCOL_TRC_UNSPECIFIED 
> > &&
> >  track->par->color_space != 
> > AVCOL_SPC_UNSPECIFIED;
> > @@ -2324,6 +2346,9 @@ static int mov_write_video_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVMuxContex
> > if (avid)
> > avio_wb32(pb, 0);
> >
> > +if (track->mode == MODE_AVIF)
> > +mov_write_ccst_tag(pb);
> > +
> > return update_size(pb, pos);
> > }
> >
> > @@ -2825,7 +2850,10 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVTrack *tra
> >
> > if (track) {
> > hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
> > -if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
> > +if (track->mode == MODE_AVIF) {
> > +hdlr_type = "pict";
> > +descr = "PictureHandler";
> > +} else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
>
> I prefer put check inside the ‘if (track->par->codec_type == 
> AVMEDIA_TYPE_VIDEO)’.
> It’s a special case of ‘AVMEDIA_TYPE_VIDEO’.
>

Done.

> > hdlr_type = "vide";
> > descr = "VideoHandler";
> > } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) {
> > @@ -2892,6 +2920,128 @@ static int mov_write_hdlr_tag(AVFormatContext *s, 
> > AVIOContext *pb, MOVTrack *tra
> > return update_size(pb, pos);
> > }
> >
> > +static int mov_write_pitm_tag(AVIOContext *pb, int item_id)
> > +{
> > +int64_t pos = avio_tell(pb);
> > +avio_wb32(pb, 0); /* size */
> > +ffio_wfourcc(pb, "pitm");
> > +avio_wb32(pb, 0); /* Version & flags */
> > +avio_wb16(pb, item_id); /* item_id */
> > +return update_size(pb, pos);
> > +}
> > +
> > +static int mov_write_iloc_tag(AVIOContext *pb, MOVMuxContext *mov, 
> > AVFormatContext *s)
> > +{
> > +int64_t pos = avio_tell(pb);
> > +avio_wb32(pb, 0); /* size */
> > +ffio_wfourcc(pb, "iloc");
> > +avio_wb32(pb, 0); /* Version & flags */
> > +avio_w8(pb, (4 << 4) + 4); /* offset_size(4) and length_size(4) */
> > +avio_w8(pb, 0); /* base_offset_size(4) and reserved(4) */
> > +avio_wb16(pb, 1); /* item_count */
> > +
> > +avio_wb16(pb, 1); /* item_id */
> > +avio_wb16(pb, 0); /* data_reference_index */
> > +avio_wb16(pb, 1); /* extent_count */
> > +mov->avif_extent_pos = avio_tell(pb);
> > +avio_wb32(pb, 0); /* extent_offset (written later) */
> > +// For animated AVIF, we simp

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-04 Thread zhilizhao(赵志立)


> On May 5, 2022, at 12:45 AM, Vignesh Venkatasubramanian 
>  wrote:
> 
>>> 
>>> -mov_write_track_udta_tag(pb, mov, st);
>>> +if (track->mode != MODE_AVIF)
>>> +mov_write_track_udta_tag(pb, mov, st);
>> 
>> Please check if the check can be removed. mov_write_track_udta_tag() does 
>> nothing
>> for mode other than MOV/MP4.
>> 
> 
> mov_write_track_udta_tag() writes itunes meta and loci tags when mode
> is not MOV/MP4. So this check is necessary.
> 

I think you are referring to ‘mov_write_udta_tag', not
‘mov_write_track_udta_tag', no?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-04 Thread Vignesh Venkatasubramanian
On Wed, May 4, 2022 at 10:10 AM "zhilizhao(赵志立)"  wrote:
>
>
>
> > On May 5, 2022, at 12:45 AM, Vignesh Venkatasubramanian 
> >  wrote:
> >
> >>>
> >>> -mov_write_track_udta_tag(pb, mov, st);
> >>> +if (track->mode != MODE_AVIF)
> >>> +mov_write_track_udta_tag(pb, mov, st);
> >>
> >> Please check if the check can be removed. mov_write_track_udta_tag() does 
> >> nothing
> >> for mode other than MOV/MP4.
> >>
> >
> > mov_write_track_udta_tag() writes itunes meta and loci tags when mode
> > is not MOV/MP4. So this check is necessary.
> >
>
> I think you are referring to ‘mov_write_udta_tag', not
> ‘mov_write_track_udta_tag', no?

Ah yes you are right. mov_write_track_udta_tag doesn't do anything for
non-MOV/MP4. I have removed the check.

> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".



-- 
Vignesh
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-11 Thread Vignesh Venkatasubramanian
On Wed, May 4, 2022 at 10:15 AM Vignesh Venkatasubramanian
 wrote:
>
> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
>
> AVIF Specification: https://aomediacodec.github.io/av1-avif
>
> Sample usage for still image:
> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> Sample usage for animated AVIF image:
> ffmpeg -i video.mp4 animated.avif
>
> We can re-use any of the AV1 encoding options that will make
> sense for image encoding (like bitrate, tiles, encoding speed,
> etc).
>
> The files generated by this muxer has been verified to be valid
> AVIF files by the following:
> 1) Displays on Chrome (both still and animated images).
> 2) Displays on Firefox (only still images, firefox does not support
>animated AVIF yet).
> 3) Verified to be valid by Compliance Warden:
>https://github.com/gpac/ComplianceWarden
>
> Fixes the encoder/muxer part of Trac Ticket #7621
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  configure|   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/movenc.c | 333 ---
>  libavformat/movenc.h |   5 +
>  4 files changed, 316 insertions(+), 24 deletions(-)
>
> diff --git a/configure b/configure
> index 196873c4aa..2992f9760e 100755
> --- a/configure
> +++ b/configure
> @@ -3404,6 +3404,7 @@ asf_stream_muxer_select="asf_muxer"
>  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
>  avi_demuxer_select="riffdec exif"
>  avi_muxer_select="riffenc"
> +avif_muxer_select="mov_muxer"
>  caf_demuxer_select="iso_media"
>  caf_muxer_select="iso_media"
>  dash_muxer_select="mp4_muxer"
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 63876c468f..1802536633 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
>  extern const AVInputFormat  ff_av1_demuxer;
>  extern const AVInputFormat  ff_avi_demuxer;
>  extern const AVOutputFormat ff_avi_muxer;
> +extern const AVOutputFormat ff_avif_muxer;
>  extern const AVInputFormat  ff_avisynth_demuxer;
>  extern const AVOutputFormat ff_avm2_muxer;
>  extern const AVInputFormat  ff_avr_demuxer;
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 271db99b46..1a20fe17ca 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -1335,7 +1335,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
> *track)
>
>  avio_wb32(pb, 0);
>  ffio_wfourcc(pb, "av1C");
> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
> MODE_AVIF);
>  return update_size(pb, pos);
>  }
>
> @@ -2037,12 +2037,13 @@ static int mov_write_colr_tag(AVIOContext *pb, 
> MOVTrack *track, int prefer_icc)
>  }
>  }
>
> -/* We should only ever be called by MOV or MP4. */
> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> +/* We should only ever be called for MOV, MP4 and AVIF. */
> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> +   track->mode == MODE_AVIF);
>
>  avio_wb32(pb, 0); /* size */
>  ffio_wfourcc(pb, "colr");
> -if (track->mode == MODE_MP4)
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
>  ffio_wfourcc(pb, "nclx");
>  else
>  ffio_wfourcc(pb, "nclc");
> @@ -2052,7 +2053,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
> *track, int prefer_icc)
>  avio_wb16(pb, track->par->color_primaries);
>  avio_wb16(pb, track->par->color_trc);
>  avio_wb16(pb, track->par->color_space);
> -if (track->mode == MODE_MP4) {
> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
>  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
>  avio_w8(pb, full_range << 7);
>  }
> @@ -2118,7 +2119,7 @@ static void find_compressor(char * compressor_name, int 
> len, MOVTrack *track)
>|| (track->par->width == 1440 && track->par->height == 
> 1080)
>|| (track->par->width == 1920 && track->par->height == 
> 1080);
>
> -if (track->mode == MODE_MOV &&
> +if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
>  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
>  av_strlcpy(compressor_name, encoder->value, 32);
>  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
> @@ -2139,6 +2140,25 @@ static void find_compressor(char * compressor_name, 
> int len, MOVTrack *track)
>  }
>  }
>
> +static int mov_write_ccst_tag(AVIOContext *pb)
> +{
> +int64_t pos = avio_tell(pb);
> +// Write sane defaults:
> +// all_ref_pics_intra = 0 : all samples can use any type of reference.
> +// intra_pred_used = 1 : intra prediction may or may not be used.
> +// max_ref_per_pic = 15 : reserved value to indicate that any number of
> +//reference i

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-11 Thread Gyan Doshi




On 2022-05-11 10:24 pm, Vignesh Venkatasubramanian wrote:

On Wed, May 4, 2022 at 10:15 AM Vignesh Venkatasubramanian
 wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specification: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
animated AVIF yet).
3) Verified to be valid by Compliance Warden:
https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure|   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 333 ---
  libavformat/movenc.h |   5 +
  4 files changed, 316 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 196873c4aa..2992f9760e 100755
--- a/configure
+++ b/configure
@@ -3404,6 +3404,7 @@ asf_stream_muxer_select="asf_muxer"
  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
  avi_demuxer_select="riffdec exif"
  avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
  caf_demuxer_select="iso_media"
  caf_muxer_select="iso_media"
  dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 63876c468f..1802536633 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
  extern const AVInputFormat  ff_av1_demuxer;
  extern const AVInputFormat  ff_avi_demuxer;
  extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
  extern const AVInputFormat  ff_avisynth_demuxer;
  extern const AVOutputFormat ff_avm2_muxer;
  extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 271db99b46..1a20fe17ca 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1335,7 +1335,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)

  avio_wb32(pb, 0);
  ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
MODE_AVIF);
  return update_size(pb, pos);
  }

@@ -2037,12 +2037,13 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
  }
  }

-/* We should only ever be called by MOV or MP4. */
-av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+/* We should only ever be called for MOV, MP4 and AVIF. */
+av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);

  avio_wb32(pb, 0); /* size */
  ffio_wfourcc(pb, "colr");
-if (track->mode == MODE_MP4)
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
  ffio_wfourcc(pb, "nclx");
  else
  ffio_wfourcc(pb, "nclc");
@@ -2052,7 +2053,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
  avio_wb16(pb, track->par->color_primaries);
  avio_wb16(pb, track->par->color_trc);
  avio_wb16(pb, track->par->color_space);
-if (track->mode == MODE_MP4) {
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
  avio_w8(pb, full_range << 7);
  }
@@ -2118,7 +2119,7 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
|| (track->par->width == 1440 && track->par->height == 1080)
|| (track->par->width == 1920 && track->par->height == 
1080);

-if (track->mode == MODE_MOV &&
+if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
  av_strlcpy(compressor_name, encoder->value, 32);
  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
@@ -2139,6 +2140,25 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
  }
  }

+static int mov_write_ccst_tag(AVIOContext *pb)
+{
+int64_t pos = avio_tell(pb);
+// Write sane defaults:
+// all_ref_pics_intra = 0 : all samples can use any type of reference.
+// intra_pred_used = 1 : intra prediction may or may not be used.
+// max_ref_per_pic = 15 : reserved value to indicate that any number of
+//reference images can be used.
+uint8_t ccstValue = (0 << 7) |  /* all_ref_pics_intra */
+(1 << 6) |  /* intra_pre

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-12 Thread Gyan Doshi



On 2022-05-11 10:55 pm, Gyan Doshi wrote:



On 2022-05-11 10:24 pm, Vignesh Venkatasubramanian wrote:

On Wed, May 4, 2022 at 10:15 AM Vignesh Venkatasubramanian
 wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specification: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif


I see an option for av1 encoder called still-picture but no avif-image.

Muxing works and files do play back, however for animated AVIF,  the 
demuxer complains

"Invalid mvhd time scale 0, defaulting to 1".

Regards,
Gyan




Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
    animated AVIF yet).
3) Verified to be valid by Compliance Warden:
    https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure    |   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 333 
---

  libavformat/movenc.h |   5 +
  4 files changed, 316 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 196873c4aa..2992f9760e 100755
--- a/configure
+++ b/configure
@@ -3404,6 +3404,7 @@ asf_stream_muxer_select="asf_muxer"
  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
  avi_demuxer_select="riffdec exif"
  avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
  caf_demuxer_select="iso_media"
  caf_muxer_select="iso_media"
  dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 63876c468f..1802536633 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
  extern const AVInputFormat  ff_av1_demuxer;
  extern const AVInputFormat  ff_avi_demuxer;
  extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
  extern const AVInputFormat  ff_avisynth_demuxer;
  extern const AVOutputFormat ff_avm2_muxer;
  extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 271db99b46..1a20fe17ca 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1335,7 +1335,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, 
MOVTrack *track)


  avio_wb32(pb, 0);
  ffio_wfourcc(pb, "av1C");
-    ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+    ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 
track->mode != MODE_AVIF);

  return update_size(pb, pos);
  }

@@ -2037,12 +2037,13 @@ static int mov_write_colr_tag(AVIOContext 
*pb, MOVTrack *track, int prefer_icc)

  }
  }

-    /* We should only ever be called by MOV or MP4. */
-    av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+    /* We should only ever be called for MOV, MP4 and AVIF. */
+    av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);

  avio_wb32(pb, 0); /* size */
  ffio_wfourcc(pb, "colr");
-    if (track->mode == MODE_MP4)
+    if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
  ffio_wfourcc(pb, "nclx");
  else
  ffio_wfourcc(pb, "nclc");
@@ -2052,7 +2053,7 @@ static int mov_write_colr_tag(AVIOContext *pb, 
MOVTrack *track, int prefer_icc)

  avio_wb16(pb, track->par->color_primaries);
  avio_wb16(pb, track->par->color_trc);
  avio_wb16(pb, track->par->color_space);
-    if (track->mode == MODE_MP4) {
+    if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
  avio_w8(pb, full_range << 7);
  }
@@ -2118,7 +2119,7 @@ static void find_compressor(char * 
compressor_name, int len, MOVTrack *track)
    || (track->par->width == 1440 && 
track->par->height == 1080)
    || (track->par->width == 1920 && 
track->par->height == 1080);


-    if (track->mode == MODE_MOV &&
+    if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
  (encoder = av_dict_get(track->st->metadata, "encoder", 
NULL, 0))) {

  av_strlcpy(compressor_name, encoder->value, 32);
  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && 
xdcam_res) {
@@ -2139,6 +2140,25 @@ static void find_compressor(char * 
compressor_name, int len, MOVTrack *track)

  }
  }

+static int mov_write_ccst_tag(AVIOContext *pb)
+{
+    int64_t pos = avio_tell(pb);
+    // Write sane defaults:
+    // all_ref_pics_intra = 0 : all samples can use any type of 
reference.

+    // intra_pred_used = 1 : intr

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-12 Thread Vignesh Venkatasubramanian
On Thu, May 12, 2022 at 3:27 AM Gyan Doshi  wrote:
>
>
>
> On 2022-05-11 10:55 pm, Gyan Doshi wrote:
> >
> >
> > On 2022-05-11 10:24 pm, Vignesh Venkatasubramanian wrote:
> >> On Wed, May 4, 2022 at 10:15 AM Vignesh Venkatasubramanian
> >>  wrote:
> >>> Add an AVIF muxer by re-using the existing the mov/mp4 muxer.
> >>>
> >>> AVIF Specification: https://aomediacodec.github.io/av1-avif
> >>>
> >>> Sample usage for still image:
> >>> ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif
>
> I see an option for av1 encoder called still-picture but no avif-image.
>

Sorry this flag was updated as a result of a review comment in an
earlier patch. I forgot to update this commit message. Updated now.
"still-picture" flag is what you want to set for the still images.

> Muxing works and files do play back, however for animated AVIF,  the
> demuxer complains
> "Invalid mvhd time scale 0, defaulting to 1".
>

I was going by playback in Chrome/Firefox and Compliance Warden's [1]
validation. I have updated the muxer to use the track's timescale if
movie_timescale is not set. The demuxer no longer warns about the
timescale.


> Regards,
> Gyan
>
>
> >>>
> >>> Sample usage for animated AVIF image:
> >>> ffmpeg -i video.mp4 animated.avif
> >>>
> >>> We can re-use any of the AV1 encoding options that will make
> >>> sense for image encoding (like bitrate, tiles, encoding speed,
> >>> etc).
> >>>
> >>> The files generated by this muxer has been verified to be valid
> >>> AVIF files by the following:
> >>> 1) Displays on Chrome (both still and animated images).
> >>> 2) Displays on Firefox (only still images, firefox does not support
> >>> animated AVIF yet).
> >>> 3) Verified to be valid by Compliance Warden:
> >>> https://github.com/gpac/ComplianceWarden
> >>>
> >>> Fixes the encoder/muxer part of Trac Ticket #7621
> >>>
> >>> Signed-off-by: Vignesh Venkatasubramanian 
> >>> ---
> >>>   configure|   1 +
> >>>   libavformat/allformats.c |   1 +
> >>>   libavformat/movenc.c | 333
> >>> ---
> >>>   libavformat/movenc.h |   5 +
> >>>   4 files changed, 316 insertions(+), 24 deletions(-)
> >>>
> >>> diff --git a/configure b/configure
> >>> index 196873c4aa..2992f9760e 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -3404,6 +3404,7 @@ asf_stream_muxer_select="asf_muxer"
> >>>   av1_demuxer_select="av1_frame_merge_bsf av1_parser"
> >>>   avi_demuxer_select="riffdec exif"
> >>>   avi_muxer_select="riffenc"
> >>> +avif_muxer_select="mov_muxer"
> >>>   caf_demuxer_select="iso_media"
> >>>   caf_muxer_select="iso_media"
> >>>   dash_muxer_select="mp4_muxer"
> >>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> >>> index 63876c468f..1802536633 100644
> >>> --- a/libavformat/allformats.c
> >>> +++ b/libavformat/allformats.c
> >>> @@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
> >>>   extern const AVInputFormat  ff_av1_demuxer;
> >>>   extern const AVInputFormat  ff_avi_demuxer;
> >>>   extern const AVOutputFormat ff_avi_muxer;
> >>> +extern const AVOutputFormat ff_avif_muxer;
> >>>   extern const AVInputFormat  ff_avisynth_demuxer;
> >>>   extern const AVOutputFormat ff_avm2_muxer;
> >>>   extern const AVInputFormat  ff_avr_demuxer;
> >>> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> >>> index 271db99b46..1a20fe17ca 100644
> >>> --- a/libavformat/movenc.c
> >>> +++ b/libavformat/movenc.c
> >>> @@ -1335,7 +1335,7 @@ static int mov_write_av1c_tag(AVIOContext *pb,
> >>> MOVTrack *track)
> >>>
> >>>   avio_wb32(pb, 0);
> >>>   ffio_wfourcc(pb, "av1C");
> >>> -ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
> >>> +ff_isom_write_av1c(pb, track->vos_data, track->vos_len,
> >>> track->mode != MODE_AVIF);
> >>>   return update_size(pb, pos);
> >>>   }
> >>>
> >>> @@ -2037,12 +2037,13 @@ static int mov_write_colr_tag(AVIOContext
> >>> *pb, MOVTrack *track, int prefer_icc)
> >>>   }
> >>>   }
> >>>
> >>> -/* We should only ever be called by MOV or MP4. */
> >>> -av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
> >>> +/* We should only ever be called for MOV, MP4 and AVIF. */
> >>> +av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
> >>> +   track->mode == MODE_AVIF);
> >>>
> >>>   avio_wb32(pb, 0); /* size */
> >>>   ffio_wfourcc(pb, "colr");
> >>> -if (track->mode == MODE_MP4)
> >>> +if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
> >>>   ffio_wfourcc(pb, "nclx");
> >>>   else
> >>>   ffio_wfourcc(pb, "nclc");
> >>> @@ -2052,7 +2053,7 @@ static int mov_write_colr_tag(AVIOContext *pb,
> >>> MOVTrack *track, int prefer_icc)
> >>>   avio_wb16(pb, track->par->color_primaries);
> >>>   avio_wb16(pb, track->par->color_trc);
> >>>   avio_wb16(pb, track->par->color_space);
> >>> -if (track->mode == MODE_MP4) {
> >>> +if (track->mode == MODE_MP4 || track->mode 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/movenc: Add support for AVIF muxing

2022-05-13 Thread Gyan Doshi



On 2022-05-12 09:53 pm, Vignesh Venkatasubramanian wrote:

Add an AVIF muxer by re-using the existing the mov/mp4 muxer.


Bumped lavf minor and pushed set as    ab05e9a7f2...84241e63cf

Regards,
Gyan




AVIF Specification: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -still-picture 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
animated AVIF yet).
3) Verified to be valid by Compliance Warden:
https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
  configure|   1 +
  libavformat/allformats.c |   1 +
  libavformat/movenc.c | 341 ---
  libavformat/movenc.h |   5 +
  4 files changed, 323 insertions(+), 25 deletions(-)

diff --git a/configure b/configure
index 196873c4aa..2992f9760e 100755
--- a/configure
+++ b/configure
@@ -3404,6 +3404,7 @@ asf_stream_muxer_select="asf_muxer"
  av1_demuxer_select="av1_frame_merge_bsf av1_parser"
  avi_demuxer_select="riffdec exif"
  avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
  caf_demuxer_select="iso_media"
  caf_muxer_select="iso_media"
  dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 63876c468f..1802536633 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
  extern const AVInputFormat  ff_av1_demuxer;
  extern const AVInputFormat  ff_avi_demuxer;
  extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
  extern const AVInputFormat  ff_avisynth_demuxer;
  extern const AVOutputFormat ff_avm2_muxer;
  extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 271db99b46..a07c0ae2b4 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1335,7 +1335,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)
  
  avio_wb32(pb, 0);

  ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
MODE_AVIF);
  return update_size(pb, pos);
  }
  
@@ -2037,12 +2037,13 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track, int prefer_icc)

  }
  }
  
-/* We should only ever be called by MOV or MP4. */

-av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+/* We should only ever be called for MOV, MP4 and AVIF. */
+av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);
  
  avio_wb32(pb, 0); /* size */

  ffio_wfourcc(pb, "colr");
-if (track->mode == MODE_MP4)
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
  ffio_wfourcc(pb, "nclx");
  else
  ffio_wfourcc(pb, "nclc");
@@ -2052,7 +2053,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
  avio_wb16(pb, track->par->color_primaries);
  avio_wb16(pb, track->par->color_trc);
  avio_wb16(pb, track->par->color_space);
-if (track->mode == MODE_MP4) {
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
  int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
  avio_w8(pb, full_range << 7);
  }
@@ -2118,7 +2119,7 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
|| (track->par->width == 1440 && track->par->height == 1080)
|| (track->par->width == 1920 && track->par->height == 
1080);
  
-if (track->mode == MODE_MOV &&

+if ((track->mode == MODE_AVIF || track->mode == MODE_MOV) &&
  (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) {
  av_strlcpy(compressor_name, encoder->value, 32);
  } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) {
@@ -2139,6 +2140,25 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
  }
  }
  
+static int mov_write_ccst_tag(AVIOContext *pb)

+{
+int64_t pos = avio_tell(pb);
+// Write sane defaults:
+// all_ref_pics_intra = 0 : all samples can use any type of reference.
+// intra_pred_used = 1 : intra prediction may or may not be used.
+// max_ref_per_pic = 15 : reserved value to indicate that any number of
+//reference images can be used.
+uint8_t ccstValue = (0 << 7) |  /* all_ref_pics_intra */
+