Re: [FFmpeg-devel] [PATCH 1/8] libavcodec/jpeg2000_parser: Speed up long skips

2022-06-03 Thread Tomas Härdin
tor 2022-06-02 klockan 21:19 +0200 skrev Michael Niedermayer:
> On Thu, Jun 02, 2022 at 11:54:39AM +0200, Tomas Härdin wrote:
> > ons 2022-06-01 klockan 18:23 +0200 skrev Michael Niedermayer:
> > > On Wed, Jun 01, 2022 at 06:21:19PM +0200, Michael Niedermayer
> > > wrote:
> > > > On Tue, May 31, 2022 at 11:58:39AM +0200, Tomas Härdin wrote:
> > > > > 
> > > > 
> > > > >  jpeg2000_parser.c |   11 +++
> > > > >  1 file changed, 11 insertions(+)
> > > > > 634546fb5a0eb281eea87ad7471c503f5bc9e8ab  0001-libavcodec-
> > > > > jpeg2000_parser-Speed-up-long-skips.patch
> > > > > From fedd7f9ae2c691a25c37be935d7547be61d46017 Mon Sep 17
> > > > > 00:00:00
> > > > > 2001
> > > > > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
> > > > > Date: Fri, 20 May 2022 11:38:25 +0200
> > > > > Subject: [PATCH 1/8] libavcodec/jpeg2000_parser: Speed up
> > > > > long
> > > > > skips
> > > > > 
> > > > > ---
> > > > >  libavcodec/jpeg2000_parser.c | 11 +++
> > > > >  1 file changed, 11 insertions(+)
> > > > 
> > > > breaks
> > > > j2kref/codestreams_profile1/p1_04.j2k
> > > 
> > > [jpeg2000 @ 0x7fb0b8002600] Psot 66195 too big
> > > [jpeg2000 @ 0x7fb0b8002600] error during processing marker
> > > segment
> > > ff90
> > > Input #0, j2k_pipe, from 'j2kref/codestreams_profile1/p1_04.j2k':
> > >   Duration: N/A, bitrate: N/A
> > >   Stream #0:0: Video: jpeg2000 (JPEG 2000 codestream restriction
> > > 1),
> > > gray16le(12 bpc), 1024x1024, 25 fps, 25 tbr, 25 tbn
> > > [jpeg2000 @ 0x7fb0b8003240] unsupported marker 0x97C8 at pos
> > > 0x6F0
> > > [jpeg2000 @ 0x7fb0b8003240] Missing EOC Marker.
> > > [jpeg2000 @ 0x7fb0b8032280] unsupported marker 0x97C8 at pos
> > > 0x6F0
> > > [jpeg2000 @ 0x7fb0b8032280] Missing EOC Marker.
> > > [jpeg2000 @ 0x7fb0b8006280] Psot 66195 too big
> > > [jpeg2000 @ 0x7fb0b8006280] error during processing marker
> > > segment
> > > ff90
> > 
> > Took a while to figure out, but this is due to buf_size - i - 9
> > being
> > changed to unsigned because of the uint32_t. Try attached patch.
> > The
> > rest of the set should work with it.
> 
> works fine here

Great

> > Can we roll these tests into FATE?
> 
> feel free to do so. 
> ill test if someone posts a patch

How are you testing them? Just decoding and checking that the output is
the same as some reference output? Just looking for non-zero exit code?

/Tomas

___
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] avcodec: add QOI decoder and demuxer and parser and encoder and muxer

2022-06-03 Thread Tomas Härdin
> +bytestream_put_buffer(&buf, "qoif", 4);
> +bytestream_put_be32(&buf, avctx->width);
> +bytestream_put_be32(&buf, avctx->height);
> +bytestream_put_byte(&buf, channels);
> +bytestream_put_byte(&buf, 0);

bytestream_put_byte(&buf, avctx->color_trc == AVCOL_TRC_LINEAR);

Looks good otherwise

/Tomas

___
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 0/6] avformat/movenc: normalize on AC-3 parser usage

2022-06-03 Thread Jan Ekström
The simplified parsing currently in `mov_write_ac3_tag` trusts the content
of the packets a bit too much (the AC-3 parser returns all data fed to it,
including any possible data before the start code), while the existing E-AC-3
logic does proper header validation by utilizing the (E-)AC-3 parser.

Thus, normalize on AC-3 parser usage for both AC-3 and E-AC-3. 

Jan Ekström (6):
  avcodec/ac3_parser{,_internal}: expose AC-3 bit_rate_code
  {configure,avformat/movenc}: enable AC-3 parser for movenc
  avformat/movenc: enable handle_eac3 to handle AC-3 tracks
  avformat/movenc: move eac3_info definition so that it can be used for
AC-3
  avformat/movenc: utilize existing AC-3 parsing workflow for AC-3
  avformat/movenc: handle OOM situations when parsing AC-3 headers

 configure|   2 +-
 libavcodec/ac3_parser.c  |   3 +
 libavcodec/ac3_parser_internal.h |   1 +
 libavformat/movenc.c | 123 ---
 4 files changed, 69 insertions(+), 60 deletions(-)

-- 
2.36.1

___
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/6] avcodec/ac3_parser{, _internal}: expose AC-3 bit_rate_code

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

Required by MP4's AC3SpecificBox and MPEG-TS AC-3 audio_descriptor,
of which the former is implemented in our MP4 writer.

