[FFmpeg-devel] [PATCH] ffmpeg: pass encoder init AVFrame side data to output AVStream

2023-03-05 Thread Jan Ekström
This enables passing through various side data during encoding,
which is not yet in AVCodecContext/AVCodecParameters, but is read
from AVStream side data in muxers.

Additionally, add a FATE test that demonstrates PNG->J2K MP4
transcoding with the ICC profile getting passed through.
---
 fftools/ffmpeg.c |  6 ++
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_mux.c | 47 +
 tests/fate/ffmpeg.mak|  4 ++
 tests/ref/fate/ffmpeg-side-data-to-avstreams | 72 
 5 files changed, 130 insertions(+)
 create mode 100644 tests/ref/fate/ffmpeg-side-data-to-avstreams

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d721a5e721..134258b825 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -3113,6 +3113,12 @@ static int init_output_stream_encode(OutputStream *ost, 
AVFrame *frame)
  
av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
 
 if (frame) {
+if (!(ost->side_data_frame = av_frame_alloc()))
+return AVERROR(ENOMEM);
+
+if ((ret = av_frame_copy_props(ost->side_data_frame, frame)) < 0)
+return ret;
+
 enc_ctx->color_range= frame->color_range;
 enc_ctx->color_primaries= frame->color_primaries;
 enc_ctx->color_trc  = frame->color_trc;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 4d4433f5ba..21dd0f3a9e 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -593,6 +593,7 @@ typedef struct OutputStream {
 AVFrame *filtered_frame;
 AVFrame *last_frame;
 AVFrame *sq_frame;
+AVFrame *side_data_frame;
 AVPacket *pkt;
 int64_t last_dropped;
 int64_t last_nb0_frames[3];
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index cf58051949..13da9ab8da 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -580,6 +580,49 @@ static int bsf_init(MuxStream *ms)
 return 0;
 }
 
+static int avframe_side_data_to_avstream(AVStream *stream, const AVFrame 
*frame)
+{
+static const struct sd_mapping {
+enum AVPacketSideDataType packet;
+enum AVFrameSideDataType frame;
+} sd_list[] = {
+{ AV_PKT_DATA_REPLAYGAIN ,AV_FRAME_DATA_REPLAYGAIN },
+{ AV_PKT_DATA_DISPLAYMATRIX,  AV_FRAME_DATA_DISPLAYMATRIX 
},
+{ AV_PKT_DATA_SPHERICAL,  AV_FRAME_DATA_SPHERICAL },
+{ AV_PKT_DATA_STEREO3D,   AV_FRAME_DATA_STEREO3D },
+{ AV_PKT_DATA_AUDIO_SERVICE_TYPE, 
AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
+{ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
+{ AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
+{ AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
+{ AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
+{ AV_PKT_DATA_S12M_TIMECODE,  AV_FRAME_DATA_S12M_TIMECODE 
},
+{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
+};
+
+if (!frame || !frame->nb_side_data)
+return 0;
+
+if (!stream)
+return AVERROR(EINVAL);
+
+for (int i = 0; i < FF_ARRAY_ELEMS(sd_list); i++) {
+const struct sd_mapping mapping = sd_list[i];
+uint8_t *packet_sd  = NULL;
+AVFrameSideData *sd = av_frame_get_side_data(frame, mapping.frame);
+if (!sd)
+continue;
+
+packet_sd = av_stream_new_side_data(stream, mapping.packet,
+sd->size);
+if (!packet_sd)
+return AVERROR(ENOMEM);
+
+memcpy(packet_sd, sd->data, sd->size);
+}
+
+return 0;
+}
+
 int of_stream_init(OutputFile *of, OutputStream *ost)
 {
 Muxer *mux = mux_from_of(of);
@@ -589,6 +632,9 @@ int of_stream_init(OutputFile *of, OutputStream *ost)
 if (ost->sq_idx_mux >= 0)
 sq_set_tb(mux->sq_mux, ost->sq_idx_mux, ost->mux_timebase);
 
+if ((ret = avframe_side_data_to_avstream(ost->st, ost->side_data_frame)) < 
0)
+return ret;
+
 /* initialize bitstream filters for the output stream
  * needs to be done here, because the codec id for streamcopy is not
  * known until now */
@@ -666,6 +712,7 @@ static void ost_free(OutputStream **post)
 av_frame_free(&ost->filtered_frame);
 av_frame_free(&ost->sq_frame);
 av_frame_free(&ost->last_frame);
+av_frame_free(&ost->side_data_frame);
 av_packet_free(&ost->pkt);
 av_dict_free(&ost->encoder_opts);
 
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index 0f33c2a0ed..3d6ef2a8fb 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -224,3 +224,7 @@ FATE_TIME_BASE-$(call PARSERDEMDEC, MPEGVIDEO, MPEGPS, 
MPEG2VIDEO, MPEGVIDEO_DEM
 fate-time_base: CMD = md5 -i $(TARGET_SAMPLES)/mpeg2/dv

Re: [FFmpeg-devel] [PATCH] lavfi/buffersrc: issue more specific error in case of invalid parameters

2023-03-05 Thread Stefano Sabatini
On date Wednesday 2023-03-01 15:33:51 +0100, Anton Khirnov wrote:
> Quoting Stefano Sabatini (2023-03-01 01:05:29)
[...]
> > BTW, I noticied this as part of debugging transcode.c (which looks
> > broken at the moment), since the timebase is read as 0/1 from the
> > decoder context, it would be a valid value when reading from the
> > AVStream (but this information is not copied by
> > avcodec_parameters_to_context). In decode_filter_video.c this is
> > indeed "fixed" by copying the timebase directly from the AVStream.
> > 
> > Is this expected? Shouldn't the timebase be copied to the decoder
> > context?
> 
> Historically, AVCodecContext.time_base for decoding was NOT (as one
> might expect) the timebase of input packets, set by the user. It was
> instead the inverse of the framerate stored in codec-level headers,
> which was called "codec timebase" by some documents.
> 
> Since that was massively confusing for pretty much everyone, I added
> AVCodecContext.framerate for exporting the framerate from the decoder,
> and deprecated the use of AVCodecContext.time_base for decoding
> entirely. After the recent major bump, time_base should not be used at
> all in any way when decoding.
> 
> The timebase of input packets should instead be stored in
> AVCodecContext.pkt_timebase. I suppose after some time has passed we
> might want to merge its functionality into time_base.

Makes sense, for the time being I understand the correct solution is to
use pkt_timebase. Thank you.
___
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] avcodec/rka: use 64bit for srate_pad computation

2023-03-05 Thread Michael Niedermayer
Fixes: left shift of 538976288 by 13 places cannot be represented in type 'int'
Fixes: 
56148/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-6257370708967424

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/rka.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/rka.c b/libavcodec/rka.c
index 2212e3f930..1e6a48568d 100644
--- a/libavcodec/rka.c
+++ b/libavcodec/rka.c
@@ -207,7 +207,7 @@ static int chctx_init(RKAContext *s, ChContext *c,
 c->bprob[0] = s->bprob[0];
 c->bprob[1] = s->bprob[1];
 
-c->srate_pad = (sample_rate << 13) / 44100 & 0xFFFCU;
+c->srate_pad = ((int64_t)sample_rate << 13) / 44100 & 0xFFFCU;
 c->pos_idx = 1;
 
 for (int i = 0; i < FF_ARRAY_ELEMS(s->bprob[0]); i++)
-- 
2.17.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/2] avformat/wavdec: Check that smv block fits in available space

2023-03-05 Thread Michael Niedermayer
Fixes: OOM
Fixes: 
56271/clusterfuzz-testcase-minimized-ffmpeg_dem_WAV_fuzzer-5290810045497344

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavformat/wavdec.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index e3f790fcc9..97e69ab2ee 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -730,6 +730,10 @@ smv_retry:
 goto smv_out;
 }
 size = avio_rl24(s->pb);
+if (size > wav->smv_block_size) {
+ret = AVERROR_EOF;
+goto smv_out;
+}
 ret  = av_get_packet(s->pb, pkt, size);
 if (ret < 0)
 goto smv_out;
-- 
2.17.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".


Re: [FFmpeg-devel] [PATCH] lavc/avcodec.h: extend documentation for avcodec_open2()

2023-03-05 Thread Stefano Sabatini
On date Wednesday 2023-03-01 15:04:16 +0800, "zhilizhao(赵志立)" wrote:
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index 9a0fe97cad..fbf1d3d83c 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -2418,8 +2418,14 @@ int avcodec_parameters_to_context(AVCodecContext 
> > *codec,
> >   * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way 
> > for
> >   * retrieving a codec.
> >   *
> > - * @note Always call this function before using decoding routines (such as
> > - * @ref avcodec_receive_frame()).
> > + * Depending on the codec, you might need to set options in the codec 
> > context
> > + * also for decoding (e.g. width, height, or the pixel or audio sample 
> > format in
> > + * case the information is not is not available in the bitstream, e.g. as 
> > in
> 
> 'is not is not'
> 
> > + * case of decoding raw audio or video).
> 
> in ’the’ case of.
> 
> > + *
> > + * Options on the codec context can be either set by providing the options
> > + * specified in an AVDictionary, or by setting the values on the context 
> > itself,
> > + * directly or by using the av_opt_set() API.
> >   *
> >   * @code
> >   * av_dict_set(&opts, "b", "2.5M", 0);
> > @@ -2433,17 +2439,35 @@ int avcodec_parameters_to_context(AVCodecContext 
> > *codec,
> >   * exit(1);
> >   * @endcode
> >   *
> > + * In case AVCodecParameters are available (e.g. when demuxing a stream 
> > using
> > + * libavformat, and accessing the AVStream contained in the demuxer), the 
> > codec
> > + * parameters can be copied to the codec context using
> > + * avcodec_parameters_to_context(), as in the following code:
> > + *
> > + * @code
> > + * context = avcodec_alloc_context3(codec);
> > + * if (avcodec_parameters_to_context(*dec_ctx, codecpar) < 0)
> > + * exit(1);
> > + * if (avcodec_open2(context, codec, NULL) < 0)
> > + * exit(1);
> 
> What’s the dec_ctx?

Updated, thanks for the feedback.
>From 672de0e5d15ab8a22f3957222680d847f60bced8 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Tue, 28 Feb 2023 23:26:43 +0100
Subject: [PATCH 1/2] lavc/avcodec.h: extend documentation for avcodec_open2()

In particular, clarify how to set options in the codec context, and
mention when to use avcodec_parameters_to_context().

Fix trac issues:
http://trac.ffmpeg.org/ticket/5781
http://trac.ffmpeg.org/ticket/5838
---
 libavcodec/avcodec.h | 36 +++-
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 87ebee22b1..f630fafe24 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2429,8 +2429,15 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
  * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for
  * retrieving a codec.
  *
- * @note Always call this function before using decoding routines (such as
- * @ref avcodec_receive_frame()).
+ * Depending on the codec, you might need to set options in the codec context
+ * also for decoding (e.g. width, height, or the pixel or audio sample format in
+ * the case the information is not available in the bitstream, as when decoding
+ * raw audio or video).
+ *
+ * Options on the codec context can be set either by setting them in the
+ * provided options AVDictionary, or by setting the values on the context
+ * itself, directly or by using the av_opt_set() API before calling the
+ * function.
  *
  * @code
  * av_dict_set(&opts, "b", "2.5M", 0);
@@ -2444,17 +2451,36 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
  * exit(1);
  * @endcode
  *
+ * In case AVCodecParameters are available (e.g. when demuxing a stream using
+ * libavformat, and accessing the AVStream contained in the demuxer), the codec
+ * parameters can be copied to the codec context using
+ * avcodec_parameters_to_context(), as in the following code:
+ *
+ * @code
+ * AVStream *stream = ...;
+ * context = avcodec_alloc_context3(codec);
+ * if (avcodec_parameters_to_context(context, stream->codecpar) < 0)
+ * exit(1);
+ * if (avcodec_open2(context, codec, NULL) < 0)
+ * exit(1);
+ * @endcode
+ *
+ * @note Always call this function before using decoding routines (such as
+ * @ref avcodec_receive_frame()).
+ *
  * @param avctx The context to initialize.
  * @param codec The codec to open this context for. If a non-NULL codec has been
  *  previously passed to avcodec_alloc_context3() or
  *  for this context, then this parameter MUST be either NULL or
  *  equal to the previously passed codec.
- * @param options A dictionary filled with AVCodecContext and codec-private options.
- *On return this object will be filled with options that were not found.
+ * @param options A dictionary filled with AVCodecContext and codec-private
+ *options, which are set on top of the options already set in
+ *avctx, can be NULL. On return this object will be filled

Re: [FFmpeg-devel] [PATCH] tests: actually test yadif's 10 and 16-bit functions

2023-03-05 Thread James Darnley

On 2/20/23 14:06, James Darnley wrote:

On 2/20/23 13:49, Nicolas George wrote:

James Darnley (12023-02-20):


snip


Moving scale before yadif is right, but format= is redundant with
-pix_fmt.

Regards,



So the patch should just be moving the scale filter first?  Sure.  Any 
other comments?  I wait a short while then make that change and push.


I forgot about this.  Now that the repo seems to be working again after 
the HW failure I will push on Monday.

___
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] trac optimization

2023-03-05 Thread Michael Niedermayer
Hi

due to continuing performance issues (and complaints) about trac speed
ive switched the database to WAL mode. This should make th db signifciantly
faster but iam not sure the database was the limiting factor.
Now reading and writing can proceed concurrently, before writes would block
everything.
One might think "but there wasnt that much changed/writen" this is logic but
not true. The database stores every recent spammer access and everything that
could be a spammer, every session cookie (we have 129379 temporary sessions in
teh ffmpeg trac databse for example). This is bad design arguably of course 

If you notice any new issue, please report it here.
Ive made a backup from trac before this and we have daily trac backups
if this causes a major issue i intend to rollback to a previous backup and
disable it again. But i expect no major issue, its likely either faster or not.

thx

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
conveniently.
New school: Use the highest level language in which the latest supercomputer
can solve the problem without the user falling asleep waiting.


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] [PATCH v4] avformat: Add support for embedding cover art in Ogg files

2023-03-05 Thread Zsolt Vadász
This version can actually be applied to master. Also added checks to
ensure there won't be an OGGStreamContext for the cover art to suppress
warnings in mpv.

Signed-off-by: Zsolt Vadasz 
---
 libavformat/flac_picture.c | 132 ++
 libavformat/flac_picture.h |   5 +
 libavformat/flacenc.c  |  90 +--
 libavformat/oggenc.c   | 217 ++---
 4 files changed, 319 insertions(+), 125 deletions(-)

diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index b33fee75b4..30152a2ba9 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -20,6 +20,9 @@
  */

 #include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/base64.h"
+#include "libavutil/pixdesc.h"
 #include "libavcodec/bytestream.h"
 #include "libavcodec/png.h"
 #include "avformat.h"
@@ -188,3 +191,132 @@ fail:

 return ret;
 }
+
+int ff_flac_write_picture(struct AVFormatContext *s,
+  int isogg,
+  unsigned *attached_types,
+  int audio_stream_idx, // unused if !isogg
+  AVPacket *pkt)
+{
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0, blocklen;
+
+if (!pkt->data)
+return 0;
+
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
+return AVERROR(EINVAL);
+}
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if (((*attached_types) & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
+return AVERROR(EINVAL);
+}
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
+return AVERROR(EINVAL);
+}
+
+*attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+blocklen = 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + pkt->size;
+if (blocklen >= 1<<24) {
+av_log(s, AV_LOG_ERROR, "Picture block too big %d >= %d\n", blocklen, 
1<<24);
+return AVERROR(EINVAL);
+}
+
+if(!isogg) {
+avio_w8(pb, 0x06);
+avio_wb24(pb, blocklen);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+} else {
+uint8_t *metadata_block_picture, *ptr;
+int encoded_len, ret;
+char *encoded;
+AVStream *audio_stream = s->streams[audio_stream_idx];
+
+metadata_block_picture = av_mallocz(blocklen);
+ptr = metadata_block_picture;
+bytestream_put_be32(&ptr, type);
+
+bytestream_put_be32(&ptr, mimelen);
+bytestream_put_buffer(&ptr, mimetype, mimelen);
+
+bytestream_put_be32(&ptr, desclen);
+bytestream_put_buffer(&ptr, desc, desclen);
+
+bytestream_put_be32(&ptr, st->codecpar->width);
+bytestream_put_be32(&ptr, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+bytestream_put_be32(&ptr, av_get_bits_per_pixel(pixdesc));
+else
+bytestream_put_be32(&ptr, 0);
+bytestream_put_be32(&ptr, 0);
+
+bytestream_put_be32(&ptr, pkt->size);
+bytestream_put_buffer(&ptr, pkt->data, pkt->size);
+
+encoded_len = AV_BASE64_SIZE(blocklen);
+encoded = av_mallocz(encoded_len);
+av_base64_encode(encoded, encoded_len, metadata_block_picture, 
blocklen);
+av_free(metadata_bl

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/rka: use 64bit for srate_pad computation

2023-03-05 Thread Paul B Mahol
On 3/5/23, Michael Niedermayer  wrote:
> Fixes: left shift of 538976288 by 13 places cannot be represented in type
> 'int'
> Fixes:
> 56148/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-6257370708967424
>

Please make sure that this does not break decoding.

> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/rka.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/rka.c b/libavcodec/rka.c
> index 2212e3f930..1e6a48568d 100644
> --- a/libavcodec/rka.c
> +++ b/libavcodec/rka.c
> @@ -207,7 +207,7 @@ static int chctx_init(RKAContext *s, ChContext *c,
>  c->bprob[0] = s->bprob[0];
>  c->bprob[1] = s->bprob[1];
>
> -c->srate_pad = (sample_rate << 13) / 44100 & 0xFFFCU;
> +c->srate_pad = ((int64_t)sample_rate << 13) / 44100 & 0xFFFCU;
>  c->pos_idx = 1;
>
>  for (int i = 0; i < FF_ARRAY_ELEMS(s->bprob[0]); i++)
> --
> 2.17.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 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] ffmpeg: pass encoder init AVFrame side data to output AVStream

2023-03-05 Thread Jan Ekström
On Sun, Mar 5, 2023 at 1:17 PM Jan Ekström  wrote:
>
> This enables passing through various side data during encoding,
> which is not yet in AVCodecContext/AVCodecParameters, but is read
> from AVStream side data in muxers.
>
> Additionally, add a FATE test that demonstrates PNG->J2K MP4
> transcoding with the ICC profile getting passed through.
> ---

Just tested locally and going PNG->MP4 (RGB H.264)->PNG actually does
work with ffmpeg.c now with regards to ICC side data :) So something
like this does actually help with round-tripping (most likely since
the side data goes from the AVStream to the first AVPacket and thus
into the first AVFrame, which then gets picked up by pngenc),

Currently this is only limited to video, as audio cannot work with the
avfilter peek API, as the peeked frame gets buffered, and thus any
further adjustment of audio frame size will fail, as the buffered
frame gets output first (with whatever the original requested size
was).

>  fftools/ffmpeg.c |  6 ++
>  fftools/ffmpeg.h |  1 +
>  fftools/ffmpeg_mux.c | 47 +
>  tests/fate/ffmpeg.mak|  4 ++
>  tests/ref/fate/ffmpeg-side-data-to-avstreams | 72 
>  5 files changed, 130 insertions(+)
>  create mode 100644 tests/ref/fate/ffmpeg-side-data-to-avstreams
>
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index d721a5e721..134258b825 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -3113,6 +3113,12 @@ static int init_output_stream_encode(OutputStream 
> *ost, AVFrame *frame)
>   
> av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
>
>  if (frame) {
> +if (!(ost->side_data_frame = av_frame_alloc()))
> +return AVERROR(ENOMEM);
> +
> +if ((ret = av_frame_copy_props(ost->side_data_frame, frame)) < 0)
> +return ret;
> +
>  enc_ctx->color_range= frame->color_range;
>  enc_ctx->color_primaries= frame->color_primaries;
>  enc_ctx->color_trc  = frame->color_trc;
> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
> index 4d4433f5ba..21dd0f3a9e 100644
> --- a/fftools/ffmpeg.h
> +++ b/fftools/ffmpeg.h
> @@ -593,6 +593,7 @@ typedef struct OutputStream {
>  AVFrame *filtered_frame;
>  AVFrame *last_frame;
>  AVFrame *sq_frame;
> +AVFrame *side_data_frame;
>  AVPacket *pkt;
>  int64_t last_dropped;
>  int64_t last_nb0_frames[3];
> diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
> index cf58051949..13da9ab8da 100644
> --- a/fftools/ffmpeg_mux.c
> +++ b/fftools/ffmpeg_mux.c
> @@ -580,6 +580,49 @@ static int bsf_init(MuxStream *ms)
>  return 0;
>  }
>
> +static int avframe_side_data_to_avstream(AVStream *stream, const AVFrame 
> *frame)
> +{
> +static const struct sd_mapping {
> +enum AVPacketSideDataType packet;
> +enum AVFrameSideDataType frame;
> +} sd_list[] = {
> +{ AV_PKT_DATA_REPLAYGAIN ,AV_FRAME_DATA_REPLAYGAIN },
> +{ AV_PKT_DATA_DISPLAYMATRIX,  
> AV_FRAME_DATA_DISPLAYMATRIX },
> +{ AV_PKT_DATA_SPHERICAL,  AV_FRAME_DATA_SPHERICAL },
> +{ AV_PKT_DATA_STEREO3D,   AV_FRAME_DATA_STEREO3D },
> +{ AV_PKT_DATA_AUDIO_SERVICE_TYPE, 
> AV_FRAME_DATA_AUDIO_SERVICE_TYPE },
> +{ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
> AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
> +{ AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
> AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
> +{ AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
> +{ AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE 
> },
> +{ AV_PKT_DATA_S12M_TIMECODE,  
> AV_FRAME_DATA_S12M_TIMECODE },
> +{ AV_PKT_DATA_DYNAMIC_HDR10_PLUS, 
> AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
> +};

For the record, this listing was taken from
ff_decode_frame_props_from_pkt, and probably at the end of the day
should be in a "get one from the other" or "iterate me all the
mappings" sort of API in avcodec.

Then this function adding stuff to AVStream could be in avformat
without the list being duplicated.

This thing is here in this patch mostly to prove that this kind of
passing through additional side data would help.

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 1/2] avcodec/rka: use 64bit for srate_pad computation

2023-03-05 Thread Michael Niedermayer
On Sun, Mar 05, 2023 at 05:37:09PM +0100, Paul B Mahol wrote:
> On 3/5/23, Michael Niedermayer  wrote:
> > Fixes: left shift of 538976288 by 13 places cannot be represented in type
> > 'int'
> > Fixes:
> > 56148/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_RKA_fuzzer-6257370708967424
> >
> 
> Please make sure that this does not break decoding.

how ?

* Testing all rka files on the internet ? 
i cannot

* Reading the specification ?
i failed to find a public specification

* Generating files that have a high enough sample rate with the binary windows
  encoder?
"ERROR: Unsupported format type." even at 88.2k, well below that point

Also if it worked before its dependant on the compiler, its undefined
bahevior.
For files with more normal sample rates like the sample in our archieve
it produces the same output.

Other ideas ?

thx

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

It is what and why we do it that matters, not just one of them.


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


Re: [FFmpeg-devel] Subject: [PATCH v4] avformat: Add support for embedding cover art in Ogg files

2023-03-05 Thread Marton Balint



On Sat, 4 Mar 2023, Zsolt Vadász wrote:


Signed-off-by: Zsolt Vadasz 
---
libavformat/flac_picture.c | 132 ++
libavformat/flac_picture.h |   5 +
libavformat/flacenc.c  |  90 +--
libavformat/oggenc.c   | 217 ++---
4 files changed, 319 insertions(+), 125 deletions(-)


Can you split this into two patches? One factorizes flac_write_picture, 
but contains no change in functionality, the other adds the actual support 
to ogg.


Thanks,
Marton



diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c
index b33fee75b4..30152a2ba9 100644
--- a/libavformat/flac_picture.c
+++ b/libavformat/flac_picture.c
@@ -20,6 +20,9 @@
 */

#include "libavutil/intreadwrite.h"
+#include "libavutil/avstring.h"
+#include "libavutil/base64.h"
+#include "libavutil/pixdesc.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/png.h"
#include "avformat.h"
@@ -188,3 +191,132 @@ fail:

return ret;
}
+
+int ff_flac_write_picture(struct AVFormatContext *s,
+  int isogg,
+  unsigned *attached_types,
+  int audio_stream_idx, // unused if !isogg
+  AVPacket *pkt)
+{
+AVIOContext *pb = s->pb;
+const AVPixFmtDescriptor *pixdesc;
+const CodecMime *mime = ff_id3v2_mime_tags;
+AVDictionaryEntry *e;
+const char *mimetype = NULL, *desc = "";
+const AVStream *st = s->streams[pkt->stream_index];
+int i, mimelen, desclen, type = 0, blocklen;
+
+if (!pkt->data)
+return 0;
+
+while (mime->id != AV_CODEC_ID_NONE) {
+if (mime->id == st->codecpar->codec_id) {
+mimetype = mime->str;
+break;
+}
+mime++;
+}
+if (!mimetype) {
+av_log(s, AV_LOG_ERROR, "No mimetype is known for stream %d, cannot "
+   "write an attached picture.\n", st->index);
+return AVERROR(EINVAL);
+}
+mimelen = strlen(mimetype);
+
+/* get the picture type */
+e = av_dict_get(st->metadata, "comment", NULL, 0);
+for (i = 0; e && i < FF_ARRAY_ELEMS(ff_id3v2_picture_types); i++) {
+if (!av_strcasecmp(e->value, ff_id3v2_picture_types[i])) {
+type = i;
+break;
+}
+}
+
+if (((*attached_types) & (1 << type)) & 0x6) {
+av_log(s, AV_LOG_ERROR, "Duplicate attachment for type '%s'\n", 
ff_id3v2_picture_types[type]);
+return AVERROR(EINVAL);
+}
+
+if (type == 1 && (st->codecpar->codec_id != AV_CODEC_ID_PNG ||
+  st->codecpar->width != 32 ||
+  st->codecpar->height != 32)) {
+av_log(s, AV_LOG_ERROR, "File icon attachment must be a 32x32 PNG");
+return AVERROR(EINVAL);
+}
+
+*attached_types |= (1 << type);
+
+/* get the description */
+if ((e = av_dict_get(st->metadata, "title", NULL, 0)))
+desc = e->value;
+desclen = strlen(desc);
+
+blocklen = 4 + 4 + mimelen + 4 + desclen + 4 + 4 + 4 + 4 + 4 + pkt->size;
+if (blocklen >= 1<<24) {
+av_log(s, AV_LOG_ERROR, "Picture block too big %d >= %d\n", blocklen, 
1<<24);
+return AVERROR(EINVAL);
+}
+
+if(!isogg) {
+avio_w8(pb, 0x06);
+avio_wb24(pb, blocklen);
+
+avio_wb32(pb, type);
+
+avio_wb32(pb, mimelen);
+avio_write(pb, mimetype, mimelen);
+
+avio_wb32(pb, desclen);
+avio_write(pb, desc, desclen);
+
+avio_wb32(pb, st->codecpar->width);
+avio_wb32(pb, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+avio_wb32(pb, av_get_bits_per_pixel(pixdesc));
+else
+avio_wb32(pb, 0);
+avio_wb32(pb, 0);
+
+avio_wb32(pb, pkt->size);
+avio_write(pb, pkt->data, pkt->size);
+} else {
+uint8_t *metadata_block_picture, *ptr;
+int encoded_len, ret;
+char *encoded;
+AVStream *audio_stream = s->streams[audio_stream_idx];
+
+metadata_block_picture = av_mallocz(blocklen);
+ptr = metadata_block_picture;
+bytestream_put_be32(&ptr, type);
+
+bytestream_put_be32(&ptr, mimelen);
+bytestream_put_buffer(&ptr, mimetype, mimelen);
+
+bytestream_put_be32(&ptr, desclen);
+bytestream_put_buffer(&ptr, desc, desclen);
+
+bytestream_put_be32(&ptr, st->codecpar->width);
+bytestream_put_be32(&ptr, st->codecpar->height);
+if ((pixdesc = av_pix_fmt_desc_get(st->codecpar->format)))
+bytestream_put_be32(&ptr, av_get_bits_per_pixel(pixdesc));
+else
+bytestream_put_be32(&ptr, 0);
+bytestream_put_be32(&ptr, 0);
+
+bytestream_put_be32(&ptr, pkt->size);
+bytestream_put_buffer(&ptr, pkt->data, pkt->size);
+
+encoded_len = AV_BASE64_SIZE(blocklen);
+encoded = av_mallocz(encoded_len);
+av_base64_encode(encoded, encoded_len, metadata_blo

Re: [FFmpeg-devel] [PATCH v4] avformat: Add support for embedding cover art in Ogg files

2023-03-05 Thread Michael Niedermayer
On Sun, Mar 05, 2023 at 03:59:41PM +, Zsolt Vadász wrote:
> This version can actually be applied to master. Also added checks to
> ensure there won't be an OGGStreamContext for the cover art to suppress
> warnings in mpv.
> 
> Signed-off-by: Zsolt Vadasz 
> ---
>  libavformat/flac_picture.c | 132 ++
>  libavformat/flac_picture.h |   5 +
>  libavformat/flacenc.c  |  90 +--
>  libavformat/oggenc.c   | 217 ++---
>  4 files changed, 319 insertions(+), 125 deletions(-)

breaks fate

--- ./tests/ref/lavf-fate/vp8.ogg   2023-02-25 23:39:59.312106371 +0100
+++ tests/data/fate/lavf-fate-vp8.ogg   2023-03-05 20:25:46.872310586 +0100
@@ -1,3 +1,3 @@
-20f1e9b1714513a0ba85ca636e818784 *tests/data/lavf-fate/lavf.vp8.ogg
-95009 tests/data/lavf-fate/lavf.vp8.ogg
-tests/data/lavf-fate/lavf.vp8.ogg CRC=0xa5857a66
+b6755b4eb67bac91a775e0fcc8323e49 *tests/data/lavf-fate/lavf.vp8.ogg
+76738 tests/data/lavf-fate/lavf.vp8.ogg
+tests/data/lavf-fate/lavf.vp8.ogg CRC=0xe090528e
TESTcheckasm-fmtconvert
Test lavf-fate-vp8.ogg failed. Look at tests/data/fate/lavf-fate-vp8.ogg.err 
for details.
tests/Makefile:306: recipe for target 'fate-lavf-fate-vp8.ogg' failed
make: *** [fate-lavf-fate-vp8.ogg] Error 1
make: *** Waiting for unfinished jobs


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

No snowflake in an avalanche ever feels responsible. -- Voltaire


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] [PATCH] vulkan: Fix win/i386 calling convention and pointer/int conversion error

2023-03-05 Thread Martin Storsjö
This fixes the following two errors when compiling with a modern
version of Clang for Windows/i386:

src/libavutil/hwcontext_vulkan.c:738:32: error: incompatible function pointer 
types initializing 'PFN_vkDebugUtilsMessengerCallbackEXT' (aka 'unsigned int 
(*)(enum VkDebugUtilsMessageSeverityFlagBitsEXT, unsigned int, const struct 
VkDebugUtilsMessengerCallbackDataEXT *, void *) __attribute__((stdcall))') with 
an expression of type 'VkBool32 (VkDebugUtilsMessageSeverityFlagBitsEXT, 
VkDebugUtilsMessageTypeFlagsEXT, const VkDebugUtilsMessengerCallbackDataEXT *, 
void *)' (aka 'unsigned int (enum VkDebugUtilsMessageSeverityFlagBitsEXT, 
unsigned int, const struct VkDebugUtilsMessengerCallbackDataEXT *, void *)') 
[-Wincompatible-function-pointer-types]
.pfnUserCallback = vk_dbg_callback,
   ^~~
src/libavutil/hwcontext_vulkan.c:1152:15: error: incompatible pointer to 
integer conversion assigning to 'VkCommandPool' (aka 'unsigned long long') from 
'void *' [-Wint-conversion]
cmd->pool = NULL;
  ^ 
2 errors generated.

The calling convention mismatch is an issue only on Windows/i386,
while the latter is a hard error by default in modern Clang whenever
pointers are smaller than unsigned long long.

Signed-off-by: Martin Storsjö 
---
 libavutil/hwcontext_vulkan.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 2a9b5f4aac..2ae469283d 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -401,10 +401,10 @@ static const char *vk_ret2str(VkResult res)
 #undef CASE
 }
 
-static VkBool32 vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEXT 
severity,
-VkDebugUtilsMessageTypeFlagsEXT messageType,
-const VkDebugUtilsMessengerCallbackDataEXT 
*data,
-void *priv)
+static VkBool32 VKAPI_CALL 
vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
+   VkDebugUtilsMessageTypeFlagsEXT 
messageType,
+   const 
VkDebugUtilsMessengerCallbackDataEXT *data,
+   void *priv)
 {
 int l;
 AVHWDeviceContext *ctx = priv;
@@ -1149,7 +1149,7 @@ static void free_exec_ctx(AVHWFramesContext *hwfc, 
VulkanExecCtx *cmd)
 
 av_freep(&cmd->queues);
 av_freep(&cmd->bufs);
-cmd->pool = NULL;
+cmd->pool = 0;
 }
 
 static VkCommandBuffer get_buf_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx 
*cmd)
-- 
2.34.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".


Re: [FFmpeg-devel] [PATCH v2 2/8] avformat/mov: check that pcmC box is of the expected type

2023-03-05 Thread Jan Ekström
On Mon, Feb 27, 2023 at 6:26 PM Jan Ekström  wrote:
>
> On Mon, Feb 27, 2023 at 3:36 PM Tomas Härdin  wrote:
> >
> > lör 2023-02-25 klockan 02:28 +0800 skrev Zhao Zhili:
> > > From: Jan Ekström 
> > >
> > > As per 23003-5:2020 this box is defined as
> > > PCMConfig extends FullBox(‘pcmC’, version = 0, 0), which means
> > > that version is 0 and flags should be zero.
> > > ---
> > >  libavformat/mov.c | 13 +++--
> > >  1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > Probably OK, but I'm not versed i the version problems relating to this
> > tag. Should we also support version > 0?
> >
> > /Tomas
>
> pcmC only has version 0 and flags coded to zero, thankfully
>
> The channel layout box is where the "fun" begins with version 1 as
> well as this following quote:
>
> > When authoring, version 1 should be preferred over version 0.
> > Version 1 conveys the channel ordering, which is not always the case for
> > version 0. Version 1 should be used to convey the base channel count for 
> > DRC.

Applied as adca877acb930faf1a5d686af93b9f657cebf1b5 to make this set
under review shorter.

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 v2 3/8] avformat/mov: base the endianness on just the LSB

2023-03-05 Thread Jan Ekström
On Mon, Feb 27, 2023 at 3:37 PM Tomas Härdin  wrote:
>
> lör 2023-02-25 klockan 02:28 +0800 skrev Zhao Zhili:
> > From: Jan Ekström 
> >
> > As per 23003-5:2020, the rest of the bits are reserved, and thus
> > in the future they may be utilized for something else.
> >
> > Quote:
> > format_flags is a field of flags that modify the default PCM sample
> > format.
> > Undefined flags are reserved and shall be zero. The following flag is
> > defined:
> >   0x01 indicates little-endian format. If not present, big-endian
> > format is used.
> > ---
> >  libavformat/mov.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index cdd44a9e44..a9911c0f79 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -1608,7 +1608,7 @@ static int mov_read_pcmc(MOVContext *c,
> > AVIOContext *pb, MOVAtom atom)
> >  }
> >
> >  format_flags = avio_r8(pb);
> > -if (format_flags == 1) // indicates little-endian format. If not
> > present, big-endian format is used
> > +if (format_flags & 1) // indicates little-endian format. If not
> > present, big-endian format is used
>
> Should be OK.

Applied as 912ac82a3c769792ad992534f3df9b0a549ff827 to make this set
under review shorter, with a minor improvement to the commit message
("base *pcmC* endianness on just the LSB")

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] avfilter/graphparser: fix filter instance name when an id is provided

2023-03-05 Thread James Almer

On 3/2/2023 10:02 AM, James Almer wrote:

Restores the behavior of naming the instance filter@id, which was accidentally 
changed
to simpy id in commit f17051eaae.

Fixes ticket #10226.

Signed-off-by: James Almer 
---
  libavfilter/graphparser.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index 8e12416ccb..4347131fad 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -532,8 +532,7 @@ int 
avfilter_graph_segment_create_filters(AVFilterGraphSegment *seg, int flags)
  for (size_t j = 0; j < ch->nb_filters; j++) {
  AVFilterParams *p = ch->filters[j];
  const AVFilter *f = avfilter_get_by_name(p->filter_name);
-char inst_name[30], *name = p->instance_name ? p->instance_name :
-   inst_name;
+char name[64];
  
  // skip already processed filters

  if (p->filter || !p->filter_name)
@@ -546,7 +545,9 @@ int 
avfilter_graph_segment_create_filters(AVFilterGraphSegment *seg, int flags)
  }
  
  if (!p->instance_name)

-snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%zu", 
f->name, idx);
+snprintf(name, sizeof(name), "Parsed_%s_%zu", f->name, idx);
+else
+snprintf(name, sizeof(name), "%s@%s", f->name, 
p->instance_name);
  
  p->filter = avfilter_graph_alloc_filter(seg->graph, f, name);

  if (!p->filter)


Will apply.
___
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/3] avcodec/escape124: fix signdness of end of input check

2023-03-05 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
56561/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ESCAPE124_fuzzer-5560363635834880

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/escape124.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 024eec59ce..e9c6b2df1b 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -89,7 +89,7 @@ static CodeBook unpack_codebook(GetBitContext* gb, unsigned 
depth,
 unsigned i, j;
 CodeBook cb = { 0 };
 
-if (size >= INT_MAX / 34 || get_bits_left(gb) < size * 34)
+if (size >= INT_MAX / 34 || get_bits_left(gb) < (int)size * 34)
 return cb;
 
 if (size >= INT_MAX / sizeof(MacroBlock))
-- 
2.17.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/3] avcodec/escape124: Fix some return codes

2023-03-05 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/escape124.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index e9c6b2df1b..064a4e6bf5 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -89,11 +89,6 @@ static CodeBook unpack_codebook(GetBitContext* gb, unsigned 
depth,
 unsigned i, j;
 CodeBook cb = { 0 };
 
-if (size >= INT_MAX / 34 || get_bits_left(gb) < (int)size * 34)
-return cb;
-
-if (size >= INT_MAX / sizeof(MacroBlock))
-return cb;
 cb.blocks = av_malloc(size ? size * sizeof(MacroBlock) : 1);
 if (!cb.blocks)
 return cb;
@@ -225,7 +220,7 @@ static int escape124_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 // represent a lower bound of the space needed for skipped superblocks. Non
 // skipped SBs need more space.
 if (get_bits_left(&gb) < 64 + s->num_superblocks * 23LL / 4320)
-return -1;
+return AVERROR_INVALIDDATA;
 
 frame_flags = get_bits_long(&gb, 32);
 frame_size  = get_bits_long(&gb, 32);
@@ -276,9 +271,14 @@ static int escape124_decode_frame(AVCodecContext *avctx, 
AVFrame *frame,
 }
 
 av_freep(&s->codebooks[i].blocks);
+if (cb_size >= INT_MAX / 34 || get_bits_left(&gb) < (int)cb_size * 
34)
+return AVERROR_INVALIDDATA;
+
+if (cb_size >= INT_MAX / sizeof(MacroBlock))
+return AVERROR_INVALIDDATA;
 s->codebooks[i] = unpack_codebook(&gb, cb_depth, cb_size);
 if (!s->codebooks[i].blocks)
-return -1;
+return AVERROR(ENOMEM);
 }
 }
 
-- 
2.17.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/3] avcodec/escape124: Simplify unpack_codebook()

2023-03-05 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/escape124.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 064a4e6bf5..e8a8395f4b 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -97,15 +97,12 @@ static CodeBook unpack_codebook(GetBitContext* gb, unsigned 
depth,
 cb.size = size;
 for (i = 0; i < size; i++) {
 unsigned mask_bits = get_bits(gb, 4);
-unsigned color0 = get_bits(gb, 15);
-unsigned color1 = get_bits(gb, 15);
-
-for (j = 0; j < 4; j++) {
-if (mask_bits & (1 << j))
-cb.blocks[i].pixels[j] = color1;
-else
-cb.blocks[i].pixels[j] = color0;
-}
+unsigned color[2];
+color[0] = get_bits(gb, 15);
+color[1] = get_bits(gb, 15);
+
+for (j = 0; j < 4; j++)
+cb.blocks[i].pixels[j] = color[(mask_bits>>j) & 1];
 }
 return cb;
 }
-- 
2.17.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/matroska: Add support for A_ATRAC/AT1

2023-03-05 Thread asivery
Signed-off-by: asivery 
---
libavformat/matroska.c | 1 +
libavformat/matroskadec.c | 2 ++
2 files changed, 3 insertions(+)

diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index 90d94b65bf..37305a523c 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -55,6 +55,7 @@ const CodecTags ff_mkv_codec_tags[]={
{"A_REAL/ATRC" , AV_CODEC_ID_ATRAC3},
{"A_REAL/COOK" , AV_CODEC_ID_COOK},
{"A_REAL/SIPR" , AV_CODEC_ID_SIPR},
+ {"A_ATRAC/AT1" , AV_CODEC_ID_ATRAC1},
{"A_TRUEHD" , AV_CODEC_ID_TRUEHD},
{"A_TTA1" , AV_CODEC_ID_TTA},
{"A_VORBIS" , AV_CODEC_ID_VORBIS},
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..0aa8e6f3b3 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2795,6 +2795,8 @@ static int matroska_parse_tracks(AVFormatContext *s)
track->audio.frame_size);
if (!track->audio.buf)
return AVERROR(ENOMEM);
+ } else if (codec_id == AV_CODEC_ID_ATRAC1) {
+ st->codecpar->block_align = track->audio.channels * 212; /* Constant ATRAC 
frame size */
} else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) {
ret = matroska_parse_flac(s, track, &extradata_offset);
if (ret < 0)
--
2.34.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".


Re: [FFmpeg-devel] RFC: opinions on making fftools work like a library

2023-03-05 Thread Steven Liu
Zhao Zhili  于2023年3月3日周五 18:15写道:
>
> I'd like to know what do you think about making fftools work like a
> library, like what ffmpeg-kit already did, but with built-in support.
>
> https://github.com/arthenica/ffmpeg-kit
>
>FFmpegKit is a collection of tools to use FFmpeg in Android, iOS,
>Linux, macOS, tvOS, Flutter and React Native applications.
>
>It includes scripts to build FFmpeg native libraries, a wrapper
>library to run FFmpeg/FFprobe commands in applications and 8
>prebuilt binary packages available at Github, Maven Central,
>CocoaPods, pub and npm.
>
> Pro:
> 1. It can be used for testing on mobile devices.
> 2. It can be used directly to do useful work.
> 3. It can combine some work from projects like ffmpeg-kit to extend the
> funtion.
>
> Cons:
> 1. It makes things complicated.
> 2. It's hard to support mobile devices.
>
> Welcome to comments. I want to know is it:
>
> a. Absolutely no! It's not fftools supported to do.
> b. Doesn't matter/Don't care.
> c. I like the idea, (but...)

I think there have two problem when testing on mobile devices for me:
1. The ABI of libav* always be modified.
2. There have lots of error when i run fate on mobile devices

1.  just make a portable framework between ffmpeg and downstream
modules, eg. video editor, live streaming publisher.
If ffmpeg modified the ABI, just modify the framework should be ok.
But this should not part of ffmpeg.

2. I don't get lots of time to fix them. And not sure if you have same problem.

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


Thanks
Steven
___
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] codec/arm/hevcdsp_idct_neon: remove duplicate mov

2023-03-05 Thread xufuji456
---
 libavcodec/arm/hevcdsp_idct_neon.S | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavcodec/arm/hevcdsp_idct_neon.S 
b/libavcodec/arm/hevcdsp_idct_neon.S
index 41ca3b83a8..66ed1c6785 100644
--- a/libavcodec/arm/hevcdsp_idct_neon.S
+++ b/libavcodec/arm/hevcdsp_idct_neon.S
@@ -877,33 +877,27 @@ function func_tr_32x4_\name
 vld1.s16{q0}, [r9, :128]!
 vld1.s16{q1}, [r9, :128]
 add r4, sp, #2048
+mov r2, #64
+mov r8, #-64
 
 bl  tr_block1
 mov r1, r11
-mov r2, #64
-mov r8, #-64
 add r3, r11, #(56 + 3 * 64)
 scale_store \shift
 
 bl  tr_block2
 add r1, r11, #8
 add r3, r11, #(48 + 3 * 64)
-mov r2, #64
-mov r8, #-64
 scale_store \shift
 
 bl  tr_block3
 add r1, r11, #16
 add r3, r11, #(40 + 3 * 64)
-mov r2, #64
-mov r8, #-64
 scale_store \shift
 
 bl  tr_block4
 add r1, r11, #24
 add r3, r11, #(32 + 3 * 64)
-mov r2, #64
-mov r8, #-64
 scale_store \shift
 
 bx   r10
-- 
2.32.0 (Apple Git-132)

___
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 v2] avcodec/mathops: Optimize generic mid_pred function

2023-03-05 Thread Junxian Zhu
From: Junxian Zhu 

Rewrite mid_pred function in generic mathops.h, reduce branch jump to improve 
performance. And because nowadays new version compiler can compile enough short 
asmbbely code as handwritting in these function, so remove specified optimized 
mips inline asmbbely mathops.h.

Signed-off-by: Junxian Zhu 
---
 libavcodec/mathops.h  | 20 
 libavcodec/mips/mathops.h | 67 ---
 2 files changed, 6 insertions(+), 81 deletions(-)
 delete mode 100644 libavcodec/mips/mathops.h

diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index c89054d6ed..526ffe0eec 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -41,8 +41,6 @@ extern const uint8_t ff_zigzag_scan[16+1];
 #   include "arm/mathops.h"
 #elif ARCH_AVR32
 #   include "avr32/mathops.h"
-#elif ARCH_MIPS
-#   include "mips/mathops.h"
 #elif ARCH_PPC
 #   include "ppc/mathops.h"
 #elif ARCH_X86
@@ -98,18 +96,12 @@ static av_always_inline unsigned UMULH(unsigned a, unsigned 
b){
 #define mid_pred mid_pred
 static inline av_const int mid_pred(int a, int b, int c)
 {
-if(a>b){
-if(c>b){
-if(c>a) b=a;
-elseb=c;
-}
-}else{
-if(b>c){
-if(c>a) b=c;
-elseb=a;
-}
-}
-return b;
+int t0,t1,t2,t3;
+t0 = (a > b) ? b : a ;
+t1 = (a > b) ? a : b ;
+t2 = (t0 > c) ? t0 : c;
+t3 = (t1 > t2) ? t2 : t1;
+return t3; 
 }
 #endif
 
diff --git a/libavcodec/mips/mathops.h b/libavcodec/mips/mathops.h
deleted file mode 100644
index bb9dc8375a..00
--- a/libavcodec/mips/mathops.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2009 Mans Rullgard 
- * Copyright (c) 2015 Zhou Xiaoyong 
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef AVCODEC_MIPS_MATHOPS_H
-#define AVCODEC_MIPS_MATHOPS_H
-
-#include 
-#include "config.h"
-#include "libavutil/common.h"
-
-#if HAVE_INLINE_ASM
-
-#if HAVE_LOONGSON3
-
-#define MULH MULH
-static inline av_const int MULH(int a, int b)
-{
-int c;
-__asm__ ("dmult %1, %2  \n\t"
- "mflo %0   \n\t"
- "dsrl %0, %0, 32   \n\t"
- : "=r"(c)
- : "r"(a),"r"(b)
- : "hi", "lo");
-return c;
-}
-
-#define mid_pred mid_pred
-static inline av_const int mid_pred(int a, int b, int c)
-{
-int t = b;
-__asm__ ("sgt $8, %1, %2\n\t"
- "movn %0, %1, $8   \n\t"
- "movn %1, %2, $8   \n\t"
- "sgt $8, %1, %3\n\t"
- "movz %1, %3, $8   \n\t"
- "sgt $8, %0, %1\n\t"
- "movn %0, %1, $8   \n\t"
- : "+&r"(t),"+&r"(a)
- : "r"(b),"r"(c)
- : "$8");
-return t;
-}
-
-#endif /* HAVE_LOONGSON3 */
-
-#endif /* HAVE_INLINE_ASM */
-
-#endif /* AVCODEC_MIPS_MATHOPS_H */
-- 
2.39.2.windows.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".


Re: [FFmpeg-devel] [PATCH v2] avcodec/mathops: Optimize generic mid_pred function

2023-03-05 Thread James Almer

On 3/5/2023 11:38 PM, Junxian Zhu wrote:

From: Junxian Zhu 

Rewrite mid_pred function in generic mathops.h, reduce branch jump to improve 
performance. And because nowadays new version compiler can compile enough short 
asmbbely code as handwritting in these function, so remove specified optimized 
mips inline asmbbely mathops.h.

Signed-off-by: Junxian Zhu 
---
  libavcodec/mathops.h  | 20 
  libavcodec/mips/mathops.h | 67 ---
  2 files changed, 6 insertions(+), 81 deletions(-)
  delete mode 100644 libavcodec/mips/mathops.h

diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index c89054d6ed..526ffe0eec 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -41,8 +41,6 @@ extern const uint8_t ff_zigzag_scan[16+1];
  #   include "arm/mathops.h"
  #elif ARCH_AVR32
  #   include "avr32/mathops.h"
-#elif ARCH_MIPS
-#   include "mips/mathops.h"
  #elif ARCH_PPC
  #   include "ppc/mathops.h"
  #elif ARCH_X86
@@ -98,18 +96,12 @@ static av_always_inline unsigned UMULH(unsigned a, unsigned 
b){
  #define mid_pred mid_pred
  static inline av_const int mid_pred(int a, int b, int c)
  {
-if(a>b){
-if(c>b){
-if(c>a) b=a;
-elseb=c;
-}
-}else{
-if(b>c){
-if(c>a) b=c;
-elseb=a;
-}
-}
-return b;
+int t0,t1,t2,t3;
+t0 = (a > b) ? b : a ;
+t1 = (a > b) ? a : b ;
+t2 = (t0 > c) ? t0 : c;
+t3 = (t1 > t2) ? t2 : t1;
+return t3;


int t0 = FFMIN(a, b);
int t1 = FFMAX(a, b);
int t2 = FFMAX(t0, c);
return FFMIN(t1, t2);
___
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 v3 1/5] avformat/mov: fix ISO/IEC 23003-5 support

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

Missing floating-point formats support.

Signed-off-by: Zhao Zhili 
---
 libavformat/isom.h |  2 ++
 libavformat/mov.c  | 49 ++
 2 files changed, 51 insertions(+)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 5107b4eb74..4b1cd42f0f 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -418,6 +418,8 @@ static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int 
bps, int flags)
 
 #define MOV_ISMV_TTML_TAG MKTAG('d', 'f', 'x', 'p')
 #define MOV_MP4_TTML_TAG  MKTAG('s', 't', 'p', 'p')
+#define MOV_MP4_FPCM_TAG  MKTAG('f', 'p', 'c', 'm')
+#define MOV_MP4_IPCM_TAG  MKTAG('i', 'p', 'c', 'm')
 
 struct MP4TrackKindValueMapping {
 int disposition;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a9911c0f79..14528bdcaa 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1591,6 +1591,10 @@ static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 {
 int format_flags;
 int version, flags;
+int pcm_sample_size;
+AVFormatContext *fc = c->fc;
+AVStream *st;
+MOVStreamContext *sc;
 
 if (atom.size < 6) {
 av_log(c->fc, AV_LOG_ERROR, "Empty pcmC box\n");
@@ -1608,6 +1612,51 @@ static int mov_read_pcmc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 
 format_flags = avio_r8(pb);
+pcm_sample_size = avio_r8(pb);
+
+if (fc->nb_streams < 1)
+return AVERROR_INVALIDDATA;
+
+st = fc->streams[fc->nb_streams - 1];
+sc = st->priv_data;
+
+if (sc->format == MOV_MP4_FPCM_TAG) {
+switch (pcm_sample_size) {
+case 32:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_F32BE;
+break;
+case 64:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_F64BE;
+break;
+default:
+av_log(fc, AV_LOG_ERROR, "invalid pcm_sample_size %d for %s\n",
+ pcm_sample_size,
+ av_fourcc2str(sc->format));
+return AVERROR_INVALIDDATA;
+}
+} else if (sc->format == MOV_MP4_IPCM_TAG) {
+switch (pcm_sample_size) {
+case 16:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
+break;
+case 24:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE;
+break;
+case 32:
+st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;
+break;
+default:
+av_log(fc, AV_LOG_ERROR, "invalid pcm_sample_size %d for %s\n",
+ pcm_sample_size,
+ av_fourcc2str(sc->format));
+return AVERROR_INVALIDDATA;
+}
+} else {
+av_log(fc, AV_LOG_ERROR, "'pcmC' with invalid sample entry '%s'\n",
+av_fourcc2str(sc->format));
+return AVERROR_INVALIDDATA;
+}
+
 if (format_flags & 1) // indicates little-endian format. If not present, 
big-endian format is used
 set_last_stream_little_endian(c->fc);
 
-- 
2.25.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 v3 0/5] add PCM in mp4 support

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

This patchset adds support of demux/mux PCM in mp4, and related channel
layout information. PCM in mp4 is defined by ISO/IEC 23003-5. The channel
layout tag 'chn' is defined by ISO/IEC 14496-12 with reference to ISO/IEC
23001-8.

v3:
1. Rebase on master
2. Reorder the patchset to add demux support first, then mux
3. Add pcmC and chnl support in a single patch to movenc

v2:
1/8: simplied with switch-case
2-3/8: cherry-picked from jeeb's work
4/8: use switch-case and add log message
5/8:
6/8: 
  a. check version and flags
  b. support number of channels >= 64 with custom layout
  c. fix some channel layout operations like assignment directly
  d. return error for unsupported channel configurations
  e. warning when skiping bytes
7/8: support number of channels >= 64
8/8: fix fate-mov-mp4-pcm-float dependency

Zhao Zhili (5):
  avformat/mov: fix ISO/IEC 23003-5 support
  avformat/isom_tags: remove ipcm from movaudio_tags
  avformat/mov: parse ISO-14496-12 ChannelLayout
  avformat/movenc: add PCM in mp4 support
  fate/mov: add PCM in mp4 test

 libavformat/isom.h   |   2 +
 libavformat/isom_tags.c  |   2 -
 libavformat/mov.c| 134 +-
 libavformat/mov_chan.c   | 296 +++
 libavformat/mov_chan.h   |  26 +++
 libavformat/movenc.c |  84 -
 tests/fate/mov.mak   |  12 ++
 tests/filtergraphs/mov-mp4-pcm   |   5 +
 tests/ref/fate/mov-mp4-pcm   |  27 +++
 tests/ref/fate/mov-mp4-pcm-float |   7 +
 10 files changed, 591 insertions(+), 4 deletions(-)
 create mode 100644 tests/filtergraphs/mov-mp4-pcm
 create mode 100644 tests/ref/fate/mov-mp4-pcm
 create mode 100644 tests/ref/fate/mov-mp4-pcm-float

-- 
2.25.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 v3 2/5] avformat/isom_tags: remove ipcm from movaudio_tags

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

ipcm is defined by ISO/IEC 23003-5, not defined by quicktime. After
adding ISO/IEC 23003-5 support, we don't need it for ticket #9219.

Signed-off-by: Zhao Zhili 
---
 libavformat/isom_tags.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
index e2b80405cc..86c7272525 100644
--- a/libavformat/isom_tags.c
+++ b/libavformat/isom_tags.c
@@ -321,8 +321,6 @@ const AVCodecTag ff_codec_movaudio_tags[] = {
 { AV_CODEC_ID_PCM_S16LE,   MKTAG('s', 'o', 'w', 't') },
 { AV_CODEC_ID_PCM_S16BE,   MKTAG('l', 'p', 'c', 'm') },
 { AV_CODEC_ID_PCM_S16LE,   MKTAG('l', 'p', 'c', 'm') },
-{ AV_CODEC_ID_PCM_S16BE,   MKTAG('i', 'p', 'c', 'm') },
-{ AV_CODEC_ID_PCM_S16LE,   MKTAG('i', 'p', 'c', 'm') },
 { AV_CODEC_ID_PCM_S24BE,   MKTAG('i', 'n', '2', '4') },
 { AV_CODEC_ID_PCM_S24LE,   MKTAG('i', 'n', '2', '4') },
 { AV_CODEC_ID_PCM_S32BE,   MKTAG('i', 'n', '3', '2') },
-- 
2.25.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 v3 4/5] avformat/movenc: add PCM in mp4 support

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

It's defined by ISO/IEC 23003-5.

Fixes ticket #10185

Signed-off-by: Zhao Zhili 
---
 libavformat/movenc.c | 84 +++-
 1 file changed, 83 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index c4fcb5f8b1..2ec575c954 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1179,6 +1179,68 @@ static int mov_write_btrt_tag(AVIOContext *pb, MOVTrack 
*track)
 return update_size(pb, pos);
 }
 
+static int mov_write_chnl_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
+{
+int64_t pos = avio_tell(pb);
+int config = 0;
+int ret;
+uint8_t *speaker_pos = NULL;
+const AVChannelLayout *layout = &track->par->ch_layout;
+
+ret = ff_mov_get_channel_config_from_layout(layout, &config);
+if (ret || !config) {
+config = 0;
+speaker_pos = av_malloc(layout->nb_channels);
+ret = ff_mov_get_channel_positions_from_layout(layout,
+speaker_pos, layout->nb_channels);
+if (ret) {
+char buf[128] = {};
+
+av_freep(&speaker_pos);
+av_channel_layout_describe(layout, buf, sizeof(buf));
+av_log(s, AV_LOG_ERROR, "unsupported channel layout %s\n", buf);
+return ret;
+}
+}
+
+avio_wb32(pb, 0); /* size */
+ffio_wfourcc(pb, "chnl");
+avio_wb32(pb, 0); /* version & flags */
+
+avio_w8(pb, 1); /* stream_structure */
+avio_w8(pb, config);
+if (config) {
+avio_wb64(pb, 0);
+} else {
+for (int i = 0; i < layout->nb_channels; i++)
+avio_w8(pb, speaker_pos[i]);
+av_freep(&speaker_pos);
+}
+
+return update_size(pb, pos);
+}
+
+static int mov_write_pcmc_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack 
*track)
+{
+int64_t pos = avio_tell(pb);
+int format_flags;
+
+avio_wb32(pb, 0); /* size */
+ffio_wfourcc(pb, "pcmC");
+avio_wb32(pb, 0); /* version & flags */
+
+/* 0x01: indicates little-endian format */
+format_flags = (track->par->codec_id == AV_CODEC_ID_PCM_F32LE ||
+track->par->codec_id == AV_CODEC_ID_PCM_F64LE ||
+track->par->codec_id == AV_CODEC_ID_PCM_S16LE ||
+track->par->codec_id == AV_CODEC_ID_PCM_S24LE ||
+track->par->codec_id == AV_CODEC_ID_PCM_S32LE);
+avio_w8(pb, format_flags);
+avio_w8(pb, track->par->bits_per_raw_sample);
+
+return update_size(pb, pos);
+}
+
 static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, 
MOVMuxContext *mov, MOVTrack *track)
 {
 int64_t pos = avio_tell(pb);
@@ -1305,7 +1367,13 @@ static int mov_write_audio_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 ret = mov_write_dops_tag(s, pb, track);
 else if (track->par->codec_id == AV_CODEC_ID_TRUEHD)
 ret = mov_write_dmlp_tag(s, pb, track);
-else if (track->vos_len > 0)
+else if (tag == MOV_MP4_IPCM_TAG || tag == MOV_MP4_FPCM_TAG) {
+if (track->par->ch_layout.nb_channels > 1)
+ret = mov_write_chnl_tag(s, pb, track);
+if (ret < 0)
+return ret;
+ret = mov_write_pcmc_tag(s, pb, track);
+} else if (track->vos_len > 0)
 ret = mov_write_glbl_tag(pb, track);
 
 if (ret < 0)
@@ -7744,6 +7812,20 @@ static const AVCodecTag codec_mp4_tags[] = {
 { AV_CODEC_ID_MPEGH_3D_AUDIO,  MKTAG('m', 'h', 'm', '1') },
 { AV_CODEC_ID_TTML,MOV_MP4_TTML_TAG  },
 { AV_CODEC_ID_TTML,MOV_ISMV_TTML_TAG },
+
+/* ISO/IEC 23003-5 integer formats */
+{ AV_CODEC_ID_PCM_S16BE,   MOV_MP4_IPCM_TAG  },
+{ AV_CODEC_ID_PCM_S16LE,   MOV_MP4_IPCM_TAG  },
+{ AV_CODEC_ID_PCM_S24BE,   MOV_MP4_IPCM_TAG  },
+{ AV_CODEC_ID_PCM_S24LE,   MOV_MP4_IPCM_TAG  },
+{ AV_CODEC_ID_PCM_S32BE,   MOV_MP4_IPCM_TAG  },
+{ AV_CODEC_ID_PCM_S32LE,   MOV_MP4_IPCM_TAG  },
+/* ISO/IEC 23003-5 floating-point formats */
+{ AV_CODEC_ID_PCM_F32BE,   MOV_MP4_FPCM_TAG  },
+{ AV_CODEC_ID_PCM_F32LE,   MOV_MP4_FPCM_TAG  },
+{ AV_CODEC_ID_PCM_F64BE,   MOV_MP4_FPCM_TAG  },
+{ AV_CODEC_ID_PCM_F64LE,   MOV_MP4_FPCM_TAG  },
+
 { AV_CODEC_ID_NONE,   0 },
 };
 #if CONFIG_MP4_MUXER || CONFIG_PSP_MUXER
-- 
2.25.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 v3 5/5] fate/mov: add PCM in mp4 test

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

