Re: [FFmpeg-devel] [PATCH] avcodec/avcodec: don't uninitialize ch_layout in avcodec_close()
On Sat, Mar 19, 2022 at 4:04 AM James Almer wrote: > > The function is not meant to clear codec parameters, and the lavf demux code > relies on this behavior. > Regression since 327efa66331ebdc0087c6b656059a8df2f404019. > > Signed-off-by: James Almer > --- > libavcodec/avcodec.c | 6 ++ > 1 file changed, 6 insertions(+) > > diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c > index 38bdaad4fa..253c9f56cc 100644 > --- a/libavcodec/avcodec.c > +++ b/libavcodec/avcodec.c > @@ -469,6 +469,7 @@ void avsubtitle_free(AVSubtitle *sub) > > av_cold int avcodec_close(AVCodecContext *avctx) > { > +AVChannelLayout ch_layout; > int i; > > if (!avctx) > @@ -524,7 +525,12 @@ av_cold int avcodec_close(AVCodecContext *avctx) > > if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) > av_opt_free(avctx->priv_data); > +/* av_opt_free() will uninitialize avctx->ch_layout, but we want to keep > it. > + It will be uninitialized in avcodec_free_context() */ > +ch_layout = avctx->ch_layout; > +memset(&avctx->ch_layout, 0, sizeof(avctx->ch_layout)); > av_opt_free(avctx); > +avctx->ch_layout = ch_layout; > av_freep(&avctx->priv_data); > if (av_codec_is_encoder(avctx->codec)) { > av_freep(&avctx->extradata); This feels pretty ugly and still a bit risky that any call to av_opt_free could invalidate data its not supposed to. Maybe we should have a flag for AVOptions instead where av_opt_free won't touch an entry, because its only there to set/get it, not manage its memory? - Hendrik ___ 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/avcodec: don't uninitialize ch_layout in avcodec_close()
Quoting James Almer (2022-03-19 04:04:07) > The function is not meant to clear codec parameters, and the lavf demux code > relies on this behavior. Maybe it shouldn't? Which code is it exactly? -- Anton Khirnov ___ 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/3] avformat/slndec: add support to set channel layout
Quoting James Almer (2022-03-18 23:19:05) > Signed-off-by: James Almer > --- > libavformat/pcmdec.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c > index dcd13787d5..a2bcfc2814 100644 > --- a/libavformat/pcmdec.c > +++ b/libavformat/pcmdec.c > @@ -170,7 +170,8 @@ PCMDEF(vidc, "PCM Archimedes VIDC", > NULL, VIDC) > #if CONFIG_SLN_DEMUXER > static const AVOption sln_options[] = { > { "sample_rate", "", offsetof(PCMAudioDemuxerContext, sample_rate), > AV_OPT_TYPE_INT, {.i64 = 8000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, > -{ "channels","", offsetof(PCMAudioDemuxerContext, channels), > AV_OPT_TYPE_INT, {.i64 = 1}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, > +{ "channels","", offsetof(PCMAudioDemuxerContext, channels), > AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, > +{ "ch_layout", "", offsetof(PCMAudioDemuxerContext, ch_layout), > AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, > { NULL }, > }; > > -- > 2.35.1 For what purpose? The demuxer doesn't do anything with the value. -- Anton Khirnov ___ 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] Allow to modify max qp configuration parameter in libvpx without reseting the encoder
Quoting Lynne (2022-03-16 13:37:55) > 16 Mar 2022, 13:13 by danilchap-at-google@ffmpeg.org: > > > On Mon, Mar 14, 2022 at 4:28 PM Jan Ekström wrote: > > > >> > >> On Mon, Mar 14, 2022 at 3:05 PM Danil Chapovalov > >> wrote: > >> > > >> > --- > >> > >> Probably something a la > >> > >> avcodec/libvpxenc: enable dynamic quantizer reconfiguration > >> > >> ? > >> > > > > Thank you, resubmitted with new title > > > >> > >> > libavcodec/libvpxenc.c | 7 +++ > >> > 1 file changed, 7 insertions(+) > >> > > >> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c > >> > index 8f94ba15dc..45baeed435 100644 > >> > --- a/libavcodec/libvpxenc.c > >> > +++ b/libavcodec/libvpxenc.c > >> > @@ -1658,6 +1658,13 @@ static int vpx_encode(AVCodecContext *avctx, > >> > AVPacket *pkt, > >> > flags |= strtoul(en->value, NULL, 10); > >> > } > >> > > >> > +en = av_dict_get(frame->metadata, "max-quantizer", NULL, 0); > >> > +if (en) { > >> > +struct vpx_codec_enc_cfg cfg = *enccfg; > >> > +cfg.rc_max_quantizer = strtoul(en->value, NULL, 10); > >> > +vpx_codec_enc_config_set(&ctx->encoder, &cfg); > >> > +} > >> > + > >> > >> There is side data already defined for quantizers, AVVideoEncParams / > >> AV_FRAME_DATA_VIDEO_ENC_PARAMS . > >> > >> In other words, this should be handled in a similar manner to ROI, not > >> as an ad-hoc metadata key in the AVFrame. > >> > > > > I've checked struct AVVideoEncParams, it doesn't look fitting: it > > contains exact qp (plus qp per plane), while my patch suggests > > changing max-qp limit for current and following frames. > > AVVideoEncParams also has some extra fields that I'm unsure how to > > handle (they are unrelated to what I'm trying to do), > > I haven't found any other struct that would contain something like max qp. > > What is ROI? What code can I use as an example of your suggestion? > > > > If the encoder is operating under bitrate mode, then I think it would > be fine to interpret the qp field as a max qp field. > IIRC Youtube run libvpx and libaom under constant bitrate mode and > adjust the max quantizer per frame, because no one can fix the > rate control system of either library. Why not just update AVCodecContext.qmax? -- Anton Khirnov ___ 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 2/3] avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
Very nice. -- Anton Khirnov ___ 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] lavf/mpegenc: fix memory leak in the fifo since the new API
Quoting Nicolas Gaullier (2022-03-18 14:15:04) > The older av_fifo_realloc2 implemented an auto grow that should be ported as > such. > > This introduces a limitation in the buffer size. > AUTO_GROW_DEFAULT_BYTES is currently 1MB which seems reasonable here. Are you sure it's enough? 1MB packets are not unthinkable for high-bitrate video. -- Anton Khirnov ___ 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/video: fix shadowed variable
Quoting Zhao Zhili (2022-03-10 07:53:38) > --- > libavfilter/video.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libavfilter/video.c b/libavfilter/video.c > index fa3d588044..b2f0cdf88a 100644 > --- a/libavfilter/video.c > +++ b/libavfilter/video.c > @@ -50,7 +50,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, > int w, int h) > if (link->hw_frames_ctx && > ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == > link->format) { > int ret; > -AVFrame *frame = av_frame_alloc(); > +frame = av_frame_alloc(); > > if (!frame) > return NULL; > -- > 2.31.1 Looks good, will push -- Anton Khirnov ___ 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 v7 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser
This commit adds support to libavcodec to read and parse encoded Jpeg XL images. Jpeg XL is intended to be an extended-life replacement to legacy mjpeg. --- MAINTAINERS|2 + libavcodec/Makefile|1 + libavcodec/codec_desc.c|9 + libavcodec/codec_id.h |1 + libavcodec/jpegxl.h| 43 ++ libavcodec/jpegxl_parser.c | 1031 libavcodec/parsers.c |1 + libavcodec/version.h |2 +- 8 files changed, 1089 insertions(+), 1 deletion(-) create mode 100644 libavcodec/jpegxl.h create mode 100644 libavcodec/jpegxl_parser.c diff --git a/MAINTAINERS b/MAINTAINERS index 931cf4bd2c..2e0de9e224 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -188,6 +188,7 @@ Codecs: interplayvideo.c Mike Melanson jni*, ffjni* Matthieu Bouron jpeg2000* Nicolas Bertrand + jpegxl.h, jpegxl_parser.c Leo Izen jvdec.c Peter Ross lcl*.cRoberto Togni, Reimar Doeffinger libcelt_dec.c Nicolas George @@ -616,6 +617,7 @@ Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 DC99 E0F5 76D4 76FC 437F Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368 James Almer 7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 59E0 Jean Delvare 7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 4E6A +Leo Izen (thebombzen) B6FD 3CFC 7ACF 83FC 9137 6945 5A71 C331 FD2F A19A Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE Lynne FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 4464 Michael Niedermayer 9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB diff --git a/libavcodec/Makefile b/libavcodec/Makefile index dc6dc8a4bb..3c40c419cd 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -44,6 +44,7 @@ OBJS = ac3_parser.o \ dv_profile.o \ encode.o \ imgconvert.o \ + jpegxl_parser.o \ jni.o\ mathtables.o \ mediacodec.o \ diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 81f3b3c640..1b82870aaa 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1863,6 +1863,15 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"), .props = AV_CODEC_PROP_LOSSY, }, +{ +.id= AV_CODEC_ID_JPEGXL, +.type = AVMEDIA_TYPE_VIDEO, +.name = "jpegxl", +.long_name = NULL_IF_CONFIG_SMALL("JPEG XL"), +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | + AV_CODEC_PROP_LOSSLESS, +.mime_types= MT("image/jxl"), +}, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 3ffb9bd22e..dbc4f3a208 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -308,6 +308,7 @@ enum AVCodecID { AV_CODEC_ID_SIMBIOSIS_IMX, AV_CODEC_ID_SGA_VIDEO, AV_CODEC_ID_GEM, +AV_CODEC_ID_JPEGXL, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h new file mode 100644 index 00..4f93c99687 --- /dev/null +++ b/libavcodec/jpegxl.h @@ -0,0 +1,43 @@ +/* + * JPEG XL header + * Copyright (c) 2021 Leo Izen + * + * 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 + */ + +/** + * @file + * JPEG XL header + */ + +#ifndef AVCODEC_JPEGXL_H +#define AVCODEC_JPEGXL_H + +#include + +/* these are also used in avformat/img2dec.c */ +#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff +#define FF_JPEGXL_CODESTREAM
[FFmpeg-devel] [PATCH v7 2/5] avcodec/libjxl: add Jpeg XL decoding via libjxl
This commit adds decoding support to libavcodec for Jpeg XL images via the external library libjxl. --- MAINTAINERS | 1 + configure | 5 + doc/general_contents.texi | 7 + libavcodec/Makefile | 1 + libavcodec/allcodecs.c| 1 + libavcodec/libjxl.c | 70 + libavcodec/libjxl.h | 48 ++ libavcodec/libjxldec.c| 301 ++ 8 files changed, 434 insertions(+) create mode 100644 libavcodec/libjxl.c create mode 100644 libavcodec/libjxl.h create mode 100644 libavcodec/libjxldec.c diff --git a/MAINTAINERS b/MAINTAINERS index 2e0de9e224..875d25ca89 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -195,6 +195,7 @@ Codecs: libcodec2.c Tomas Härdin libdirac* David Conrad libdavs2.cHuiwen Ren + libjxl*.c, libjxl.h Leo Izen libgsm.c Michel Bardiaux libkvazaar.c Arttu Ylä-Outinen libopenh264enc.c Martin Storsjo, Linjie Fu diff --git a/configure b/configure index c43d1bb2e7..a88de8ca9c 100755 --- a/configure +++ b/configure @@ -240,6 +240,7 @@ External library support: --enable-libiec61883 enable iec61883 via libiec61883 [no] --enable-libilbc enable iLBC de/encoding via libilbc [no] --enable-libjack enable JACK audio sound server [no] + --enable-libjxl enable JPEG XL decoding via libjxl [no] --enable-libklvanc enable Kernel Labs VANC processing [no] --enable-libkvazaar enable HEVC encoding via libkvazaar [no] --enable-liblensfun enable lensfun lens correction [no] @@ -1833,6 +1834,7 @@ EXTERNAL_LIBRARY_LIST=" libiec61883 libilbc libjack +libjxl libklvanc libkvazaar libmodplug @@ -3329,6 +3331,7 @@ libgsm_ms_decoder_deps="libgsm" libgsm_ms_encoder_deps="libgsm" libilbc_decoder_deps="libilbc" libilbc_encoder_deps="libilbc" +libjxl_decoder_deps="libjxl libjxl_threads" libkvazaar_encoder_deps="libkvazaar" libmodplug_demuxer_deps="libmodplug" libmp3lame_encoder_deps="libmp3lame" @@ -6541,6 +6544,8 @@ enabled libgsm&& { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do check_lib libgsm "${gsm_hdr}" gsm_create -lgsm && break; done || die "ERROR: libgsm not found"; } enabled libilbc && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc $pthreads_extralibs +enabled libjxl&& require_pkg_config libjxl "libjxl >= 0.7.0" jxl/decode.h JxlDecoderVersion && + require_pkg_config libjxl_threads "libjxl_threads >= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner enabled libklvanc && require libklvanc libklvanc/vanc.h klvanc_context_create -lklvanc enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" kvazaar.h kvz_api_get enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h lf_db_new diff --git a/doc/general_contents.texi b/doc/general_contents.texi index fcd9da1b34..a893347fbe 100644 --- a/doc/general_contents.texi +++ b/doc/general_contents.texi @@ -171,6 +171,13 @@ Go to @url{https://github.com/TimothyGu/libilbc} and follow the instructions for installing the library. Then pass @code{--enable-libilbc} to configure to enable it. +@section libjxl + +JPEG XL is an image format intended to fully replace legacy JPEG for an extended +period of life. See @url{https://jpegxl.info/} for more information, and see +@url{https://github.com/libjxl/libjxl} for the library source. You can pass +@code{--enable-libjxl} to configure in order enable the libjxl wrapper. + @section libvpx FFmpeg can make use of the libvpx library for VP8/VP9 decoding and encoding. diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3c40c419cd..572e31e647 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1059,6 +1059,7 @@ OBJS-$(CONFIG_LIBGSM_MS_DECODER) += libgsmdec.o OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsmenc.o OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o +OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 74049afa8f..7d1eb0e22c 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -748,6 +748,7 @@ extern const AVCodec ff_libgsm_ms_encoder; extern const AVCodec ff_libgsm_ms_decoder; extern const AVCodec ff_libilbc_encoder; extern const AVCodec ff_libilbc_decoder; +extern const AVCodec ff_libjxl_decoder; extern const AVCodec ff_libmp3lame_encoder; extern const AVCodec ff_libope
[FFmpeg-devel] [PATCH v7 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl
This commit adds encoding support to libavcodec for Jpeg XL images via the external library libjxl. --- configure | 3 +- libavcodec/Makefile| 1 + libavcodec/allcodecs.c | 1 + libavcodec/libjxlenc.c | 386 + 4 files changed, 390 insertions(+), 1 deletion(-) create mode 100644 libavcodec/libjxlenc.c diff --git a/configure b/configure index a88de8ca9c..3b098cc716 100755 --- a/configure +++ b/configure @@ -240,7 +240,7 @@ External library support: --enable-libiec61883 enable iec61883 via libiec61883 [no] --enable-libilbc enable iLBC de/encoding via libilbc [no] --enable-libjack enable JACK audio sound server [no] - --enable-libjxl enable JPEG XL decoding via libjxl [no] + --enable-libjxl enable JPEG XL de/encoding via libjxl [no] --enable-libklvanc enable Kernel Labs VANC processing [no] --enable-libkvazaar enable HEVC encoding via libkvazaar [no] --enable-liblensfun enable lensfun lens correction [no] @@ -3332,6 +3332,7 @@ libgsm_ms_encoder_deps="libgsm" libilbc_decoder_deps="libilbc" libilbc_encoder_deps="libilbc" libjxl_decoder_deps="libjxl libjxl_threads" +libjxl_encoder_deps="libjxl libjxl_threads" libkvazaar_encoder_deps="libkvazaar" libmodplug_demuxer_deps="libmodplug" libmp3lame_encoder_deps="libmp3lame" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 572e31e647..e81e911f55 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1060,6 +1060,7 @@ OBJS-$(CONFIG_LIBGSM_MS_ENCODER) += libgsmenc.o OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o +OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 7d1eb0e22c..179827ebca 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -749,6 +749,7 @@ extern const AVCodec ff_libgsm_ms_decoder; extern const AVCodec ff_libilbc_encoder; extern const AVCodec ff_libilbc_decoder; extern const AVCodec ff_libjxl_decoder; +extern const AVCodec ff_libjxl_encoder; extern const AVCodec ff_libmp3lame_encoder; extern const AVCodec ff_libopencore_amrnb_encoder; extern const AVCodec ff_libopencore_amrnb_decoder; diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c new file mode 100644 index 00..a96bea0425 --- /dev/null +++ b/libavcodec/libjxlenc.c @@ -0,0 +1,386 @@ +/* + * JPEG XL encoding support via libjxl + * Copyright (c) 2021 Leo Izen + * + * 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 + */ + +/** + * @file + * JPEG XL encoder using libjxl + */ + +#include "libavutil/avutil.h" +#include "libavutil/error.h" +#include "libavutil/frame.h" +#include "libavutil/libm.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/pixfmt.h" +#include "libavutil/version.h" + +#include "avcodec.h" +#include "internal.h" + +#include +#include +#include "libjxl.h" + +typedef struct LibJxlEncodeContext { +AVClass *class; +void *runner; +JxlEncoder *encoder; +JxlEncoderFrameSettings *options; +int effort; +float distance; +int modular; +uint8_t *buffer; +size_t buffer_size; +} LibJxlEncodeContext; + +/** + * Map a quality setting for -qscale roughly from libjpeg + * quality numbers to libjxl's butteraugli distance for + * photographic content. + * + * Setting distance explicitly is preferred, but this will + * allow qscale to be used as a fallback. + * + * This function is continuous and injective on [0, 100] which + * makes it monotonic. + * + * @param quality 0.0 to 100.0 quality setting, libjpeg quality + * @return Butteraugli distance between 0.0 and 15.0 + */ +static float quality_to_distance(float quality){ +if (quality >= 100.0) { +return 0.0; +} else if (quality >= 90.0) { +return (100.0 - quality) * 0.10; +} else if (quality >= 30.0) { +return 0.1 + (100.0 - quality) * 0.09; +
[FFmpeg-devel] [PATCH v7 4/5] avformat/image2: add Jpeg XL as image2 format
This commit adds support to libavformat for muxing and demuxing Jpeg XL images as image2 streams. --- libavformat/allformats.c | 1 + libavformat/img2.c | 1 + libavformat/img2dec.c| 21 + libavformat/img2enc.c| 6 +++--- libavformat/mov.c| 1 + libavformat/version.h| 4 ++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 587ad59b3c..941f3643f8 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -510,6 +510,7 @@ extern const AVInputFormat ff_image_gif_pipe_demuxer; extern const AVInputFormat ff_image_j2k_pipe_demuxer; extern const AVInputFormat ff_image_jpeg_pipe_demuxer; extern const AVInputFormat ff_image_jpegls_pipe_demuxer; +extern const AVInputFormat ff_image_jpegxl_pipe_demuxer; extern const AVInputFormat ff_image_pam_pipe_demuxer; extern const AVInputFormat ff_image_pbm_pipe_demuxer; extern const AVInputFormat ff_image_pcx_pipe_demuxer; diff --git a/libavformat/img2.c b/libavformat/img2.c index 4153102c92..13b1b997b8 100644 --- a/libavformat/img2.c +++ b/libavformat/img2.c @@ -87,6 +87,7 @@ const IdStrMap ff_img_tags[] = { { AV_CODEC_ID_GEM,"img" }, { AV_CODEC_ID_GEM,"ximg" }, { AV_CODEC_ID_GEM,"timg" }, +{ AV_CODEC_ID_JPEGXL, "jxl" }, { AV_CODEC_ID_NONE, NULL } }; diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index b9c06c5b54..32cadacb9d 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -32,6 +32,7 @@ #include "libavutil/parseutils.h" #include "libavutil/intreadwrite.h" #include "libavcodec/gif.h" +#include "libavcodec/jpegxl.h" #include "avformat.h" #include "avio_internal.h" #include "internal.h" @@ -836,6 +837,25 @@ static int jpegls_probe(const AVProbeData *p) return 0; } +static int jpegxl_probe(const AVProbeData *p) +{ +const uint8_t *b = p->buf; + +/* ISOBMFF-based container */ +/* 0x4a584c20 == "JXL " */ +if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE) +return AVPROBE_SCORE_EXTENSION + 1; +#if CONFIG_JPEGXL_PARSER +/* Raw codestreams all start with 0xff0a */ +if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) +return 0; +if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, p->buf_size) == 0) +return AVPROBE_SCORE_MAX - 2; +#endif +return 0; +} + + static int pcx_probe(const AVProbeData *p) { const uint8_t *b = p->buf; @@ -1165,6 +1185,7 @@ IMAGEAUTO_DEMUXER(gif, GIF) IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K) IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG) IMAGEAUTO_DEMUXER(jpegls,JPEGLS) +IMAGEAUTO_DEMUXER(jpegxl,JPEGXL) IMAGEAUTO_DEMUXER(pam, PAM) IMAGEAUTO_DEMUXER(pbm, PBM) IMAGEAUTO_DEMUXER(pcx, PCX) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index 9b3b8741c8..e6ec6a50aa 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -263,9 +263,9 @@ static const AVClass img2mux_class = { const AVOutputFormat ff_image2_muxer = { .name = "image2", .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), -.extensions = "bmp,dpx,exr,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,png," - "ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,im24," - "sunras,xbm,xface,pix,y", +.extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv," + "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8," + "im24,sunras,xbm,xface,pix,y", .priv_data_size = sizeof(VideoMuxData), .video_codec= AV_CODEC_ID_MJPEG, .write_header = write_header, diff --git a/libavformat/mov.c b/libavformat/mov.c index 6c847de164..c4b8873b0a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7697,6 +7697,7 @@ static int mov_probe(const AVProbeData *p) if (tag == MKTAG('f','t','y','p') && ( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ') || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ') +|| AV_RL32(p->buf + offset + 8) == MKTAG('j','x','l',' ') )) { score = FFMAX(score, 5); } else { diff --git a/libavformat/version.h b/libavformat/version.h index f4a26c2870..683184d5da 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,8 +31,8 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 20 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MINOR 21 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 2.35.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.or
[FFmpeg-devel] [PATCH v7 5/5] fate/jpegxl: add JPEG XL demux and parse FATE test
Add a fate test for the JPEG XL parser in libavcodec and its image2 wrapper inside libavformat. --- tests/fate/image.mak| 10 ++ tests/ref/fate/jxl-parse-codestream | 6 ++ tests/ref/fate/jxl-parse-container | 6 ++ 3 files changed, 22 insertions(+) create mode 100644 tests/ref/fate/jxl-parse-codestream create mode 100644 tests/ref/fate/jxl-parse-container diff --git a/tests/fate/image.mak b/tests/fate/image.mak index 573d398915..15b6145c58 100644 --- a/tests/fate/image.mak +++ b/tests/fate/image.mak @@ -357,6 +357,16 @@ FATE_JPEGLS-$(call DEMDEC, IMAGE2, JPEGLS) += $(FATE_JPEGLS) FATE_IMAGE += $(FATE_JPEGLS-yes) fate-jpegls: $(FATE_JPEGLS-yes) +FATE_JPEGXL += fate-jxl-parse-codestream +fate-jxl-parse-codestream: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/belgium.jxl -c:v copy + +FATE_JPEGXL += fate-jxl-parse-container +fate-jxl-parse-container: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/lenna-256.jxl -c:v copy + +FATE_JPEGXL-$(call DEMDEC, IMAGE2) += $(FATE_JPEGXL) +FATE_IMAGE += $(FATE_JPEGXL-yes) +fate-jxl: $(FATE_JPEGXL-yes) + FATE_IMAGE-$(call DEMDEC, IMAGE2, QDRAW) += fate-pict fate-pict: CMD = framecrc -i $(TARGET_SAMPLES)/quickdraw/TRU256.PCT -pix_fmt rgb24 diff --git a/tests/ref/fate/jxl-parse-codestream b/tests/ref/fate/jxl-parse-codestream new file mode 100644 index 00..b2fe5035ac --- /dev/null +++ b/tests/ref/fate/jxl-parse-codestream @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 768x512 +#sar 0: 0/1 +0, 0, 0,1, 32, 0xa2930a20 diff --git a/tests/ref/fate/jxl-parse-container b/tests/ref/fate/jxl-parse-container new file mode 100644 index 00..99233d612a --- /dev/null +++ b/tests/ref/fate/jxl-parse-container @@ -0,0 +1,6 @@ +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: jpegxl +#dimensions 0: 256x256 +#sar 0: 0/1 +0, 0, 0,1, 8088, 0xbbfea9bd -- 2.35.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] avcodec/vp9_superframe_split_bsf: Check in size
On Fri, Mar 18, 2022 at 06:56:19PM +0100, Andreas Rheinhardt wrote: > Michael Niedermayer: > > Fixes: Out of array read > > Fixes: > > 45137/clusterfuzz-testcase-minimized-ffmpeg_BSF_VP9_SUPERFRAME_SPLIT_fuzzer-4984270639202304 > > > > Found-by: continuous fuzzing process > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > Signed-off-by: Michael Niedermayer > > --- > > libavcodec/vp9_superframe_split_bsf.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/libavcodec/vp9_superframe_split_bsf.c > > b/libavcodec/vp9_superframe_split_bsf.c > > index ed0444561a..481484a4f0 100644 > > --- a/libavcodec/vp9_superframe_split_bsf.c > > +++ b/libavcodec/vp9_superframe_split_bsf.c > > @@ -51,7 +51,7 @@ static int vp9_superframe_split_filter(AVBSFContext *ctx, > > AVPacket *out) > > return ret; > > in = s->buffer_pkt; > > > > -marker = in->data[in->size - 1]; > > +marker = in->size ? in->data[in->size - 1] : 0; > > if ((marker & 0xe0) == 0xc0) { > > int length_size = 1 + ((marker >> 3) & 0x3); > > int nb_frames = 1 + (marker & 0x7); > > There is a second place in this BSF where data might be read in the > absence of data, namely if one of the frames in a superframe have size > of zero (its attempted to read its profile; no actual read takes place > due to the checks of the get_bits API, but it is nevertheless invalid > data). See > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200530160541.29517-7-andreas.rheinha...@gmail.com/; > also see > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200530160541.29517-11-andreas.rheinha...@gmail.com/ > and > https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200530160541.29517-1-andreas.rheinha...@gmail.com/ Why did you not apply your bugfixes ? I think you should apply them thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you drop bombs on a foreign country and kill a hundred thousand innocent people, expect your government to call the consequence "unprovoked inhuman terrorist attacks" and use it to justify dropping more bombs and killing more people. The technology changed, the idea is old. 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] [PATCH 2/3] avcodec/wmalosslessdec: Check channel mask against num channels
On Fri, Mar 18, 2022 at 08:38:28AM -0300, James Almer wrote: > > > On 3/18/2022 8:27 AM, Michael Niedermayer wrote: > > On Thu, Mar 17, 2022 at 10:00:18PM -0300, James Almer wrote: > > > > > > > > > On 3/17/2022 9:07 PM, James Almer wrote: > > > > > > > > > > > > On 3/17/2022 8:52 PM, James Almer wrote: > > > > > On 3/17/2022 8:30 PM, Michael Niedermayer wrote: > > > > > > Fixes: Out of array write > > > > > > Fixes: > > > > > > 45613/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMALOSSLESS_fuzzer-4539073606320128 > > > > > > > > > > > > > > > > > > Found-by: continuous fuzzing process > > > > > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > > > > > Signed-off-by: Michael Niedermayer > > > > > > --- > > > > > > libavcodec/wmalosslessdec.c | 3 +++ > > > > > > 1 file changed, 3 insertions(+) > > > > > > > > > > > > diff --git a/libavcodec/wmalosslessdec.c > > > > > > b/libavcodec/wmalosslessdec.c > > > > > > index cd05b22689..1728920729 100644 > > > > > > --- a/libavcodec/wmalosslessdec.c > > > > > > +++ b/libavcodec/wmalosslessdec.c > > > > > > @@ -281,6 +281,9 @@ static av_cold int > > > > > > decode_init(AVCodecContext *avctx) > > > > > > av_channel_layout_uninit(&avctx->ch_layout); > > > > > > av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); > > > > > > + if (s->num_channels != avctx->ch_layout.nb_channels) > > > > > > + return AVERROR_PATCHWELCOME; //are there non fuzzed > > > > > > files with this or is it an error ? > > > > > > > > > > s->num_channels at this point is set to the channels count the user > > > > > set before calling avcodec_open2() (Normally from lavf), but it > > > > > could be anything. > > > > > If channel_mask is taken from extradata, maybe it should be used to > > > > > set s->num_channels instead of aborting because the user set value > > > > > and extradata disagreed. > > > > > > > > > > Also, can you reproduce this crash before 3c933af493? > > > > > s->num_channels was being set to the user set channel count too, > > > > > same as now. > > > > > > > > Right, before that commit s->num_channels and avctx->channels were > > > > always the same, but avctx->channel_layout was whatever came from > > > > extradata, and its popcnt could be != avctx->channels. > > > > After it, avctx->ch_layout.nb_channels is always the same as > > > > popcnt(avctx->ch_layout.u.mask), which can be different than > > > > s->num_channels. > > > > > > > > I think my suggestion above to use the extradata channel mask and > > > > ignoring the user set channel count is the best approach for this. > > > > > > Like this maybe (channel_mask could in theory be zero, so in that case the > > > user set value should be used). > > > > > > > diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c > > > > index cd05b22689..915add1962 100644 > > > > --- a/libavcodec/wmalosslessdec.c > > > > +++ b/libavcodec/wmalosslessdec.c > > > > @@ -197,15 +197,6 @@ static av_cold int decode_init(AVCodecContext > > > > *avctx) > > > > return AVERROR_PATCHWELCOME; > > > > } > > > > > > > > -s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels; > > > > -s->frame_data = av_mallocz(s->max_frame_size + > > > > AV_INPUT_BUFFER_PADDING_SIZE); > > > > -if (!s->frame_data) > > > > -return AVERROR(ENOMEM); > > > > - > > > > -s->avctx = avctx; > > > > -ff_llauddsp_init(&s->dsp); > > > > -init_put_bits(&s->pb, s->frame_data, s->max_frame_size); > > > > - > > > > if (avctx->extradata_size >= 18) { > > > > s->decode_flags= AV_RL16(edata_ptr + 14); > > > > channel_mask = AV_RL32(edata_ptr + 2); > > > > @@ -230,6 +221,33 @@ static av_cold int decode_init(AVCodecContext > > > > *avctx) > > > > return AVERROR_PATCHWELCOME; > > > > } > > > > > > > > +if (channel_mask) { > > > > +av_channel_layout_uninit(&avctx->ch_layout); > > > > +av_channel_layout_from_mask(&avctx->ch_layout, channel_mask); > > > > +} else > > > > +avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; > > > > + > > > > +s->num_channels = avctx->ch_layout.nb_channels; > > > > + > > > > +/* extract lfe channel position */ > > > > +s->lfe_channel = -1; > > > > + > > > > +if (channel_mask & 8) { > > > > +unsigned int mask; > > > > +for (mask = 1; mask < 16; mask <<= 1) > > > > +if (channel_mask & mask) > > > > +++s->lfe_channel; > > > > +} > > > > + > > > > +s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels; > > > > +s->frame_data = av_mallocz(s->max_frame_size + > > > > AV_INPUT_BUFFER_PADDING_SIZE); > > > > +if (!s->frame_data) > > > > +return AVERROR(ENOMEM); > > > > + > > > > +s->avctx = avctx; > > > > +ff_llauddsp_init(&s->dsp); > > > > +init_put_bits(&s->pb, s->frame_data, s->max_frame_size); > > > > + > > > > /* generic i
Re: [FFmpeg-devel] [PATCH 4/4] ffmpeg: replace custom channel_layout code with an SpecifierOpt based one
On Fri, Mar 18, 2022 at 07:47:48PM -0300, James Almer wrote: > This is cleaner and allows fine tuning which stream the option is applied to. > > Signed-off-by: James Almer > --- > fftools/ffmpeg.h | 2 ++ > fftools/ffmpeg_opt.c | 84 ++-- > 2 files changed, 36 insertions(+), 50 deletions(-) Not sure its intended or not but This changes the output of ./ffmpeg -channel_layout 3.0 -ac 3 -f u8 -i /dev/zero -t 1 /tmp/file-old.wav 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] [PATCH 2/4] avformat/mxfdec: Check count in mxf_read_strong_ref_array()
On Mon, Mar 14, 2022 at 08:19:51PM +0100, Tomas Härdin wrote: > sön 2022-03-13 klockan 00:52 +0100 skrev Michael Niedermayer: > > Signed-off-by: Michael Niedermayer > > --- > > libavformat/mxfdec.c | 8 +++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c > > index b85c10bf19..d7cdd22c8a 100644 > > --- a/libavformat/mxfdec.c > > +++ b/libavformat/mxfdec.c > > @@ -932,7 +932,13 @@ static int mxf_read_cryptographic_context(void > > *arg, AVIOContext *pb, int tag, i > > > > static int mxf_read_strong_ref_array(AVIOContext *pb, UID **refs, > > int *count) > > { > > - *count = avio_rb32(pb); > > + unsigned c = avio_rb32(pb); > > not uint32_t? we dont need an exact length variable here > > > + > > + //avio_read() used int > > + if (c > INT_MAX / sizeof(UID)) > > + return AVERROR_PATCHWELCOME; > > + *count = c; > > + > > This should already be caught by av_calloc(), no? the API as in the documentation of av_calloc() does not gurantee this. Its bad practice if we write code that depends on some implementation of some code in a diferent module/lib thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Does the universe only have a finite lifespan? No, its going to go on forever, its just that you wont like living in it. -- Hiranya Peiri 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] [PATCH 3/4] avformat/mxfdec: Check for avio_read() failure in mxf_read_strong_ref_array()
On Mon, Mar 14, 2022 at 08:21:04PM +0100, Tomas Härdin wrote: > sön 2022-03-13 klockan 00:52 +0100 skrev Michael Niedermayer: > > Signed-off-by: Michael Niedermayer > > --- > > libavformat/mxfdec.c | 8 +++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c > > index d7cdd22c8a..828fc0f9f1 100644 > > --- a/libavformat/mxfdec.c > > +++ b/libavformat/mxfdec.c > > @@ -932,6 +932,7 @@ static int mxf_read_cryptographic_context(void > > *arg, AVIOContext *pb, int tag, i > > > > static int mxf_read_strong_ref_array(AVIOContext *pb, UID **refs, > > int *count) > > { > > + int64_t ret; > > unsigned c = avio_rb32(pb); > > > > //avio_read() used int > > @@ -946,7 +947,12 @@ static int mxf_read_strong_ref_array(AVIOContext > > *pb, UID **refs, int *count) > > return AVERROR(ENOMEM); > > } > > avio_skip(pb, 4); /* useless size of objects, always 16 > > according to specs */ > > - avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID)); > > + ret = avio_read(pb, (uint8_t *)*refs, *count * sizeof(UID)); > > + if (ret != *count * sizeof(UID)) { > > + *count = ret < 0 ? 0 : ret / sizeof(UID); > > + return ret < 0 ? ret : AVERROR_INVALIDDATA; > > Looks ok i will apply once we agree on the previous patch as that is on top of it thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Asymptotically faster algorithms should always be preferred if you have asymptotical amounts of data 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] [PATCH 0/6] avcodec/vc1: Arm optimisations
Hi Ben, On Thu, 17 Mar 2022, Ben Avison wrote: The VC1 decoder was missing lots of important fast paths for Arm, especially for 64-bit Arm. This submission fills in implementations for all functions where a fast path already existed and the fallback C implementation was taking 1% or more of the runtime, and adds a new fast path to permit vc1_unescape_buffer() to be overridden. I've measured the playback speed on a 1.5 GHz Cortex-A72 (Raspberry Pi 4) using `ffmpeg -i -f null -` for a couple of example streams: Architecture: AArch32AArch32AArch64AArch64 Stream:1 2 1 2 Before speed: 1.22x 0.82x 1.00x 0.67x After speed: 1.31x 0.98x 1.39x 1.06x Improvement: 7.4% 20%39%58% `make fate` passes on both AArch32 and AArch64. Thanks for the patches! I have looked briefly at the patches (I haven't started reading the implementation in detail yet though). As you are writing assembly for these functions, I would very much appreciate if you could add checkasm tests for all the functions you're implementing. I see that there exists a test for the blockdsp functions, but all the other ones are missing a test. I try to request such tests for all new assembly. Such a test allows testing all interesting cornercases of the DSP functions with one concise test, instead of having to run the full fate testsuite. It also allows catching a number of other possible lingering issues, like using the full 64 bit register when the argument only set 32 bits where the upper bits are undefined, or missing to restore callee saved registers, etc. It also allows for easy benchmarking of the functions on their own, which is very useful for tuning of the implementation. And it finally allows easily checking that the assembly works correctly when built with a different toolchain for a different platform - without needing to run the full decoding tests. Especially as you've been implementing the functions, you're probably more familiar with the expectations and behaviours (and potential cornercases that are worth testing) of the functions than most other developers in the community at the moment, which is good for writing useful testcases. There's plenty of existing examples of such tests - the h264dsp, vp8dsp and vp9dsp cases might be relevant. The other main issue I'd like to request is to indent the assembly similarly to the rest of the existing assembly. For the 32 bit assembly, your patches do match the surrounding code, but for the 64 bit assembly, your patches align the operands column differently than the rest. (I think your code aligns the operands with 16 chars to the left of the operands, while our code aligns it with 24 chars to the left, both in 32 and 64 bit arm assembly.) Finally, the 32 bit assembly fails to build for me both with (recent) clang and old binutils, with errors like these: src/libavcodec/arm/vc1dsp_neon.S: Assembler messages: src/libavcodec/arm/vc1dsp_neon.S:1579: Error: bad type for scalar -- `vmov r0,d4[1]' src/libavcodec/arm/vc1dsp_neon.S:1582: Error: bad type for scalar -- `vmov r2,d5[1]' src/libavcodec/arm/vc1dsp_neon.S:1592: Error: bad type for scalar -- `vmov r2,d8[1]' src/libavcodec/arm/vc1dsp_neon.S:1595: Error: bad type for scalar -- `vmov r12,d9[1]' Qualifying the "vmov" into "vmov.32" seems to fix it. // Martin ___ 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 0/6] avcodec/vc1: Arm optimisations
On Sun, 20 Mar 2022, Martin Storsjö wrote: The other main issue I'd like to request is to indent the assembly similarly to the rest of the existing assembly. For the 32 bit assembly, your patches do match the surrounding code, but for the 64 bit assembly, your patches align the operands column differently than the rest. (I think your code aligns the operands with 16 chars to the left of the operands, while our code aligns it with 24 chars to the left, both in 32 and 64 bit arm assembly.) Oh, sidenote - I do see that the last patch in the set uses much more inconsistent indentation, with varying indentation between lines. Is this intentional to signify some structure in the code, or just accidental? I think it'd be preferrable to have it use normal straight indentation all the way throughout. // Martin ___ 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/binkaudio: add support for >2 channels dct codec
On Fri, Mar 18, 2022 at 04:21:44PM +0100, Paul B Mahol wrote: > On 3/18/22, Andreas Rheinhardt wrote: > > Paul B Mahol: > >> As presented in .binka files. > >> > >> Signed-off-by: Paul B Mahol > >> --- > >> libavcodec/binkaudio.c | 50 +++--- > >> 1 file changed, 32 insertions(+), 18 deletions(-) > >> > >> diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c > >> index b4ff15beeb..54b7e22854 100644 > >> --- a/libavcodec/binkaudio.c > >> +++ b/libavcodec/binkaudio.c > >> @@ -51,13 +51,14 @@ typedef struct BinkAudioContext { > >> int version_b; ///< Bink version 'b' > >> int first; > >> int channels; > >> +int ch_offset; > >> int frame_len; ///< transform size (samples) > >> int overlap_len;///< overlap size (samples) > >> int block_size; > >> int num_bands; > >> float root; > >> unsigned int bands[26]; > >> -float previous[MAX_CHANNELS][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs > >> from previous audio block > >> +float previous[6][BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from > >> previous audio block > >> float quant_table[96]; > >> AVPacket *pkt; > >> union { > >> @@ -74,6 +75,7 @@ static av_cold int decode_init(AVCodecContext *avctx) > >> int sample_rate_half; > >> int i, ret; > >> int frame_len_bits; > >> +int max_channels = avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT ? > >> MAX_CHANNELS : 6; > > > > If you allow up to six channels, then MAX_CHANNELS (i.e. two) needs to > > be renamed. > > > >> int channels = avctx->ch_layout.nb_channels; > >> > >> /* determine frame length */ > >> @@ -85,7 +87,7 @@ static av_cold int decode_init(AVCodecContext *avctx) > >> frame_len_bits = 11; > >> } > >> > >> -if (channels < 1 || channels > MAX_CHANNELS) { > >> +if (channels < 1 || channels > max_channels) { > >> av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", > >> channels); > >> return AVERROR_INVALIDDATA; > >> } > >> @@ -110,7 +112,7 @@ static av_cold int decode_init(AVCodecContext *avctx) > >> > >> s->frame_len = 1 << frame_len_bits; > >> s->overlap_len = s->frame_len / 16; > >> -s->block_size= (s->frame_len - s->overlap_len) * s->channels; > >> +s->block_size= (s->frame_len - s->overlap_len) * > >> FFMIN(MAX_CHANNELS, s->channels); > >> sample_rate_half = (sample_rate + 1LL) / 2; > >> if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) > >> s->root = 2.0 / (sqrt(s->frame_len) * 32768.0); > >> @@ -166,7 +168,8 @@ static const uint8_t rle_length_tab[16] = { > >> * @param[out] out Output buffer (must contain s->block_size elements) > >> * @return 0 on success, negative error code on failure > >> */ > >> -static int decode_block(BinkAudioContext *s, float **out, int use_dct) > >> +static int decode_block(BinkAudioContext *s, float **out, int use_dct, > >> +int channels, int ch_offset) > >> { > >> int ch, i, j, k; > >> float q, quant[25]; > >> @@ -176,8 +179,8 @@ static int decode_block(BinkAudioContext *s, float > >> **out, int use_dct) > >> if (use_dct) > >> skip_bits(gb, 2); > >> > >> -for (ch = 0; ch < s->channels; ch++) { > >> -FFTSample *coeffs = out[ch]; > >> +for (ch = 0; ch < channels; ch++) { > >> +FFTSample *coeffs = out[ch + ch_offset]; > >> > >> if (s->version_b) { > >> if (get_bits_left(gb) < 64) > >> @@ -252,17 +255,17 @@ static int decode_block(BinkAudioContext *s, float > >> **out, int use_dct) > >> s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs); > >> } > >> > >> -for (ch = 0; ch < s->channels; ch++) { > >> +for (ch = 0; ch < channels; ch++) { > >> int j; > >> -int count = s->overlap_len * s->channels; > >> +int count = s->overlap_len * channels; > >> if (!s->first) { > >> j = ch; > >> -for (i = 0; i < s->overlap_len; i++, j += s->channels) > >> -out[ch][i] = (s->previous[ch][i] * (count - j) + > >> - out[ch][i] * j) / count; > >> +for (i = 0; i < s->overlap_len; i++, j += channels) > >> +out[ch + ch_offset][i] = (s->previous[ch + ch_offset][i] > >> * (count - j) + > >> + out[ch + ch_offset][i] * > >> j) / count; ^^^ This line needs to be indented some more, to match the previous line. > >> } > >> -memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len], > >> - s->overlap_len * sizeof(*s->previous[ch])); > >> +memcpy(s->previous[ch + ch_offset], &out[ch + > >> ch_offset][s->frame_len - s->overlap_len], > >> + s->overlap_len * sizeof(*s->previous[ch + ch_offset])); > >> } > >> > >> s->first = 0; > >> @@ -293,6 +296,7 @@ static int binkaudio_