Signed-off-by: Jan Ekström 
---
 libavcodec/ac3_parser.c  | 3 +++
 libavcodec/ac3_parser_internal.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 119b1598c5..852c9e6b0d 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -70,6 +70,7 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo 
*hdr)
 return AAC_AC3_PARSE_ERROR_BSID;
 
 hdr->num_blocks = 6;
+hdr->ac3_bit_rate_code = -1;
 
 /* set default mix levels */
 hdr->center_mix_level   = 5;  // -4.5dB
@@ -89,6 +90,8 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo 
*hdr)
 if(frame_size_code > 37)
 return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
 
+hdr->ac3_bit_rate_code = (frame_size_code >> 1);
+
 skip_bits(gbc, 5); // skip bsid, already got it
 
 hdr->bitstream_mode = get_bits(gbc, 3);
diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
index dd57dc95a6..bd4e1bbffb 100644
--- a/libavcodec/ac3_parser_internal.h
+++ b/libavcodec/ac3_parser_internal.h
@@ -60,6 +60,7 @@ typedef struct AC3HeaderInfo {
 uint8_t channels;
 uint16_t frame_size;
 uint64_t channel_layout;
+int8_t ac3_bit_rate_code;
 /** @} */
 } AC3HeaderInfo;
 
-- 
2.36.1

___
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 2/6] {configure, avformat/movenc}: enable AC-3 parser for movenc

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

This simplifies the code to no longer have #ifs in a manner which
does not require handling avpriv_ac3_parse_header returning ENOSYS.

As an existing example, the MPEG-TS muxer already requires the AC-3
parser, and in order to fix existing issues with the current AC-3
movenc code, switching to use the AC-3 parser is required, so this
is an enabling change for that.

Signed-off-by: Jan Ekström 
---
 configure| 2 +-
 libavformat/movenc.c | 4 
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/configure b/configure
index 5a167613a4..a4e8e33b83 100755
--- a/configure
+++ b/configure
@@ -3440,7 +3440,7 @@ mlp_demuxer_select="mlp_parser"
 mmf_muxer_select="riffenc"
 mov_demuxer_select="iso_media riffdec"
 mov_demuxer_suggest="zlib"
-mov_muxer_select="iso_media riffenc rtpenc_chain vp9_superframe_bsf 
aac_adtstoasc_bsf"
+mov_muxer_select="iso_media riffenc rtpenc_chain vp9_superframe_bsf 
aac_adtstoasc_bsf ac3_parser"
 mp3_demuxer_select="mpegaudio_parser"
 mp3_muxer_select="mpegaudioheader"
 mp4_muxer_select="mov_muxer"
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index de971f94e8..63713e5640 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -407,7 +407,6 @@ struct eac3_info {
 } substream[1]; /* TODO: support 8 independent substreams */
 };
 
-#if CONFIG_AC3_PARSER
 static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
 {
 AC3HeaderInfo *hdr = NULL;
@@ -548,7 +547,6 @@ end:
 
 return ret;
 }
-#endif
 
 static int mov_write_eac3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
 {
@@ -6045,7 +6043,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 }
 }
 
-#if CONFIG_AC3_PARSER
 } else if (par->codec_id == AV_CODEC_ID_EAC3) {
 size = handle_eac3(mov, pkt, trk);
 if (size < 0)
@@ -6053,7 +6050,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 else if (!size)
 goto end;
 avio_write(pb, pkt->data, size);
-#endif
 } else if (par->codec_id == AV_CODEC_ID_EIA_608) {
 size = 8;
 
-- 
2.36.1

___
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 3/6] avformat/movenc: enable handle_eac3 to handle AC-3 tracks

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

Add the AC-3 frame type, as well as early exit from additional packet
parsing in case of AC-3, as only a single packet is required to get
the required information.

Additionally, expose ac3_bit_rate_code via the eac3_info struct as
it is required for AC3SpecificBox.