Signed-off-by: Zhao Zhili 
---
 tests/fate/mov.mak   | 12 
 tests/filtergraphs/mov-mp4-pcm   |  5 +
 tests/ref/fate/mov-mp4-pcm   | 27 +++
 tests/ref/fate/mov-mp4-pcm-float |  7 +++
 4 files changed, 51 insertions(+)
 create mode 100644 tests/filtergraphs/mov-mp4-pcm
 create mode 100644 tests/ref/fate/mov-mp4-pcm
 create mode 100644 tests/ref/fate/mov-mp4-pcm-float

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 8a7218a215..d795445691 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -165,6 +165,18 @@ FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, 
WAV_DEMUXER PAN_FILTER) \
 fate-mov-channel-description: tests/data/asynth-44100-1.wav 
tests/data/filtergraphs/mov-channel-description
 fate-mov-channel-description: CMD = transcode wav 
$(TARGET_PATH)/tests/data/asynth-44100-1.wav mov "-filter_complex_script 
$(TARGET_PATH)/tests/data/filtergraphs/mov-channel-description -map [outFL] 
-map [outFR] -map [outFC] -map [outLFE] -map [outBL] -map [outBR] -map [outDL] 
-map [outDR] -c:a pcm_s16le" "-map 0 -c copy -frames:a 0"
 
