Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-08-09 Thread James Zern
On Tue, Aug 2, 2022 at 9:54 AM James Zern  wrote:
>
> Andreas,
>
> On Thu, Jul 28, 2022 at 11:25 AM Vignesh Venkatasubramanian
>  wrote:
> >
> > Stores the item ids of all the items found in the file and
> > processes the primary item at the end of the meta box. This patch
> > does not change any behavior. It sets up the code for parsing
> > alpha channel (and possibly images with 'grid') in follow up
> > patches.
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  libavformat/isom.h |   6 ++
> >  libavformat/mov.c  | 143 +++--
> >  2 files changed, 92 insertions(+), 57 deletions(-)
> >
>
> Any more comments on this one?
>

Applied.
___
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 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-08-02 Thread James Zern
Andreas,

On Thu, Jul 28, 2022 at 11:25 AM Vignesh Venkatasubramanian
 wrote:
>
> Stores the item ids of all the items found in the file and
> processes the primary item at the end of the meta box. This patch
> does not change any behavior. It sets up the code for parsing
> alpha channel (and possibly images with 'grid') in follow up
> patches.
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  libavformat/isom.h |   6 ++
>  libavformat/mov.c  | 143 +++--
>  2 files changed, 92 insertions(+), 57 deletions(-)
>

Any more comments on this one?

> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index f05c2d9c28..9d8646d2ea 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -318,6 +318,12 @@ typedef struct MOVContext {
>  uint32_t max_stts_delta;
>  int is_still_picture_avif;
>  int primary_item_id;
> +struct {
> +int item_id;
> +int extent_length;
> +int64_t extent_offset;
> +} *avif_info;
> +int avif_info_size;
>  } MOVContext;
>
>  int ff_mp4_read_descr_len(AVIOContext *pb);
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index a09a762d91..6ee6ed0950 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  return ret;
>  }
>
> +static int avif_add_stream(MOVContext *c, int item_id)
> +{
> +MOVStreamContext *sc;
> +AVStream *st;
> +int item_index = -1;
> +for (int i = 0; i < c->avif_info_size; i++)
> +if (c->avif_info[i].item_id == item_id) {
> +item_index = i;
> +break;
> +}
> +if (item_index < 0)
> +return AVERROR_INVALIDDATA;
> +st = avformat_new_stream(c->fc, NULL);
> +if (!st)
> +return AVERROR(ENOMEM);
> +st->id = c->fc->nb_streams;
> +sc = av_mallocz(sizeof(MOVStreamContext));
> +if (!sc)
> +return AVERROR(ENOMEM);
> +
> +st->priv_data = sc;
> +st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> +st->codecpar->codec_id = AV_CODEC_ID_AV1;
> +sc->ffindex = st->index;
> +c->trak_index = st->index;
> +st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
> +st->time_base.num = st->time_base.den = 1;
> +st->nb_frames = 1;
> +sc->time_scale = 1;
> +sc = st->priv_data;
> +sc->pb = c->fc->pb;
> +sc->pb_is_copied = 1;
> +
> +// Populate the necessary fields used by mov_build_index.
> +sc->stsc_count = 1;
> +sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
> +if (!sc->stsc_data)
> +return AVERROR(ENOMEM);
> +sc->stsc_data[0].first = 1;
> +sc->stsc_data[0].count = 1;
> +sc->stsc_data[0].id = 1;
> +sc->chunk_count = 1;
> +sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
> +if (!sc->chunk_offsets)
> +return AVERROR(ENOMEM);
> +sc->sample_count = 1;
> +sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
> +if (!sc->sample_sizes)
> +return AVERROR(ENOMEM);
> +sc->stts_count = 1;
> +sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
> +if (!sc->stts_data)
> +return AVERROR(ENOMEM);
> +sc->stts_data[0].count = 1;
> +// Not used for still images. But needed by mov_build_index.
> +sc->stts_data[0].duration = 0;
> +sc->sample_sizes[0] = c->avif_info[item_index].extent_length;
> +sc->chunk_offsets[0] = c->avif_info[item_index].extent_offset;
> +
> +mov_build_index(c, st);
> +return 0;
> +}
> +
>  static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>  {
>  while (atom.size > 8) {
> @@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  tag = avio_rl32(pb);
>  atom.size -= 4;
>  if (tag == MKTAG('h','d','l','r')) {
> +int ret;
>  avio_seek(pb, -8, SEEK_CUR);
>  atom.size += 8;
> -return mov_read_default(c, pb, atom);
> +if ((ret = mov_read_default(c, pb, atom)) < 0)
> +return ret;
> +if (c->is_still_picture_avif) {
> +int ret;
> +// Add a stream for the YUV planes (primary item).
> +if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
> +return ret;
> +// For still AVIF images, the meta box contains all the
> +// necessary information that would generally be provided by 
> the
> +// moov box. So simply mark that we have found the moov box 
> so
> +// that parsing can continue.
> +c->found_moov = 1;
> +}
> +return ret;
>  }
>  }
>  return 0;
> @@ -7478,8 +7555,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  int item_count, extent_count;
>  uint64_t base_offset, extent_offse

[FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-28 Thread Vignesh Venkatasubramanian
Stores the item ids of all the items found in the file and
processes the primary item at the end of the meta box. This patch
does not change any behavior. It sets up the code for parsing
alpha channel (and possibly images with 'grid') in follow up
patches.

Signed-off-by: Vignesh Venkatasubramanian 
---
 libavformat/isom.h |   6 ++
 libavformat/mov.c  | 143 +++--
 2 files changed, 92 insertions(+), 57 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index f05c2d9c28..9d8646d2ea 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -318,6 +318,12 @@ typedef struct MOVContext {
 uint32_t max_stts_delta;
 int is_still_picture_avif;
 int primary_item_id;
+struct {
+int item_id;
+int extent_length;
+int64_t extent_offset;
+} *avif_info;
+int avif_info_size;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a09a762d91..6ee6ed0950 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return ret;
 }
 
+static int avif_add_stream(MOVContext *c, int item_id)
+{
+MOVStreamContext *sc;
+AVStream *st;
+int item_index = -1;
+for (int i = 0; i < c->avif_info_size; i++)
+if (c->avif_info[i].item_id == item_id) {
+item_index = i;
+break;
+}
+if (item_index < 0)
+return AVERROR_INVALIDDATA;
+st = avformat_new_stream(c->fc, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->id = c->fc->nb_streams;
+sc = av_mallocz(sizeof(MOVStreamContext));
+if (!sc)
+return AVERROR(ENOMEM);
+
+st->priv_data = sc;
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id = AV_CODEC_ID_AV1;
+sc->ffindex = st->index;
+c->trak_index = st->index;
+st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
+st->time_base.num = st->time_base.den = 1;
+st->nb_frames = 1;
+sc->time_scale = 1;
+sc = st->priv_data;
+sc->pb = c->fc->pb;
+sc->pb_is_copied = 1;
+
+// Populate the necessary fields used by mov_build_index.
+sc->stsc_count = 1;
+sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
+if (!sc->stsc_data)
+return AVERROR(ENOMEM);
+sc->stsc_data[0].first = 1;
+sc->stsc_data[0].count = 1;
+sc->stsc_data[0].id = 1;
+sc->chunk_count = 1;
+sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
+if (!sc->chunk_offsets)
+return AVERROR(ENOMEM);
+sc->sample_count = 1;
+sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
+if (!sc->sample_sizes)
+return AVERROR(ENOMEM);
+sc->stts_count = 1;
+sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
+if (!sc->stts_data)
+return AVERROR(ENOMEM);
+sc->stts_data[0].count = 1;
+// Not used for still images. But needed by mov_build_index.
+sc->stts_data[0].duration = 0;
+sc->sample_sizes[0] = c->avif_info[item_index].extent_length;
+sc->chunk_offsets[0] = c->avif_info[item_index].extent_offset;
+
+mov_build_index(c, st);
+return 0;
+}
+
 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 while (atom.size > 8) {
@@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+if ((ret = mov_read_default(c, pb, atom)) < 0)
+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be provided by 
the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
 }
 return 0;
@@ -7478,8 +7555,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int item_count, extent_count;
 uint64_t base_offset, extent_offset, extent_length;
 uint8_t value;
-AVStream *st;
-MOVStreamContext *sc;
 
 if (!c->is_still_picture_avif) {
 // * For non-avif, we simply ignore the iloc box.
@@ -7493,27 +7568,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
-st = avformat_new_stream(c->fc, NULL);
-if (!st)
-return 

Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-28 Thread Vignesh Venkatasubramanian
On Wed, Jul 27, 2022 at 12:40 PM Andreas Rheinhardt
 wrote:
>
> Vignesh Venkatasubramanian:
> > Stores the item ids of all the items found in the file and
> > processes the primary item at the end of the meta box. This patch
> > does not change any behavior. It sets up the code for parsing
> > alpha channel (and possibly images with 'grid') in follow up
> > patches.
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  libavformat/isom.h |   4 ++
> >  libavformat/mov.c  | 146 -
> >  2 files changed, 95 insertions(+), 55 deletions(-)
> >
> > diff --git a/libavformat/isom.h b/libavformat/isom.h
> > index f05c2d9c28..d8b262e915 100644
> > --- a/libavformat/isom.h
> > +++ b/libavformat/isom.h
> > @@ -318,6 +318,10 @@ typedef struct MOVContext {
> >  uint32_t max_stts_delta;
> >  int is_still_picture_avif;
> >  int primary_item_id;
> > +int *avif_item_ids;
> > +int avif_item_ids_size;
> > +int *avif_extent_lengths;
> > +int64_t *avif_extent_offsets;
>
> Why are these three different buffers instead of one buffer of struct {
> int avif_item_ids; int avif_extent_lengths; int64_t avif_extent_offsets;}?
>

Ah good point. Updated to use a struct and a size field.

> >  } MOVContext;
> >
> >  int ff_mp4_read_descr_len(AVIOContext *pb);
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index a09a762d91..fc6a691da4 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, 
> > AVIOContext *pb, MOVAtom atom)
> >  return ret;
> >  }
> >
> > +static int avif_add_stream(MOVContext *c, int item_id)
> > +{
> > +MOVStreamContext *sc;
> > +AVStream *st;
> > +int item_index = -1;
> > +for (int i = 0; i < c->avif_item_ids_size; i++)
> > +if (c->avif_item_ids[i] == item_id) {
> > +item_index = i;
> > +break;
> > +}
> > +if (item_index < 0)
> > +return AVERROR_INVALIDDATA;
> > +st = avformat_new_stream(c->fc, NULL);
> > +if (!st)
> > +return AVERROR(ENOMEM);
> > +st->id = c->fc->nb_streams;
> > +sc = av_mallocz(sizeof(MOVStreamContext));
> > +if (!sc)
> > +return AVERROR(ENOMEM);
> > +
> > +st->priv_data = sc;
> > +st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> > +st->codecpar->codec_id = AV_CODEC_ID_AV1;
> > +sc->ffindex = st->index;
> > +c->trak_index = st->index;
> > +st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
> > +st->time_base.num = st->time_base.den = 1;
> > +st->nb_frames = 1;
> > +sc->time_scale = 1;
> > +sc = st->priv_data;
> > +sc->pb = c->fc->pb;
> > +sc->pb_is_copied = 1;
> > +
> > +// Populate the necessary fields used by mov_build_index.
> > +sc->stsc_count = 1;
> > +sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
> > +if (!sc->stsc_data)
> > +return AVERROR(ENOMEM);
> > +sc->stsc_data[0].first = 1;
> > +sc->stsc_data[0].count = 1;
> > +sc->stsc_data[0].id = 1;
> > +sc->chunk_count = 1;
> > +sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
> > +if (!sc->chunk_offsets)
> > +return AVERROR(ENOMEM);
> > +sc->sample_count = 1;
> > +sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
> > +if (!sc->sample_sizes)
> > +return AVERROR(ENOMEM);
> > +sc->stts_count = 1;
> > +sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
> > +if (!sc->stts_data)
> > +return AVERROR(ENOMEM);
> > +sc->stts_data[0].count = 1;
> > +// Not used for still images. But needed by mov_build_index.
> > +sc->stts_data[0].duration = 0;
> > +sc->sample_sizes[0] = c->avif_extent_lengths[item_index];
> > +sc->chunk_offsets[0] = c->avif_extent_offsets[item_index];
> > +
> > +mov_build_index(c, st);
> > +return 0;
> > +}
> > +
> >  static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> >  {
> >  while (atom.size > 8) {
> > @@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext 
> > *pb, MOVAtom atom)
> >  tag = avio_rl32(pb);
> >  atom.size -= 4;
> >  if (tag == MKTAG('h','d','l','r')) {
> > +int ret;
> >  avio_seek(pb, -8, SEEK_CUR);
> >  atom.size += 8;
> > -return mov_read_default(c, pb, atom);
> > +if ((ret = mov_read_default(c, pb, atom)) < 0)
> > +return ret;
> > +if (c->is_still_picture_avif) {
> > +int ret;
> > +// Add a stream for the YUV planes (primary item).
> > +if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
> > +return ret;
> > +// For still AVIF images, the meta box contains all the
> > +// necessary information that would generally be provided 
> > by the
> > +// moov

Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-27 Thread Andreas Rheinhardt
Vignesh Venkatasubramanian:
> Stores the item ids of all the items found in the file and
> processes the primary item at the end of the meta box. This patch
> does not change any behavior. It sets up the code for parsing
> alpha channel (and possibly images with 'grid') in follow up
> patches.
> 
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  libavformat/isom.h |   4 ++
>  libavformat/mov.c  | 146 -
>  2 files changed, 95 insertions(+), 55 deletions(-)
> 
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index f05c2d9c28..d8b262e915 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -318,6 +318,10 @@ typedef struct MOVContext {
>  uint32_t max_stts_delta;
>  int is_still_picture_avif;
>  int primary_item_id;
> +int *avif_item_ids;
> +int avif_item_ids_size;
> +int *avif_extent_lengths;
> +int64_t *avif_extent_offsets;

Why are these three different buffers instead of one buffer of struct {
int avif_item_ids; int avif_extent_lengths; int64_t avif_extent_offsets;}?

>  } MOVContext;
>  
>  int ff_mp4_read_descr_len(AVIOContext *pb);
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index a09a762d91..fc6a691da4 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  return ret;
>  }
>  
> +static int avif_add_stream(MOVContext *c, int item_id)
> +{
> +MOVStreamContext *sc;
> +AVStream *st;
> +int item_index = -1;
> +for (int i = 0; i < c->avif_item_ids_size; i++)
> +if (c->avif_item_ids[i] == item_id) {
> +item_index = i;
> +break;
> +}
> +if (item_index < 0)
> +return AVERROR_INVALIDDATA;
> +st = avformat_new_stream(c->fc, NULL);
> +if (!st)
> +return AVERROR(ENOMEM);
> +st->id = c->fc->nb_streams;
> +sc = av_mallocz(sizeof(MOVStreamContext));
> +if (!sc)
> +return AVERROR(ENOMEM);
> +
> +st->priv_data = sc;
> +st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
> +st->codecpar->codec_id = AV_CODEC_ID_AV1;
> +sc->ffindex = st->index;
> +c->trak_index = st->index;
> +st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
> +st->time_base.num = st->time_base.den = 1;
> +st->nb_frames = 1;
> +sc->time_scale = 1;
> +sc = st->priv_data;
> +sc->pb = c->fc->pb;
> +sc->pb_is_copied = 1;
> +
> +// Populate the necessary fields used by mov_build_index.
> +sc->stsc_count = 1;
> +sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
> +if (!sc->stsc_data)
> +return AVERROR(ENOMEM);
> +sc->stsc_data[0].first = 1;
> +sc->stsc_data[0].count = 1;
> +sc->stsc_data[0].id = 1;
> +sc->chunk_count = 1;
> +sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
> +if (!sc->chunk_offsets)
> +return AVERROR(ENOMEM);
> +sc->sample_count = 1;
> +sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
> +if (!sc->sample_sizes)
> +return AVERROR(ENOMEM);
> +sc->stts_count = 1;
> +sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
> +if (!sc->stts_data)
> +return AVERROR(ENOMEM);
> +sc->stts_data[0].count = 1;
> +// Not used for still images. But needed by mov_build_index.
> +sc->stts_data[0].duration = 0;
> +sc->sample_sizes[0] = c->avif_extent_lengths[item_index];
> +sc->chunk_offsets[0] = c->avif_extent_offsets[item_index];
> +
> +mov_build_index(c, st);
> +return 0;
> +}
> +
>  static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>  {
>  while (atom.size > 8) {
> @@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  tag = avio_rl32(pb);
>  atom.size -= 4;
>  if (tag == MKTAG('h','d','l','r')) {
> +int ret;
>  avio_seek(pb, -8, SEEK_CUR);
>  atom.size += 8;
> -return mov_read_default(c, pb, atom);
> +if ((ret = mov_read_default(c, pb, atom)) < 0)
> +return ret;
> +if (c->is_still_picture_avif) {
> +int ret;
> +// Add a stream for the YUV planes (primary item).
> +if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
> +return ret;
> +// For still AVIF images, the meta box contains all the
> +// necessary information that would generally be provided by 
> the
> +// moov box. So simply mark that we have found the moov box 
> so
> +// that parsing can continue.
> +c->found_moov = 1;
> +}
> +return ret;
>  }
>  }
>  return 0;
> @@ -7478,8 +7555,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext 
> *pb, MOVAtom atom)
>  int item_count, extent_count;
>  

Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-27 Thread James Zern
On Wed, Jul 27, 2022 at 9:12 AM Vignesh Venkatasubramanian
 wrote:
>
> Stores the item ids of all the items found in the file and
> processes the primary item at the end of the meta box. This patch
> does not change any behavior. It sets up the code for parsing
> alpha channel (and possibly images with 'grid') in follow up
> patches.
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  libavformat/isom.h |   4 ++
>  libavformat/mov.c  | 146 -
>  2 files changed, 95 insertions(+), 55 deletions(-)
>

lgtm. I'll submit this soon if there aren't any other comments.
___
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 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-27 Thread Vignesh Venkatasubramanian
On Tue, Jul 26, 2022 at 12:02 PM James Zern
 wrote:
>
> On Fri, Jul 22, 2022 at 11:21 AM Vignesh Venkatasubramanian
>  wrote:
> >
> > On Wed, Jul 13, 2022 at 9:12 AM Vignesh Venkatasubramanian
> >  wrote:
> > >
> > > On Mon, Jul 11, 2022 at 3:25 PM James Zern
> > >  wrote:
> > > >
> > > > On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
> > > >  wrote:
> > > > >
> > > > > Stores the item ids of all the items found in the file and
> > > > > processes the primary item at the end of the meta box. This patch
> > > > > does not change any behavior. It sets up the code for parsing
> > > > > alpha channel (and possibly images with 'grid') in follow up
> > > > > patches.
> > > > >
> > > > > Signed-off-by: Vignesh Venkatasubramanian 
> > > > > ---
> > > > >  libavformat/isom.h |   4 ++
> > > > >  libavformat/mov.c  | 148 
> > > > > -
> > > > >  2 files changed, 97 insertions(+), 55 deletions(-)
> > > > >
> > > > > [...]
> > > >
> > > > @@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
> > > > AVIOContext *pb, MOVAtom atom)
> > > >  tag = avio_rl32(pb);
> > > >  atom.size -= 4;
> > > >  if (tag == MKTAG('h','d','l','r')) {
> > > > +int ret;
> > > >  avio_seek(pb, -8, SEEK_CUR);
> > > >  atom.size += 8;
> > > > -return mov_read_default(c, pb, atom);
> > > > +ret = mov_read_default(c, pb, atom);
> > > > +if (ret < 0)
> > > >
> > > > In some other cases these two lines are combined, if ((ret = ...
> > > >
> > >
> > > Done.
> > >
> > > > +return ret;
> > > > +if (c->is_still_picture_avif) {
> > > > +int ret;
> > > > +// Add a stream for the YUV planes (primary item).
> > > > +ret = avif_add_stream(c, c->primary_item_id);
> > > > +if (ret)
> > > >
> > > > This could be updated too and use '< 0' to match other code.
> > > >
> > >
> > > Done.
> > >
> > > > +return ret;
> > > > +// For still AVIF images, the meta box contains all the
> > > > +// necessary information that would generally be
> > > > provided by the
> > > > +// moov box. So simply mark that we have found the 
> > > > moov box so
> > > > +// that parsing can continue.
> > > > +c->found_moov = 1;
> > > > +}
> > > > +return ret;
> > > >  }
> > > > ___
> > > > 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
> >
> > Any further comments on this one?
> >
> > Please note that i have abandoned the second patch in this list. But
> > this one is still up for merging.
> >
>
> This looks like it needs to be rebased. I'll take a look after that.

Done.

> ___
> 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".


[FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-27 Thread Vignesh Venkatasubramanian
Stores the item ids of all the items found in the file and
processes the primary item at the end of the meta box. This patch
does not change any behavior. It sets up the code for parsing
alpha channel (and possibly images with 'grid') in follow up
patches.

Signed-off-by: Vignesh Venkatasubramanian 
---
 libavformat/isom.h |   4 ++
 libavformat/mov.c  | 146 -
 2 files changed, 95 insertions(+), 55 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index f05c2d9c28..d8b262e915 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -318,6 +318,10 @@ typedef struct MOVContext {
 uint32_t max_stts_delta;
 int is_still_picture_avif;
 int primary_item_id;
+int *avif_item_ids;
+int avif_item_ids_size;
+int *avif_extent_lengths;
+int64_t *avif_extent_offsets;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a09a762d91..fc6a691da4 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4698,6 +4698,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return ret;
 }
 
+static int avif_add_stream(MOVContext *c, int item_id)
+{
+MOVStreamContext *sc;
+AVStream *st;
+int item_index = -1;
+for (int i = 0; i < c->avif_item_ids_size; i++)
+if (c->avif_item_ids[i] == item_id) {
+item_index = i;
+break;
+}
+if (item_index < 0)
+return AVERROR_INVALIDDATA;
+st = avformat_new_stream(c->fc, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->id = c->fc->nb_streams;
+sc = av_mallocz(sizeof(MOVStreamContext));
+if (!sc)
+return AVERROR(ENOMEM);
+
+st->priv_data = sc;
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id = AV_CODEC_ID_AV1;
+sc->ffindex = st->index;
+c->trak_index = st->index;
+st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
+st->time_base.num = st->time_base.den = 1;
+st->nb_frames = 1;
+sc->time_scale = 1;
+sc = st->priv_data;
+sc->pb = c->fc->pb;
+sc->pb_is_copied = 1;
+
+// Populate the necessary fields used by mov_build_index.
+sc->stsc_count = 1;
+sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
+if (!sc->stsc_data)
+return AVERROR(ENOMEM);
+sc->stsc_data[0].first = 1;
+sc->stsc_data[0].count = 1;
+sc->stsc_data[0].id = 1;
+sc->chunk_count = 1;
+sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
+if (!sc->chunk_offsets)
+return AVERROR(ENOMEM);
+sc->sample_count = 1;
+sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
+if (!sc->sample_sizes)
+return AVERROR(ENOMEM);
+sc->stts_count = 1;
+sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
+if (!sc->stts_data)
+return AVERROR(ENOMEM);
+sc->stts_data[0].count = 1;
+// Not used for still images. But needed by mov_build_index.
+sc->stts_data[0].duration = 0;
+sc->sample_sizes[0] = c->avif_extent_lengths[item_index];
+sc->chunk_offsets[0] = c->avif_extent_offsets[item_index];
+
+mov_build_index(c, st);
+return 0;
+}
+
 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 while (atom.size > 8) {
@@ -4707,9 +4770,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+if ((ret = mov_read_default(c, pb, atom)) < 0)
+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be provided by 
the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
 }
 return 0;
@@ -7478,8 +7555,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int item_count, extent_count;
 uint64_t base_offset, extent_offset, extent_length;
 uint8_t value;
-AVStream *st;
-MOVStreamContext *sc;
 
 if (!c->is_still_picture_avif) {
 // * For non-avif, we simply ignore the iloc box.
@@ -7493,27 +7568,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
-st = avformat_new_stream(c->fc, NULL);
-if (!st)
-return AVERROR(ENOMEM);
-st->id

Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-26 Thread James Zern
On Fri, Jul 22, 2022 at 11:21 AM Vignesh Venkatasubramanian
 wrote:
>
> On Wed, Jul 13, 2022 at 9:12 AM Vignesh Venkatasubramanian
>  wrote:
> >
> > On Mon, Jul 11, 2022 at 3:25 PM James Zern
> >  wrote:
> > >
> > > On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
> > >  wrote:
> > > >
> > > > Stores the item ids of all the items found in the file and
> > > > processes the primary item at the end of the meta box. This patch
> > > > does not change any behavior. It sets up the code for parsing
> > > > alpha channel (and possibly images with 'grid') in follow up
> > > > patches.
> > > >
> > > > Signed-off-by: Vignesh Venkatasubramanian 
> > > > ---
> > > >  libavformat/isom.h |   4 ++
> > > >  libavformat/mov.c  | 148 -
> > > >  2 files changed, 97 insertions(+), 55 deletions(-)
> > > >
> > > > [...]
> > >
> > > @@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
> > > AVIOContext *pb, MOVAtom atom)
> > >  tag = avio_rl32(pb);
> > >  atom.size -= 4;
> > >  if (tag == MKTAG('h','d','l','r')) {
> > > +int ret;
> > >  avio_seek(pb, -8, SEEK_CUR);
> > >  atom.size += 8;
> > > -return mov_read_default(c, pb, atom);
> > > +ret = mov_read_default(c, pb, atom);
> > > +if (ret < 0)
> > >
> > > In some other cases these two lines are combined, if ((ret = ...
> > >
> >
> > Done.
> >
> > > +return ret;
> > > +if (c->is_still_picture_avif) {
> > > +int ret;
> > > +// Add a stream for the YUV planes (primary item).
> > > +ret = avif_add_stream(c, c->primary_item_id);
> > > +if (ret)
> > >
> > > This could be updated too and use '< 0' to match other code.
> > >
> >
> > Done.
> >
> > > +return ret;
> > > +// For still AVIF images, the meta box contains all the
> > > +// necessary information that would generally be
> > > provided by the
> > > +// moov box. So simply mark that we have found the moov 
> > > box so
> > > +// that parsing can continue.
> > > +c->found_moov = 1;
> > > +}
> > > +return ret;
> > >  }
> > > ___
> > > 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
>
> Any further comments on this one?
>
> Please note that i have abandoned the second patch in this list. But
> this one is still up for merging.
>

This looks like it needs to be rebased. I'll take a look after that.
___
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 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-22 Thread Vignesh Venkatasubramanian
On Wed, Jul 13, 2022 at 9:12 AM Vignesh Venkatasubramanian
 wrote:
>
> On Mon, Jul 11, 2022 at 3:25 PM James Zern
>  wrote:
> >
> > On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
> >  wrote:
> > >
> > > Stores the item ids of all the items found in the file and
> > > processes the primary item at the end of the meta box. This patch
> > > does not change any behavior. It sets up the code for parsing
> > > alpha channel (and possibly images with 'grid') in follow up
> > > patches.
> > >
> > > Signed-off-by: Vignesh Venkatasubramanian 
> > > ---
> > >  libavformat/isom.h |   4 ++
> > >  libavformat/mov.c  | 148 -
> > >  2 files changed, 97 insertions(+), 55 deletions(-)
> > >
> > > [...]
> >
> > @@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
> > AVIOContext *pb, MOVAtom atom)
> >  tag = avio_rl32(pb);
> >  atom.size -= 4;
> >  if (tag == MKTAG('h','d','l','r')) {
> > +int ret;
> >  avio_seek(pb, -8, SEEK_CUR);
> >  atom.size += 8;
> > -return mov_read_default(c, pb, atom);
> > +ret = mov_read_default(c, pb, atom);
> > +if (ret < 0)
> >
> > In some other cases these two lines are combined, if ((ret = ...
> >
>
> Done.
>
> > +return ret;
> > +if (c->is_still_picture_avif) {
> > +int ret;
> > +// Add a stream for the YUV planes (primary item).
> > +ret = avif_add_stream(c, c->primary_item_id);
> > +if (ret)
> >
> > This could be updated too and use '< 0' to match other code.
> >
>
> Done.
>
> > +return ret;
> > +// For still AVIF images, the meta box contains all the
> > +// necessary information that would generally be
> > provided by the
> > +// moov box. So simply mark that we have found the moov 
> > box so
> > +// that parsing can continue.
> > +c->found_moov = 1;
> > +}
> > +return ret;
> >  }
> > ___
> > 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

Any further comments on this one?

Please note that i have abandoned the second patch in this list. But
this one is still up for merging.

-- 
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 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-13 Thread Vignesh Venkatasubramanian
On Mon, Jul 11, 2022 at 3:25 PM James Zern
 wrote:
>
> On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
>  wrote:
> >
> > Stores the item ids of all the items found in the file and
> > processes the primary item at the end of the meta box. This patch
> > does not change any behavior. It sets up the code for parsing
> > alpha channel (and possibly images with 'grid') in follow up
> > patches.
> >
> > Signed-off-by: Vignesh Venkatasubramanian 
> > ---
> >  libavformat/isom.h |   4 ++
> >  libavformat/mov.c  | 148 -
> >  2 files changed, 97 insertions(+), 55 deletions(-)
> >
> > [...]
>
> @@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
>  tag = avio_rl32(pb);
>  atom.size -= 4;
>  if (tag == MKTAG('h','d','l','r')) {
> +int ret;
>  avio_seek(pb, -8, SEEK_CUR);
>  atom.size += 8;
> -return mov_read_default(c, pb, atom);
> +ret = mov_read_default(c, pb, atom);
> +if (ret < 0)
>
> In some other cases these two lines are combined, if ((ret = ...
>

Done.

> +return ret;
> +if (c->is_still_picture_avif) {
> +int ret;
> +// Add a stream for the YUV planes (primary item).
> +ret = avif_add_stream(c, c->primary_item_id);
> +if (ret)
>
> This could be updated too and use '< 0' to match other code.
>

Done.

> +return ret;
> +// For still AVIF images, the meta box contains all the
> +// necessary information that would generally be
> provided by the
> +// moov box. So simply mark that we have found the moov box 
> so
> +// that parsing can continue.
> +c->found_moov = 1;
> +}
> +return ret;
>  }
> ___
> 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".


[FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-13 Thread Vignesh Venkatasubramanian
Stores the item ids of all the items found in the file and
processes the primary item at the end of the meta box. This patch
does not change any behavior. It sets up the code for parsing
alpha channel (and possibly images with 'grid') in follow up
patches.

Signed-off-by: Vignesh Venkatasubramanian 
---
 libavformat/isom.h |   4 ++
 libavformat/mov.c  | 146 -
 2 files changed, 95 insertions(+), 55 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index f05c2d9c28..d8b262e915 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -318,6 +318,10 @@ typedef struct MOVContext {
 uint32_t max_stts_delta;
 int is_still_picture_avif;
 int primary_item_id;
+int *avif_item_ids;
+int avif_item_ids_size;
+int *avif_extent_lengths;
+int64_t *avif_extent_offsets;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 88669faa70..cd87088f3e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4683,6 +4683,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return ret;
 }
 
+static int avif_add_stream(MOVContext *c, int item_id)
+{
+MOVStreamContext *sc;
+AVStream *st;
+int item_index = -1;
+for (int i = 0; i < c->avif_item_ids_size; i++)
+if (c->avif_item_ids[i] == item_id) {
+item_index = i;
+break;
+}
+if (item_index < 0)
+return AVERROR_INVALIDDATA;
+st = avformat_new_stream(c->fc, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->id = c->fc->nb_streams;
+sc = av_mallocz(sizeof(MOVStreamContext));
+if (!sc)
+return AVERROR(ENOMEM);
+
+st->priv_data = sc;
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id = AV_CODEC_ID_AV1;
+sc->ffindex = st->index;
+c->trak_index = st->index;
+st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
+st->time_base.num = st->time_base.den = 1;
+st->nb_frames = 1;
+sc->time_scale = 1;
+sc = st->priv_data;
+sc->pb = c->fc->pb;
+sc->pb_is_copied = 1;
+
+// Populate the necessary fields used by mov_build_index.
+sc->stsc_count = 1;
+sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
+if (!sc->stsc_data)
+return AVERROR(ENOMEM);
+sc->stsc_data[0].first = 1;
+sc->stsc_data[0].count = 1;
+sc->stsc_data[0].id = 1;
+sc->chunk_count = 1;
+sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
+if (!sc->chunk_offsets)
+return AVERROR(ENOMEM);
+sc->sample_count = 1;
+sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
+if (!sc->sample_sizes)
+return AVERROR(ENOMEM);
+sc->stts_count = 1;
+sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
+if (!sc->stts_data)
+return AVERROR(ENOMEM);
+sc->stts_data[0].count = 1;
+// Not used for still images. But needed by mov_build_index.
+sc->stts_data[0].duration = 0;
+sc->sample_sizes[0] = c->avif_extent_lengths[item_index];
+sc->chunk_offsets[0] = c->avif_extent_offsets[item_index];
+
+mov_build_index(c, st);
+return 0;
+}
+
 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 while (atom.size > 8) {
@@ -4692,9 +4755,23 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+if ((ret = mov_read_default(c, pb, atom)) < 0)
+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+if ((ret = avif_add_stream(c, c->primary_item_id)) < 0)
+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be provided by 
the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
 }
 return 0;
@@ -7483,8 +7560,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int item_count, extent_count;
 uint64_t base_offset, extent_offset, extent_length;
 uint8_t value;
-AVStream *st;
-MOVStreamContext *sc;
 
 if (!c->is_still_picture_avif) {
 // * For non-avif, we simply ignore the iloc box.
@@ -7498,27 +7573,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
-st = avformat_new_stream(c->fc, NULL);
-if (!st)
-return AVERROR(ENOMEM);
-st->id

Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-07-11 Thread James Zern
On Thu, Jun 30, 2022 at 2:04 PM Vignesh Venkatasubramanian
 wrote:
>
> Stores the item ids of all the items found in the file and
> processes the primary item at the end of the meta box. This patch
> does not change any behavior. It sets up the code for parsing
> alpha channel (and possibly images with 'grid') in follow up
> patches.
>
> Signed-off-by: Vignesh Venkatasubramanian 
> ---
>  libavformat/isom.h |   4 ++
>  libavformat/mov.c  | 148 -
>  2 files changed, 97 insertions(+), 55 deletions(-)
>
> [...]

@@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c,
AVIOContext *pb, MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+ret = mov_read_default(c, pb, atom);
+if (ret < 0)

In some other cases these two lines are combined, if ((ret = ...

+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+ret = avif_add_stream(c, c->primary_item_id);
+if (ret)

This could be updated too and use '< 0' to match other code.

+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be
provided by the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
___
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] [PATCH 1/2] avformat/mov: Rework the AVIF parser to handle multiple items

2022-06-30 Thread Vignesh Venkatasubramanian
Stores the item ids of all the items found in the file and
processes the primary item at the end of the meta box. This patch
does not change any behavior. It sets up the code for parsing
alpha channel (and possibly images with 'grid') in follow up
patches.

Signed-off-by: Vignesh Venkatasubramanian 
---
 libavformat/isom.h |   4 ++
 libavformat/mov.c  | 148 -
 2 files changed, 97 insertions(+), 55 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index f05c2d9c28..d8b262e915 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -318,6 +318,10 @@ typedef struct MOVContext {
 uint32_t max_stts_delta;
 int is_still_picture_avif;
 int primary_item_id;
+int *avif_item_ids;
+int avif_item_ids_size;
+int *avif_extent_lengths;
+int64_t *avif_extent_offsets;
 } MOVContext;
 
 int ff_mp4_read_descr_len(AVIOContext *pb);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 88669faa70..9df5055d4e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4683,6 +4683,69 @@ static int mov_read_custom(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return ret;
 }
 
+static int avif_add_stream(MOVContext *c, int item_id)
+{
+MOVStreamContext *sc;
+AVStream *st;
+int item_index = -1;
+for (int i = 0; i < c->avif_item_ids_size; i++)
+if (c->avif_item_ids[i] == item_id) {
+item_index = i;
+break;
+}
+if (item_index < 0)
+return AVERROR_INVALIDDATA;
+st = avformat_new_stream(c->fc, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->id = c->fc->nb_streams;
+sc = av_mallocz(sizeof(MOVStreamContext));
+if (!sc)
+return AVERROR(ENOMEM);
+
+st->priv_data = sc;
+st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+st->codecpar->codec_id = AV_CODEC_ID_AV1;
+sc->ffindex = st->index;
+c->trak_index = st->index;
+st->avg_frame_rate.num = st->avg_frame_rate.den = 1;
+st->time_base.num = st->time_base.den = 1;
+st->nb_frames = 1;
+sc->time_scale = 1;
+sc = st->priv_data;
+sc->pb = c->fc->pb;
+sc->pb_is_copied = 1;
+
+// Populate the necessary fields used by mov_build_index.
+sc->stsc_count = 1;
+sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
+if (!sc->stsc_data)
+return AVERROR(ENOMEM);
+sc->stsc_data[0].first = 1;
+sc->stsc_data[0].count = 1;
+sc->stsc_data[0].id = 1;
+sc->chunk_count = 1;
+sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
+if (!sc->chunk_offsets)
+return AVERROR(ENOMEM);
+sc->sample_count = 1;
+sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
+if (!sc->sample_sizes)
+return AVERROR(ENOMEM);
+sc->stts_count = 1;
+sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
+if (!sc->stts_data)
+return AVERROR(ENOMEM);
+sc->stts_data[0].count = 1;
+// Not used for still images. But needed by mov_build_index.
+sc->stts_data[0].duration = 0;
+sc->sample_sizes[0] = c->avif_extent_lengths[item_index];
+sc->chunk_offsets[0] = c->avif_extent_offsets[item_index];
+
+mov_build_index(c, st);
+return 0;
+}
+
 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 while (atom.size > 8) {
@@ -4692,9 +4755,25 @@ static int mov_read_meta(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 tag = avio_rl32(pb);
 atom.size -= 4;
 if (tag == MKTAG('h','d','l','r')) {
+int ret;
 avio_seek(pb, -8, SEEK_CUR);
 atom.size += 8;
-return mov_read_default(c, pb, atom);
+ret = mov_read_default(c, pb, atom);
+if (ret < 0)
+return ret;
+if (c->is_still_picture_avif) {
+int ret;
+// Add a stream for the YUV planes (primary item).
+ret = avif_add_stream(c, c->primary_item_id);
+if (ret)
+return ret;
+// For still AVIF images, the meta box contains all the
+// necessary information that would generally be provided by 
the
+// moov box. So simply mark that we have found the moov box so
+// that parsing can continue.
+c->found_moov = 1;
+}
+return ret;
 }
 }
 return 0;
@@ -7483,8 +7562,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 int item_count, extent_count;
 uint64_t base_offset, extent_offset, extent_length;
 uint8_t value;
-AVStream *st;
-MOVStreamContext *sc;
 
 if (!c->is_still_picture_avif) {
 // * For non-avif, we simply ignore the iloc box.
@@ -7498,27 +7575,6 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
-st = avformat_new_stream(c->fc, NULL);
-if (!st)
-ret