Signed-off-by: Jan Ekström 
---
 libavformat/movenc.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 63713e5640..2589f2f4bb 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -383,6 +383,7 @@ struct eac3_info {
 /* Layout of the EC3SpecificBox */
 /* maximum bitrate */
 uint16_t data_rate;
+int8_t   ac3_bit_rate_code;
 /* number of independent substreams */
 uint8_t  num_ind_sub;
 struct {
@@ -413,8 +414,12 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 struct eac3_info *info;
 int num_blocks, ret;
 
-if (!track->eac3_priv && !(track->eac3_priv = av_mallocz(sizeof(*info
-return AVERROR(ENOMEM);
+if (!track->eac3_priv) {
+if (!(track->eac3_priv = av_mallocz(sizeof(*info
+return AVERROR(ENOMEM);
+
+((struct eac3_info *)track->eac3_priv)->ac3_bit_rate_code = -1;
+}
 info = track->eac3_priv;
 
 if (!info->pkt && !(info->pkt = av_packet_alloc()))
@@ -431,6 +436,8 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 }
 
 info->data_rate = FFMAX(info->data_rate, hdr->bit_rate / 1000);
+info->ac3_bit_rate_code = FFMAX(info->ac3_bit_rate_code,
+hdr->ac3_bit_rate_code);
 num_blocks = hdr->num_blocks;
 
 if (!info->ec3_done) {
@@ -442,7 +449,8 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 
 /* this should always be the case, given that our AC-3 parser
  * concatenates dependent frames to their independent parent */
-if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
+if (hdr->frame_type == EAC3_FRAME_TYPE_INDEPENDENT ||
+hdr->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT) {
 /* substream ids must be incremental */
 if (hdr->substreamid > info->num_ind_sub + 1) {
 ret = AVERROR(EINVAL);
@@ -474,6 +482,14 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 info->substream[hdr->substreamid].acmod = hdr->channel_mode;
 info->substream[hdr->substreamid].lfeon = hdr->lfe_on;
 
+if (track->par->codec_id == AV_CODEC_ID_AC3) {
+// with AC-3 we only require the information of a single packet,
+// so we can finish as soon as the basic values of the bit stream
+// have been set to the track's informational structure.
+info->ec3_done = 1;
+goto concatenate;
+}
+
 /* Parse dependent substream(s), if any */
 if (pkt->size != hdr->frame_size) {
 int cumul_size = hdr->frame_size;
-- 
2.36.1

___
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 4/6] avformat/movenc: move eac3_info definition so that it can be used for AC-3

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavformat/movenc.c | 66 ++--
 1 file changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 2589f2f4bb..5bc1f4c7a4 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -327,6 +327,39 @@ static int mov_write_amr_tag(AVIOContext *pb, MOVTrack 
*track)
 return 0x11;
 }
 
+struct eac3_info {
+AVPacket *pkt;
+uint8_t ec3_done;
+uint8_t num_blocks;
+
+/* Layout of the EC3SpecificBox */
+/* maximum bitrate */
+uint16_t data_rate;
+int8_t   ac3_bit_rate_code;
+/* number of independent substreams */
+uint8_t  num_ind_sub;
+struct {
+/* sample rate code (see ff_ac3_sample_rate_tab) 2 bits */
+uint8_t fscod;
+/* bit stream identification 5 bits */
+uint8_t bsid;
+/* one bit reserved */
+/* audio service mixing (not supported yet) 1 bit */
+/* bit stream mode 3 bits */
+uint8_t bsmod;
+/* audio coding mode 3 bits */
+uint8_t acmod;
+/* sub woofer on 1 bit */
+uint8_t lfeon;
+/* 3 bits reserved */
+/* number of dependent substreams associated with this substream 4 
bits */
+uint8_t num_dep_sub;
+/* channel locations of the dependent substream(s), if any, 9 bits */
+uint16_t chan_loc;
+/* if there is no dependent substream, then one bit reserved instead */
+} substream[1]; /* TODO: support 8 independent substreams */
+};
+
 static int mov_write_ac3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
 {
 GetBitContext gbc;
@@ -375,39 +408,6 @@ static int mov_write_ac3_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *trac
 return 11;
 }
 
-struct eac3_info {
-AVPacket *pkt;
-uint8_t ec3_done;
-uint8_t num_blocks;
-
-/* Layout of the EC3SpecificBox */
-/* maximum bitrate */
-uint16_t data_rate;
-int8_t   ac3_bit_rate_code;
-/* number of independent substreams */
-uint8_t  num_ind_sub;
-struct {
-/* sample rate code (see ff_ac3_sample_rate_tab) 2 bits */
-uint8_t fscod;
-/* bit stream identification 5 bits */
-uint8_t bsid;
-/* one bit reserved */
-/* audio service mixing (not supported yet) 1 bit */
-/* bit stream mode 3 bits */
-uint8_t bsmod;
-/* audio coding mode 3 bits */
-uint8_t acmod;
-/* sub woofer on 1 bit */
-uint8_t lfeon;
-/* 3 bits reserved */
-/* number of dependent substreams associated with this substream 4 
bits */
-uint8_t num_dep_sub;
-/* channel locations of the dependent substream(s), if any, 9 bits */
-uint16_t chan_loc;
-/* if there is no dependent substream, then one bit reserved instead */
-} substream[1]; /* TODO: support 8 independent substreams */
-};
-
 static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track)
 {
 AC3HeaderInfo *hdr = NULL;
-- 
2.36.1

___
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 5/6] avformat/movenc: utilize existing AC-3 parsing workflow for AC-3

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavformat/movenc.c | 46 +---
 1 file changed, 18 insertions(+), 28 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 5bc1f4c7a4..a1daf3598b 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -362,44 +362,34 @@ struct eac3_info {
 
 static int mov_write_ac3_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
 {
-GetBitContext gbc;
+struct eac3_info *info = track->eac3_priv;
 PutBitContext pbc;
 uint8_t buf[3];
-int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;
 
-if (track->vos_len < 7) {
+if (!info || !info->ec3_done) {
 av_log(s, AV_LOG_ERROR,
"Cannot write moov atom before AC3 packets."
" Set the delay_moov flag to fix this.\n");
 return AVERROR(EINVAL);
 }
 
+if (info->ac3_bit_rate_code < 0) {
+av_log(s, AV_LOG_ERROR,
+   "No valid AC3 bit rate code for data rate of %d!\n",
+   info->data_rate);
+return AVERROR(EINVAL);
+}
+
 avio_wb32(pb, 11);
 ffio_wfourcc(pb, "dac3");
 
-init_get_bits(&gbc, track->vos_data + 4, (track->vos_len - 4) * 8);
-fscod  = get_bits(&gbc, 2);
-frmsizecod = get_bits(&gbc, 6);
-bsid   = get_bits(&gbc, 5);
-bsmod  = get_bits(&gbc, 3);
-acmod  = get_bits(&gbc, 3);
-if (acmod == 2) {
-skip_bits(&gbc, 2); // dsurmod
-} else {
-if ((acmod & 1) && acmod != 1)
-skip_bits(&gbc, 2); // cmixlev
-if (acmod & 4)
-skip_bits(&gbc, 2); // surmixlev
-}
-lfeon = get_bits1(&gbc);
-
 init_put_bits(&pbc, buf, sizeof(buf));
-put_bits(&pbc, 2, fscod);
-put_bits(&pbc, 5, bsid);
-put_bits(&pbc, 3, bsmod);
-put_bits(&pbc, 3, acmod);
-put_bits(&pbc, 1, lfeon);
-put_bits(&pbc, 5, frmsizecod >> 1); // bit_rate_code
+put_bits(&pbc, 2, info->substream[0].fscod);
+put_bits(&pbc, 5, info->substream[0].bsid);
+put_bits(&pbc, 3, info->substream[0].bsmod);
+put_bits(&pbc, 3, info->substream[0].acmod);
+put_bits(&pbc, 1, info->substream[0].lfeon);
+put_bits(&pbc, 5, info->ac3_bit_rate_code); // bit_rate_code
 put_bits(&pbc, 5, 0); // reserved
 
 flush_put_bits(&pbc);
@@ -5981,8 +5971,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 if ((par->codec_id == AV_CODEC_ID_DNXHD ||
  par->codec_id == AV_CODEC_ID_H264 ||
  par->codec_id == AV_CODEC_ID_HEVC ||
- par->codec_id == AV_CODEC_ID_TRUEHD ||
- par->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len &&
+ par->codec_id == AV_CODEC_ID_TRUEHD) && !trk->vos_len &&
  !TAG_IS_AVCI(trk->tag)) {
 /* copy frame to create needed atoms */
 trk->vos_len  = size;
@@ -6059,7 +6048,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
 }
 }
 
-} else if (par->codec_id == AV_CODEC_ID_EAC3) {
+} else if (par->codec_id == AV_CODEC_ID_EAC3 ||
+   par->codec_id == AV_CODEC_ID_AC3) {
 size = handle_eac3(mov, pkt, trk);
 if (size < 0)
 return size;
-- 
2.36.1

___
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 6/6] avformat/movenc: handle OOM situations when parsing AC-3 headers

2022-06-03 Thread Jan Ekström
From: Jan Ekström 

Signed-off-by: Jan Ekström 
---
 libavformat/movenc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index a1daf3598b..0f92f0e04e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -415,7 +415,10 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, 
MOVTrack *track)
 if (!info->pkt && !(info->pkt = av_packet_alloc()))
 return AVERROR(ENOMEM);
 
-if (avpriv_ac3_parse_header(&hdr, pkt->data, pkt->size) < 0) {
+if ((ret = avpriv_ac3_parse_header(&hdr, pkt->data, pkt->size) < 0)) {
+if (ret == AVERROR(ENOMEM))
+goto end;
+
 /* drop the packets until we see a good one */
 if (!track->entry) {
 av_log(mov->fc, AV_LOG_WARNING, "Dropping invalid packet from 
start of the stream\n");
-- 
2.36.1

___
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] avformat/cafdec: Implement FLAC-in-CAF parsing

2022-06-03 Thread Martijn van Beurden
The afconvert utility shipped with MacOS supports muxing of FLAC
in CAF, see afconvert help output on a recent Mac here:
https://hydrogenaud.io/index.php?topic=122509.0 A file created
with afconvert free of copyright (licensed CC0) can be found here:
http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf

This patch implements parsing of such a file
---
 libavformat/caf.c|  1 +
 libavformat/cafdec.c | 41 +
 2 files changed, 42 insertions(+)

diff --git a/libavformat/caf.c b/libavformat/caf.c
index a700e4055b..a61c39fae5 100644
--- a/libavformat/caf.c
+++ b/libavformat/caf.c
@@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = {
 { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') },
 { AV_CODEC_ID_GSM_MS,  MKTAG('m','s', 0, '1') },
 { AV_CODEC_ID_ILBC,MKTAG('i','l','b','c') },
+{ AV_CODEC_ID_FLAC,MKTAG('f','l','a','c') },
 { AV_CODEC_ID_MACE3,   MKTAG('M','A','C','3') },
 { AV_CODEC_ID_MACE6,   MKTAG('M','A','C','6') },
 { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') },
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 168f69f20b..72a74ab297 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -31,6 +31,7 @@
 #include "demux.h"
 #include "internal.h"
 #include "isom.h"
+#include "libavcodec/flac.h"
 #include "mov_chan.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
@@ -170,6 +171,46 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t 
size)
 }
 avio_skip(pb, size - ALAC_NEW_KUKI);
 }
+} else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
+int last, type, flac_metadata_size;
+uint8_t buf[4];
+/* The magic cookie format for FLAC consists mostly of an mp4 dfLa 
atom. */
+if (size < (16 + FLAC_STREAMINFO_SIZE)) {
+av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
+return AVERROR_INVALIDDATA;
+}
+/* Check cookie version. */
+if (avio_r8(pb) != 0) {
+av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n");
+return AVERROR_INVALIDDATA;
+}
+avio_rb24(pb); /* Flags */
+/* read dfLa fourcc */
+if (avio_read(pb, buf, 4) != 4) {
+av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n");
+return AVERROR_INVALIDDATA;
+}
+if (memcmp(buf,"dfLa",4)) {
+av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
+return AVERROR_INVALIDDATA;
+}
+/* Check dfLa version. */
+if (avio_r8(pb) != 0) {
+av_log(s, AV_LOG_ERROR, "unknown dfLa version\n");
+return AVERROR_INVALIDDATA;
+}
+avio_rb24(pb); /* Flags */
+avio_read(pb, buf, sizeof(buf));
+flac_parse_block_header(buf, &last, &type, &flac_metadata_size);
+if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != 
FLAC_STREAMINFO_SIZE) {
+av_log(s, AV_LOG_ERROR, "STREAMINFO must be first 
FLACMetadataBlock\n");
+return AVERROR_INVALIDDATA;
+}
+ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE);
+if (ret < 0)
+return ret;
+if (!last)
+av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) 
ignored\n");
 } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
 // The data layout for Opus is currently unknown, so we do not export
 // extradata at all. Multichannel streams are not supported.
-- 
2.30.2

___
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] avformat/cafdec: Implement FLAC-in-CAF parsing

2022-06-03 Thread Paul B Mahol
On Fri, Jun 3, 2022 at 3:12 PM Martijn van Beurden  wrote:

> The afconvert utility shipped with MacOS supports muxing of FLAC
> in CAF, see afconvert help output on a recent Mac here:
> https://hydrogenaud.io/index.php?topic=122509.0 A file created
> with afconvert free of copyright (licensed CC0) can be found here:
> http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf
>
> This patch implements parsing of such a file
> ---
>  libavformat/caf.c|  1 +
>  libavformat/cafdec.c | 41 +
>  2 files changed, 42 insertions(+)
>
> diff --git a/libavformat/caf.c b/libavformat/caf.c
> index a700e4055b..a61c39fae5 100644
> --- a/libavformat/caf.c
> +++ b/libavformat/caf.c
> @@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = {
>  { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') },
>  { AV_CODEC_ID_GSM_MS,  MKTAG('m','s', 0, '1') },
>  { AV_CODEC_ID_ILBC,MKTAG('i','l','b','c') },
> +{ AV_CODEC_ID_FLAC,MKTAG('f','l','a','c') },
>  { AV_CODEC_ID_MACE3,   MKTAG('M','A','C','3') },
>  { AV_CODEC_ID_MACE6,   MKTAG('M','A','C','6') },
>  { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') },
> diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
> index 168f69f20b..72a74ab297 100644
> --- a/libavformat/cafdec.c
> +++ b/libavformat/cafdec.c
> @@ -31,6 +31,7 @@
>  #include "demux.h"
>  #include "internal.h"
>  #include "isom.h"
> +#include "libavcodec/flac.h"
>  #include "mov_chan.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/intfloat.h"
> @@ -170,6 +171,46 @@ static int read_kuki_chunk(AVFormatContext *s,
> int64_t size)
>  }
>  avio_skip(pb, size - ALAC_NEW_KUKI);
>  }
> +} else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
> +int last, type, flac_metadata_size;
> +uint8_t buf[4];
> +/* The magic cookie format for FLAC consists mostly of an mp4
> dfLa atom. */
> +if (size < (16 + FLAC_STREAMINFO_SIZE)) {
> +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +/* Check cookie version. */
> +if (avio_r8(pb) != 0) {
> +av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +avio_rb24(pb); /* Flags */
> +/* read dfLa fourcc */
> +if (avio_read(pb, buf, 4) != 4) {
> +av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +if (memcmp(buf,"dfLa",4)) {
> +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +/* Check dfLa version. */
> +if (avio_r8(pb) != 0) {
> +av_log(s, AV_LOG_ERROR, "unknown dfLa version\n");
> +return AVERROR_INVALIDDATA;
> +}
> +avio_rb24(pb); /* Flags */
> +avio_read(pb, buf, sizeof(buf));
> +flac_parse_block_header(buf, &last, &type, &flac_metadata_size);
> +if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size
> != FLAC_STREAMINFO_SIZE) {
> +av_log(s, AV_LOG_ERROR, "STREAMINFO must be first
> FLACMetadataBlock\n");
> +return AVERROR_INVALIDDATA;
> +}
> +ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE);
> +if (ret < 0)
> +return ret;
> +if (!last)
> +av_log(s, AV_LOG_WARNING, "non-STREAMINFO
> FLACMetadataBlock(s) ignored\n");
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
>  // The data layout for Opus is currently unknown, so we do not
> export
>  // extradata at all. Multichannel streams are not supported.
> --
> 2.30.2
>
>
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".
>
___
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/8] libavcodec/jpeg2000_parser: Speed up long skips

2022-06-03 Thread Michael Niedermayer
On Fri, Jun 03, 2022 at 11:17:54AM +0200, Tomas Härdin wrote:
> tor 2022-06-02 klockan 21:19 +0200 skrev Michael Niedermayer:
> > On Thu, Jun 02, 2022 at 11:54:39AM +0200, Tomas Härdin wrote:
> > > ons 2022-06-01 klockan 18:23 +0200 skrev Michael Niedermayer:
> > > > On Wed, Jun 01, 2022 at 06:21:19PM +0200, Michael Niedermayer
> > > > wrote:
> > > > > On Tue, May 31, 2022 at 11:58:39AM +0200, Tomas Härdin wrote:
> > > > > > 
> > > > > 
> > > > > >  jpeg2000_parser.c |   11 +++
> > > > > >  1 file changed, 11 insertions(+)
> > > > > > 634546fb5a0eb281eea87ad7471c503f5bc9e8ab  0001-libavcodec-
> > > > > > jpeg2000_parser-Speed-up-long-skips.patch
> > > > > > From fedd7f9ae2c691a25c37be935d7547be61d46017 Mon Sep 17
> > > > > > 00:00:00
> > > > > > 2001
> > > > > > From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= 
> > > > > > Date: Fri, 20 May 2022 11:38:25 +0200
> > > > > > Subject: [PATCH 1/8] libavcodec/jpeg2000_parser: Speed up
> > > > > > long
> > > > > > skips
> > > > > > 
> > > > > > ---
> > > > > >  libavcodec/jpeg2000_parser.c | 11 +++
> > > > > >  1 file changed, 11 insertions(+)
> > > > > 
> > > > > breaks
> > > > > j2kref/codestreams_profile1/p1_04.j2k
> > > > 
> > > > [jpeg2000 @ 0x7fb0b8002600] Psot 66195 too big
> > > > [jpeg2000 @ 0x7fb0b8002600] error during processing marker
> > > > segment
> > > > ff90
> > > > Input #0, j2k_pipe, from 'j2kref/codestreams_profile1/p1_04.j2k':
> > > >   Duration: N/A, bitrate: N/A
> > > >   Stream #0:0: Video: jpeg2000 (JPEG 2000 codestream restriction
> > > > 1),
> > > > gray16le(12 bpc), 1024x1024, 25 fps, 25 tbr, 25 tbn
> > > > [jpeg2000 @ 0x7fb0b8003240] unsupported marker 0x97C8 at pos
> > > > 0x6F0
> > > > [jpeg2000 @ 0x7fb0b8003240] Missing EOC Marker.
> > > > [jpeg2000 @ 0x7fb0b8032280] unsupported marker 0x97C8 at pos
> > > > 0x6F0
> > > > [jpeg2000 @ 0x7fb0b8032280] Missing EOC Marker.
> > > > [jpeg2000 @ 0x7fb0b8006280] Psot 66195 too big
> > > > [jpeg2000 @ 0x7fb0b8006280] error during processing marker
> > > > segment
> > > > ff90
> > > 
> > > Took a while to figure out, but this is due to buf_size - i - 9
> > > being
> > > changed to unsigned because of the uint32_t. Try attached patch.
> > > The
> > > rest of the set should work with it.
> > 
> > works fine here
> 
> Great
> 
> > > Can we roll these tests into FATE?
> > 
> > feel free to do so. 
> > ill test if someone posts a patch
> 
> How are you testing them? Just decoding and checking that the output is
> the same as some reference output? 

yes


> Just looking for non-zero exit code?

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Any man who breaks a law that conscience tells him is unjust and willingly 
accepts the penalty by staying in jail in order to arouse the conscience of 
the community on the injustice of the law is at that moment expressing the 
very highest respect for law. - Martin Luther King Jr


signature.asc
Description: PGP signature
___
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] Consulting Request

2022-06-03 Thread Samuel Raposo Vieira Mira
Hi all,

We are Qt (www.qt.io), a global software company with a strong presence in more 
than 70 industries and is the leading independent technology behind 1+ billion 
devices and applications.

Now we are working on integrating the FFmpeg library into our Multimedia module 
as one of the possible backends.
Android is one of our target platforms, and we now face the issue of lacking 
Hardware Acceleration for Encoding for Android.

We are evaluating the possibility of hiring a consulting service to implement 
the Mediacodec Hardware encoder in FFmpeg.
So we would like to know if any developer would be interested in taking on this 
consulting project.

Regards,
Samuel Mira
Senior Software Developer
The Qt Company
Tutkijantie 4C
FI-90590 Oulu
Finland
samuel.m...@qt.io
www.qt.io
[signature_1385223811]
[signature_2378664325]
[signature_2256736393]
[signature_2852832549]
[signature_228390225]

___
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] avcodec: add QOI decoder and demuxer and parser and encoder and muxer

2022-06-03 Thread Andreas Rheinhardt
Paul B Mahol:
> 
> +
> +packet_size = avctx->width * avctx->height * 16LL;
> +if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
> +return ret;
> +

Where does 16 come from? Looking at the code, the factor should be
channels + 1 per pixel (and 14 + 8 byte for header + footer). Or am I
missing something?

- 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] avcodec: add QOI decoder and demuxer and parser and encoder and muxer

2022-06-03 Thread Paul B Mahol
On Fri, Jun 3, 2022 at 6:17 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Paul B Mahol:
> >
> > +
> > +packet_size = avctx->width * avctx->height * 16LL;
> > +if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
> > +return ret;
> > +
>
> Where does 16 come from? Looking at the code, the factor should be
> channels + 1 per pixel (and 14 + 8 byte for header + footer). Or am I
> missing something?
>

Worst case compression.


>
> - 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".
>
___
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] avcodec: add QOI decoder and demuxer and parser and encoder and muxer

2022-06-03 Thread Andreas Rheinhardt
Paul B Mahol:
> On Fri, Jun 3, 2022 at 6:17 PM Andreas Rheinhardt <
> andreas.rheinha...@outlook.com> wrote:
> 
>> Paul B Mahol:
>>>
>>> +
>>> +packet_size = avctx->width * avctx->height * 16LL;
>>> +if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
>>> +return ret;
>>> +
>>
>> Where does 16 come from? Looking at the code, the factor should be
>> channels + 1 per pixel (and 14 + 8 byte for header + footer). Or am I
>> missing something?
>>
> 
> Worst case compression.
> 

Details please. My estimate was actually for the worst case.

- 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] avcodec: add QOI decoder and demuxer and parser and encoder and muxer

2022-06-03 Thread Paul B Mahol
On Fri, Jun 3, 2022 at 6:21 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Paul B Mahol:
> > On Fri, Jun 3, 2022 at 6:17 PM Andreas Rheinhardt <
> > andreas.rheinha...@outlook.com> wrote:
> >
> >> Paul B Mahol:
> >>>
> >>> +
> >>> +packet_size = avctx->width * avctx->height * 16LL;
> >>> +if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
> >>> +return ret;
> >>> +
> >>
> >> Where does 16 come from? Looking at the code, the factor should be
> >> channels + 1 per pixel (and 14 + 8 byte for header + footer). Or am I
> >> missing something?
> >>
> >
> > Worst case compression.
> >
>
> Details please. My estimate was actually for the worst case.
>

Changed to:

packet_size = avctx->width * avctx->height * (channels + 1LL) + 14LL + 8LL;


>
> - 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".
>
___
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] avformat/cafdec: Implement FLAC-in-CAF parsing

2022-06-03 Thread Andreas Rheinhardt
Martijn van Beurden:
> The afconvert utility shipped with MacOS supports muxing of FLAC
> in CAF, see afconvert help output on a recent Mac here:
> https://hydrogenaud.io/index.php?topic=122509.0 A file created
> with afconvert free of copyright (licensed CC0) can be found here:
> http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf
> 
> This patch implements parsing of such a file
> ---
>  libavformat/caf.c|  1 +
>  libavformat/cafdec.c | 41 +
>  2 files changed, 42 insertions(+)
> 
> diff --git a/libavformat/caf.c b/libavformat/caf.c
> index a700e4055b..a61c39fae5 100644
> --- a/libavformat/caf.c
> +++ b/libavformat/caf.c
> @@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = {
>  { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') },
>  { AV_CODEC_ID_GSM_MS,  MKTAG('m','s', 0, '1') },
>  { AV_CODEC_ID_ILBC,MKTAG('i','l','b','c') },
> +{ AV_CODEC_ID_FLAC,MKTAG('f','l','a','c') },
>  { AV_CODEC_ID_MACE3,   MKTAG('M','A','C','3') },
>  { AV_CODEC_ID_MACE6,   MKTAG('M','A','C','6') },
>  { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') },
> diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
> index 168f69f20b..72a74ab297 100644
> --- a/libavformat/cafdec.c
> +++ b/libavformat/cafdec.c
> @@ -31,6 +31,7 @@
>  #include "demux.h"
>  #include "internal.h"
>  #include "isom.h"
> +#include "libavcodec/flac.h"
>  #include "mov_chan.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/intfloat.h"
> @@ -170,6 +171,46 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t 
> size)
>  }
>  avio_skip(pb, size - ALAC_NEW_KUKI);
>  }
> +} else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
> +int last, type, flac_metadata_size;
> +uint8_t buf[4];
> +/* The magic cookie format for FLAC consists mostly of an mp4 dfLa 
> atom. */
> +if (size < (16 + FLAC_STREAMINFO_SIZE)) {
> +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +/* Check cookie version. */
> +if (avio_r8(pb) != 0) {
> +av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +avio_rb24(pb); /* Flags */
> +/* read dfLa fourcc */
> +if (avio_read(pb, buf, 4) != 4) {
> +av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +if (memcmp(buf,"dfLa",4)) {
> +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> +return AVERROR_INVALIDDATA;
> +}
> +/* Check dfLa version. */
> +if (avio_r8(pb) != 0) {
> +av_log(s, AV_LOG_ERROR, "unknown dfLa version\n");
> +return AVERROR_INVALIDDATA;
> +}
> +avio_rb24(pb); /* Flags */
> +avio_read(pb, buf, sizeof(buf));

You are not checking this; this could lead to uninitialized values being
used in flac_parse_block_header() below.

> +flac_parse_block_header(buf, &last, &type, &flac_metadata_size);
> +if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != 
> FLAC_STREAMINFO_SIZE) {
> +av_log(s, AV_LOG_ERROR, "STREAMINFO must be first 
> FLACMetadataBlock\n");
> +return AVERROR_INVALIDDATA;
> +}
> +ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE);
> +if (ret < 0)
> +return ret;
> +if (!last)
> +av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) 
> ignored\n");
>  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
>  // The data layout for Opus is currently unknown, so we do not export
>  // extradata at all. Multichannel streams are not supported.

Is there an official spec for this?

- 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] avformat/cafdec: Implement FLAC-in-CAF parsing

2022-06-03 Thread Jan Ekström
On Fri, Jun 3, 2022 at 8:11 PM Andreas Rheinhardt
 wrote:
>
> Martijn van Beurden:
> > The afconvert utility shipped with MacOS supports muxing of FLAC
> > in CAF, see afconvert help output on a recent Mac here:
> > https://hydrogenaud.io/index.php?topic=122509.0 A file created
> > with afconvert free of copyright (licensed CC0) can be found here:
> > http://www.audiograaf.nl/misc_stuff/afconvert-FLAC-in-CAF.caf
> >
> > This patch implements parsing of such a file
> > ---
> >  libavformat/caf.c|  1 +
> >  libavformat/cafdec.c | 41 +
> >  2 files changed, 42 insertions(+)
> >
> > diff --git a/libavformat/caf.c b/libavformat/caf.c
> > index a700e4055b..a61c39fae5 100644
> > --- a/libavformat/caf.c
> > +++ b/libavformat/caf.c
> > @@ -46,6 +46,7 @@ const AVCodecTag ff_codec_caf_tags[] = {
> >  { AV_CODEC_ID_GSM, MKTAG('a','g','s','m') },
> >  { AV_CODEC_ID_GSM_MS,  MKTAG('m','s', 0, '1') },
> >  { AV_CODEC_ID_ILBC,MKTAG('i','l','b','c') },
> > +{ AV_CODEC_ID_FLAC,MKTAG('f','l','a','c') },
> >  { AV_CODEC_ID_MACE3,   MKTAG('M','A','C','3') },
> >  { AV_CODEC_ID_MACE6,   MKTAG('M','A','C','6') },
> >  { AV_CODEC_ID_MP1, MKTAG('.','m','p','1') },
> > diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
> > index 168f69f20b..72a74ab297 100644
> > --- a/libavformat/cafdec.c
> > +++ b/libavformat/cafdec.c
> > @@ -31,6 +31,7 @@
> >  #include "demux.h"
> >  #include "internal.h"
> >  #include "isom.h"
> > +#include "libavcodec/flac.h"
> >  #include "mov_chan.h"
> >  #include "libavutil/intreadwrite.h"
> >  #include "libavutil/intfloat.h"
> > @@ -170,6 +171,46 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t 
> > size)
> >  }
> >  avio_skip(pb, size - ALAC_NEW_KUKI);
> >  }
> > +} else if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
> > +int last, type, flac_metadata_size;
> > +uint8_t buf[4];
> > +/* The magic cookie format for FLAC consists mostly of an mp4 dfLa 
> > atom. */
> > +if (size < (16 + FLAC_STREAMINFO_SIZE)) {
> > +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +/* Check cookie version. */
> > +if (avio_r8(pb) != 0) {
> > +av_log(s, AV_LOG_ERROR, "unknown FLAC magic cookie\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +avio_rb24(pb); /* Flags */
> > +/* read dfLa fourcc */
> > +if (avio_read(pb, buf, 4) != 4) {
> > +av_log(s, AV_LOG_ERROR, "failed to read FLAC magic cookie\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +if (memcmp(buf,"dfLa",4)) {
> > +av_log(s, AV_LOG_ERROR, "invalid FLAC magic cookie\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +/* Check dfLa version. */
> > +if (avio_r8(pb) != 0) {
> > +av_log(s, AV_LOG_ERROR, "unknown dfLa version\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +avio_rb24(pb); /* Flags */
> > +avio_read(pb, buf, sizeof(buf));
>
> You are not checking this; this could lead to uninitialized values being
> used in flac_parse_block_header() below.
>
> > +flac_parse_block_header(buf, &last, &type, &flac_metadata_size);
> > +if (type != FLAC_METADATA_TYPE_STREAMINFO || flac_metadata_size != 
> > FLAC_STREAMINFO_SIZE) {
> > +av_log(s, AV_LOG_ERROR, "STREAMINFO must be first 
> > FLACMetadataBlock\n");
> > +return AVERROR_INVALIDDATA;
> > +}
> > +ret = ff_get_extradata(s, st->codecpar, pb, FLAC_STREAMINFO_SIZE);
> > +if (ret < 0)
> > +return ret;
> > +if (!last)
> > +av_log(s, AV_LOG_WARNING, "non-STREAMINFO FLACMetadataBlock(s) 
> > ignored\n");
> >  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
> >  // The data layout for Opus is currently unknown, so we do not 
> > export
> >  // extradata at all. Multichannel streams are not supported.
>
> Is there an official spec for this?

CAF mostly follows ISOBMFF in these things, so
https://github.com/xiph/flac/blob/master/doc/isoflac.txt is probably
the source of truth for dfLa FLACSpecificBox and such.

Base CAF specification is at
https://developer.apple.com/library/archive/documentation/MusicAudio/Reference/CAFSpec/CAF_spec/CAF_spec.html
, but it stops at AAC, and ignores both Opus and FLAC.

Jan
___
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] avformat/cafdec: Implement FLAC-in-CAF parsing

2022-06-03 Thread Martijn van Beurden
Op vr 3 jun. 2022 om 19:11 schreef Andreas Rheinhardt
:
>
> You are not checking this; this could lead to uninitialized values being
> used in flac_parse_block_header() below.
>

Yes, indeed, thank you. Interestingly enough, I copied this bit
directly from mov_read_dfla in mov.c, so I'll send a patch for that as
well.

>
> Is there an official spec for this?
>

Not that I know of, but as I was looking at the file the with a hex
editor dfLa stood out as recognizable, as the MP4 spec uses it as well
(as Jan already commented). Therefore I copied most of the code from
mov_read_dfla, with some additions/changes as it is used in a
different context here of course.
___
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".