+# Test PCM in mp4 and channel layout
+FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \
+  += fate-mov-mp4-pcm
+fate-mov-mp4-pcm: tests/data/asynth-44100-1.wav 
tests/data/filtergraphs/mov-mp4-pcm
+fate-mov-mp4-pcm: CMD = transcode wav 
$(TARGET_PATH)/tests/data/asynth-44100-1.wav mp4 "-filter_complex_script 
$(TARGET_PATH)/tests/data/filtergraphs/mov-mp4-pcm -map [mono] -map [stereo] 
-map [2.1] -map [5.1] -map [7.1] -c:a pcm_s16le" "-map 0 -c copy -frames:a 0"
+
+# Test floating sample format PCM in mp4 and unusual channel layout
+FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \
+  += fate-mov-mp4-pcm-float
+fate-mov-mp4-pcm-float: tests/data/asynth-44100-1.wav
+fate-mov-mp4-pcm-float: CMD = transcode wav 
$(TARGET_PATH)/tests/data/asynth-44100-1.wav mp4 "-af 
aresample,pan=FL+LFE+BR|c0=c0|c1=c0|c2=c0 -c:a pcm_f32le" "-map 0 -c copy 
-frames:a 0"
+
 FATE_FFMPEG += $(FATE_MOV_FFMPEG-yes)
 
 fate-mov: $(FATE_MOV) $(FATE_MOV_FFMPEG-yes) $(FATE_MOV_FFPROBE) 
$(FATE_MOV_FASTSTART) $(FATE_MOV_FFMPEG_FFPROBE-yes)
diff --git a/tests/filtergraphs/mov-mp4-pcm b/tests/filtergraphs/mov-mp4-pcm
new file mode 100644
index 00..7fa25a2c3c
--- /dev/null
+++ b/tests/filtergraphs/mov-mp4-pcm
@@ -0,0 +1,5 @@
+[0:a:0]pan=mono|c0=c0[mono];
+[0:a:0]pan=stereo|c0=c0|c1=c0[stereo];
+[0:a:0]pan=2.1|c0=c0|c1=c0|c2=c0[2.1];
+[0:a:0]pan=5.1|c0=c0|c1=c0|c2=c0|c3=c0|c4=c0|c5=c0[5.1];
+[0:a:0]pan=7.1|c0=c0|c1=c0|c2=c0|c3=c0|c4=c0|c5=c0|c6=c0|c7=c0[7.1];
diff --git a/tests/ref/fate/mov-mp4-pcm b/tests/ref/fate/mov-mp4-pcm
new file mode 100644
index 00..b34f5e59e1
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-pcm
@@ -0,0 +1,27 @@
+1573ecbd24a65a6ec23ef08a861614b3 *tests/data/fate/mov-mp4-pcm.mp4
+10589277 tests/data/fate/mov-mp4-pcm.mp4
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 44100
+#channel_layout_name 0: mono
+#tb 1: 1/44100
+#media_type 1: audio
+#codec_id 1: pcm_s16le
+#sample_rate 1: 44100
+#channel_layout_name 1: stereo
+#tb 2: 1/44100
+#media_type 2: audio
+#codec_id 2: pcm_s16le
+#sample_rate 2: 44100
+#channel_layout_name 2: 2.1
+#tb 3: 1/44100
+#media_type 3: audio
+#codec_id 3: pcm_s16le
+#sample_rate 3: 44100
+#channel_layout_name 3: 5.1
+#tb 4: 1/44100
+#media_type 4: audio
+#codec_id 4: pcm_s16le
+#sample_rate 4: 44100
+#channel_layout_name 4: 7.1
diff --git a/tests/ref/fate/mov-mp4-pcm-float b/tests/ref/fate/mov-mp4-pcm-float
new file mode 100644
index 00..851b79090c
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-pcm-float
@@ -0,0 +1,7 @@
+691a76a847e0f3720c09cca341971f19 *tests/data/fate/mov-mp4-pcm-float.mp4
+3175929 tests/data/fate/mov-mp4-pcm-float.mp4
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: pcm_f32le
+#sample_rate 0: 44100
+#channel_layout_name 0: 3 channels (FL+LFE+BR)
-- 
2.25.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 v3 3/5] avformat/mov: parse ISO-14496-12 ChannelLayout

2023-03-05 Thread Zhao Zhili
From: Zhao Zhili 

Only support chnl version 0 now.

Signed-off-by: Zhao Zhili 
---
 libavformat/mov.c  |  85 +++-
 libavformat/mov_chan.c | 296 +
 libavformat/mov_chan.h |  26 
 3 files changed, 406 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 14528bdcaa..057fd872b1 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -940,6 +940,88 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return 0;
 }
 
+static int mov_read_chnl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+int64_t end = av_sat_add64(avio_tell(pb), atom.size);
+int stream_structure;
+int version, flags;
+int ret = 0;
+AVStream *st;
+
+if (c->fc->nb_streams < 1)
+return 0;
+st = c->fc->streams[c->fc->nb_streams-1];
+
+version = avio_r8(pb);
+flags   = avio_rb24(pb);
+if (version != 0 || flags != 0) {
+av_log(c->fc, AV_LOG_ERROR,
+   "Unsupported 'chnl' box with version %d, flags: %#x",
+   version, flags);
+return AVERROR_INVALIDDATA;
+}
+
+stream_structure = avio_r8(pb);
+
+// stream carries channels
+if (stream_structure & 1) {
+int layout = avio_r8(pb);
+
+av_log(c->fc, AV_LOG_TRACE, "'chnl' layout %d\n", layout);
+if (!layout) {
+uint8_t *positions = 
av_malloc(st->codecpar->ch_layout.nb_channels);
+
+if (!positions)
+return AVERROR(ENOMEM);
+for (int i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
+int speaker_pos = avio_r8(pb);
+
+av_log(c->fc, AV_LOG_TRACE, "speaker_position %d\n", 
speaker_pos);
+if (speaker_pos == 126) { // explicit position
+avpriv_request_sample(c->fc, "explicit position");
+av_freep(&positions);
+return AVERROR_PATCHWELCOME;
+} else {
+positions[i] = speaker_pos;
+}
+}
+
+ret = ff_mov_get_layout_from_channel_positions(positions,
+st->codecpar->ch_layout.nb_channels,
+&st->codecpar->ch_layout);
+av_freep(&positions);
+if (ret) {
+av_log(c->fc, AV_LOG_ERROR,
+"get channel layout from speaker positions failed, 
%s\n",
+av_err2str(ret));
+return ret;
+}
+} else {
+uint64_t omitted_channel_map = avio_rb64(pb);
+
+if (omitted_channel_map) {
+avpriv_request_sample(c->fc, "omitted_channel_map 0x%" PRIx64 
" != 0",
+  omitted_channel_map);
+return AVERROR_PATCHWELCOME;
+}
+ff_mov_get_channel_layout_from_config(layout, 
&st->codecpar->ch_layout);
+}
+}
+
+// stream carries objects
+if (stream_structure & 2) {
+int obj_count = avio_r8(pb);
+av_log(c->fc, AV_LOG_TRACE, "'chnl' with object_count %d\n", 
obj_count);
+}
+
+if (avio_tell(pb) != end) {
+av_log(c->fc, AV_LOG_WARNING, "skip %" PRId64 " bytes of unknown data 
inside chnl\n",
+end - avio_tell(pb));
+avio_seek(pb, end, SEEK_SET);
+}
+return ret;
+}
+
 static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
 AVStream *st;
@@ -7817,7 +7899,8 @@ static const MOVParseTableEntry mov_default_parse_table[] 
= {
 { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */
 { MKTAG('w','f','e','x'), mov_read_wfex },
 { MKTAG('c','m','o','v'), mov_read_cmov },
-{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */
+{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout from quicktime */
+{ MKTAG('c','h','n','l'), mov_read_chnl }, /* channel layout from ISO-14496-12 
*/
 { MKTAG('d','v','c','1'), mov_read_dvc1 },
 { MKTAG('s','g','p','d'), mov_read_sgpd },
 { MKTAG('s','b','g','p'), mov_read_sbgp },
diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index f66bf0df7f..df17976e59 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -551,3 +551,299 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, 
AVStream *st,
 
 return 0;
 }
+
+/* ISO/IEC 23001-8, 8.2 */
+static const AVChannelLayout iso_channel_configuration[] = {
+// 0: any setup
+{},
+
+// 1: centre front
+AV_CHANNEL_LAYOUT_MONO,
+
+// 2: left front, right front
+AV_CHANNEL_LAYOUT_STEREO,
+
+// 3: centre front, left front, right front
+AV_CHANNEL_LAYOUT_SURROUND,
+
+// 4: centre front, left front, right front, rear centre
+AV_CHANNEL_LAYOUT_4POINT0,
+
+// 5: centre front, left front, right front, left surround, right surround
+AV_CHANNEL_LAYOUT_5POINT0,
+
+// 6: 5 + LFE
+AV_CHANNEL_LAYOUT_5POINT1,
+
+// 7: centre front, left front centre,