Re: [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Always reset got_picture at the beginnig of decoding

2022-04-15 Thread Michael Niedermayer
On Thu, Apr 14, 2022 at 05:56:30PM +0200, Andreas Rheinhardt wrote:
> Said field is set when parsing a SOF; yet a picture is only allocated
> if skip_frame is != AVDISCARD_ALL. This leads to a crash in the
> following case: If a jpeg is split into two parts, the first containing
> everything before the scans including the SOF and the second part
> containing the rest, and the first part is sent to the decoder with
> skip_frame set to AVDISCARD_ALL, got_picture is set, yet no picture
> is allocated. If the next part is sent with skip_frame set to
> AVDISCARD_NONE, the code presumes that a picture has been allocated,
> although it hasn't leading to segfaults.
> 
> Fix this by resetting got_picture at the beginning of decoding.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> This patch presumes that there is not use-case for partitioning
> the data corresponding to a single AVFrame accross multiple packets.
> I am not certain whether this is actually true, in particular
> wrt interlaced input where it might be common to put the data for
> one field into one packet.
> Anyway, no such use is covered by FATE.

This changes timestamps slightly for:
./ffmpeg -an -i ~/tickets/1915/m_noint.avi -an -bitexact -f framecrc -t 1 -

not sure thats intended

thx

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

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad


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 v2 1/1] lavc/aarch64: add some neon pix_abs functions

2022-04-15 Thread Martin Storsjö

On Thu, 14 Apr 2022, Swinney, Jonathan wrote:


- ff_pix_abs16_neon
- ff_pix_abs16_xy2_neon

In direct micro benchmarks of these ff functions verses their C implementations,
these functions performed as follows on AWS Graviton 2:

ff_pix_abs16_neon:
c:  benchmark ran 10 iterations in 0.955383 seconds
ff: benchmark ran 10 iterations in 0.097669 seconds

ff_pix_abs16_xy2_neon:
c:  benchmark ran 10 iterations in 1.916759 seconds
ff: benchmark ran 10 iterations in 0.370729 seconds


It's generally preferred to include the numbers from checkasm --bench for 
these functions. You can execute it with e.g. "checkasm --bench=pix_fmt 
--test=motion" to run only the relevant tests and benchmark some specific 
function.



Also for the checkasm test; generally I'd suggest looking closer at some 
existing test as a good example. I think e.g. vp8dsp is a decent testcase 
to use as model.



Signed-off-by: Jonathan Swinney 
---
libavcodec/aarch64/Makefile  |   2 +
libavcodec/aarch64/me_cmp_init_aarch64.c |  39 +
libavcodec/aarch64/me_cmp_neon.S | 209 +++
libavcodec/me_cmp.c  |   2 +
libavcodec/me_cmp.h  |   1 +
libavcodec/x86/me_cmp.asm|   7 +
libavcodec/x86/me_cmp_init.c |   3 +
tests/checkasm/Makefile  |   2 +-
tests/checkasm/checkasm.c|   1 +
tests/checkasm/checkasm.h|   1 +
tests/checkasm/motion.c  | 155 +
11 files changed, 421 insertions(+), 1 deletion(-)
create mode 100644 libavcodec/aarch64/me_cmp_init_aarch64.c
create mode 100644 libavcodec/aarch64/me_cmp_neon.S
create mode 100644 tests/checkasm/motion.c




diff --git a/libavcodec/aarch64/Makefile b/libavcodec/aarch64/Makefile
index 954461f81d..18869da1b4 100644
--- a/libavcodec/aarch64/Makefile
+++ b/libavcodec/aarch64/Makefile
@@ -7,6 +7,7 @@ OBJS-$(CONFIG_H264PRED) += 
aarch64/h264pred_init.o
OBJS-$(CONFIG_H264QPEL) += aarch64/h264qpel_init_aarch64.o
OBJS-$(CONFIG_HPELDSP)  += aarch64/hpeldsp_init_aarch64.o
OBJS-$(CONFIG_IDCTDSP)  += aarch64/idctdsp_init_aarch64.o
+OBJS-$(CONFIG_ME_CMP)   += aarch64/me_cmp_init_aarch64.o
OBJS-$(CONFIG_MPEGAUDIODSP) += aarch64/mpegaudiodsp_init.o
OBJS-$(CONFIG_NEON_CLOBBER_TEST)+= aarch64/neontest.o
OBJS-$(CONFIG_PIXBLOCKDSP)  += aarch64/pixblockdsp_init_aarch64.o


If this is gated behind a CONFIG_ME_CMP here, we should use the same 
CONFIG_ME_CMP for conditionals in checkasm too.



+++ b/libavcodec/me_cmp.c
@@ -1062,6 +1062,8 @@ av_cold void ff_me_cmp_init(MECmpContext *c, 
AVCodecContext *avctx)

if (ARCH_ALPHA)
ff_me_cmp_init_alpha(c, avctx);
+if (ARCH_AARCH64)
+ff_me_cmp_init_aarch64(c, avctx);


Please add this in alphabetical order, aarch64 comes before alpha.


if (ARCH_ARM)
ff_me_cmp_init_arm(c, avctx);
if (ARCH_PPC)
diff --git a/libavcodec/me_cmp.h b/libavcodec/me_cmp.h
index e9b5161c9a..2c13bb9d3b 100644
--- a/libavcodec/me_cmp.h
+++ b/libavcodec/me_cmp.h
@@ -81,6 +81,7 @@ typedef struct MECmpContext {

void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_alpha(MECmpContext *c, AVCodecContext *avctx);
+void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_arm(MECmpContext *c, AVCodecContext *avctx);


Ditto about alphabetical order


void ff_me_cmp_init_ppc(MECmpContext *c, AVCodecContext *avctx);
void ff_me_cmp_init_x86(MECmpContext *c, AVCodecContext *avctx);
diff --git a/libavcodec/x86/me_cmp.asm b/libavcodec/x86/me_cmp.asm
index ad06d485ab..f73b9f9161 100644
--- a/libavcodec/x86/me_cmp.asm
+++ b/libavcodec/x86/me_cmp.asm
@@ -255,6 +255,7 @@ hadamard8x8_diff %+ SUFFIX:

HSUM m0, m1, eax
and rax, 0x
+emms
ret



I think we shouldn't be changing the existing x86 functions here. Let's 
originally assume that the existing x86 functions are correct - they're 
expected to not call emms (as the code expects that to be done at a higher 
level somewhere). Therefore, the new checkasm test needs to check the emms 
handling in a way which acecpts the current x86 code. Lots of checkasm 
tests uses "declare_func_emms(AV_CPU_FLAG_MMX, ..." which I think implies 
this intent.



diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index f768b1144e..f542ce0768 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -30,7 +30,7 @@ AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o

-CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes)
+CHECKASMOBJS-$(CONFIG_AVCODEC)  += $(AVCODECOBJS-yes) motion.o



I guess this should use CONFIG_ME_CMP?


# libavfilter tests
AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += 

Re: [FFmpeg-devel] [PATCH v2 0/1] lavc/aarch64: add some neon pix_abs functions

2022-04-15 Thread Martin Storsjö

On Thu, 14 Apr 2022, Swinney, Jonathan wrote:

Thanks Martin for the review. I made some updates according to the 
suggestions you made.


I added a checkasm function, but I'm new to the test framework, so it 
may need some work still.


Thanks for putting in the effort to make a test - that adds a lot of value 
to the project! I'll follow up with a review of the newly added test.



Would it be beneficial to not do the addv here on each iteration, but
accumulate in v18.8h, and the just do one single addv at the end?


I did some testing with this, and it is, indeed, faster, however the 
problem I ran into is that the bounds for the loop can be higher than 
the capacity of a 16-bit unsigned integer used for accumulating in 
v16.8h. With the addv inside the loop, this register can hold the 
maximum possible value without overflowing before we increase the width 
of the field with the add instruction. If you have a trick or there are 
restrictions on the inputs that I am not aware of, let me know.


Ok, I see! Can the accumulation be done with widening, i.e. uaddw v18.4s, 
v18.4s, v16.4h, uaddw2 v19.4s, v19.4s, v16.8h? (Or you could add both 
halves into the same v18.4s, but using two destination registers there 
probably helps.) That would keep the logic more SIMD-like while doing the 
flattening to one scalar value only once at the end.



This version most certainly would be slower indeed. If we could be ok with
doing a bit of overread, the simplest version might be to load e.g. "ld1
{v4.16b, v5.16b}, [x2]" followed by "ext v5.16b, v4.16b, v5.16b, #1" to
shift it. But doing an overlapping unaligned load probably is fine too.


I experimented with these instructions and found that it was marginally 
faster on Graviton 2, but it was slower on Graviton 3. Graviton 3 has 
more vector pipelines than Graviton 2 and is therefore a better 
candidate for video encoding workloads, so I chose to prefer Graviton 3. 
I didn't test it other chips.


Ok - I guess the current implementation of that aspect is fine then!

// 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 v14 4/4] avformat/image2: add Jpeg XL as image2 format

2022-04-15 Thread Andreas Rheinhardt
Leo Izen:
> 
> On 4/15/22 07:34, Andreas Rheinhardt wrote:
>> Leo Izen:
>>> +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;
>>> +    /* Raw codestreams all start with 0xff0a */
>>> +    if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
>>> +    return 0;
>>> +    if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)
>> This will give a linking failure if the image_jpegxl_pipe_demuxer is
>> disabled.
>>
> I thought of that, and I tested it, and it doesn't. It produces a
> compiler warning that the static function jpegxl_probe is never called,
> which means the linker probably throws away the function entirely, thus
> eliminating a linking error. Though I admit that's a guess.

That only works when optimizations are enabled. Try again with -O0.

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

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


Re: [FFmpeg-devel] [PATCH v14 4/4] avformat/image2: add Jpeg XL as image2 format

2022-04-15 Thread Leo Izen



On 4/15/22 07:34, Andreas Rheinhardt wrote:

Leo Izen:

+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;
+/* Raw codestreams all start with 0xff0a */
+if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
+return 0;
+if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)

This will give a linking failure if the image_jpegxl_pipe_demuxer is
disabled.

I thought of that, and I tested it, and it doesn't. It produces a 
compiler warning that the static function jpegxl_probe is never called, 
which means the linker probably throws away the function entirely, thus 
eliminating a linking error. Though I admit that's a guess.

For the record: I'm not really ok with duplicating this code in lavf and
lavc.

This code was removed from avcodec when I moved it over to avformat, for 
now, in order to avoid an avpriv in avcodec's ABI. Essentially we have 
to decide to either duplicate code in the future, or move it to avcodec 
and add an avpriv to the ABI, but that is a decision that can be made 
down the road when Lynne finishes her proper parser. I believe this is a 
better solution now than the other way around since we can later change 
our minds once there will actually be duplicated code, but an avpriv 
cannot be removed once added without waiting the necessary ABI change 
period.


- Leo Izen (thebombzen)
___
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 v14 3/4] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-04-15 Thread Leo Izen



On 4/15/22 06:39, Anton Khirnov wrote:

Quoting Leo Izen (2022-04-15 03:37:20)

On 4/14/22 13:49, Anton Khirnov wrote:

Quoting Leo Izen (2022-04-12 07:53:32)

+
+while (1) {
+jret = JxlEncoderProcessOutput(ctx->encoder, _out, );
+if (jret == JXL_ENC_ERROR) {
+av_log(avctx, AV_LOG_ERROR, "Unspecified libjxl error occurred\n");
+return AVERROR_EXTERNAL;
+}
+bytes_written = ctx->buffer_size - available;
+/* all data passed has been encoded */
+if (jret == JXL_ENC_SUCCESS)
+break;
+if (jret == JXL_ENC_NEED_MORE_OUTPUT) {

Is it possible for the encoder to return anything other than the three
codes you're handling? Won't you get into an infinite loop if it does?


It's just these three, according to the documentation.
https://libjxl.readthedocs.io/en/latest/api_encoder.html

So the end of the loop should be unreachable, as you always break,
continue or return before. I would put return AVERROR_EXTERNAL there
just in case.

Beyond that I have no more comments on the set.

I suppose a failsafe in case of a bug or futureproofing wouldn't be a 
bad call. I can add one.


- Leo Izen (thebombzen)

___
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 v14 2/4] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-04-15 Thread Leo Izen

On 4/15/22 07:08, Andreas Rheinhardt wrote:

Leo Izen:


+return avpkt->size - remaining;

If this decoder is supposed to produce multiple frames from one packet
of input, it needs to use the receive_frame-callback. For video
decoders, it is only checked whether the return value is >= 0 or not
(see lines 451-456 in decode.c).
It isn't, because I've chosen not to support animated JXL at this time. 
As far as I'm aware an animated JXL file will just decode to its first 
frame with this decoder.

+case JXL_DEC_SUCCESS:
+av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");
+/*
+ * The file has finished decoding
+ * reset the decoder to let us
+ * reuse it again for the next image
+ */
+JxlDecoderReset(ctx->decoder);
+libjxl_init_jxl_decoder(avctx);

You are only resetting the decoder on success. What happens if any of
the errors happened? Would the decoder need to be reset before decoding
the next picture?
This was already brought up by Anton. The JXL_DEC_SUCCESS event isn't 
fired until the start of the next packet (if there is one). It is the 
"finished decoding" event which we never actually get to for single 
images because JXL_DEC_FULL_IMAGE is always fired first. If this is 
fired it means we're in an image2 sequence and this is the next frame, 
at which point the data will have been swapped out. Resetting the 
decoder is necessary here to make the library re-read the header info 
and not whine. I agree that it's a bit confusing and I should probably 
add a block comment explaining this.

+buf = avpkt->data;
+remaining = avpkt->size;
+continue;

Didn't you already feed this data to the decoder? This somehow looks
like a recipe for an infinite loop.

No, see up.

- Leo Izen (thebombzen)


___
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/alimiter: Add "flush_buffer" option to flush the remaining valid data to the output

2022-04-15 Thread Wang Cao
On Tue, Apr 12, 2022 at 12:40 PM Paul B Mahol  wrote:

> On Mon, Apr 11, 2022 at 10:59 PM Wang Cao <
> wangcao-at-google@ffmpeg.org>
> wrote:
>
> > On Sat, Apr 9, 2022 at 5:35 AM Paul B Mahol  wrote:
> >
> > > On Fri, Apr 8, 2022 at 10:41 PM Wang Cao <
> > wangcao-at-google@ffmpeg.org
> > > >
> > > wrote:
> > >
> > > > On Fri, Apr 8, 2022 at 11:40 AM Paul B Mahol 
> wrote:
> > > >
> > > > > On Thu, Apr 7, 2022 at 11:56 PM Wang Cao <
> > > > wangcao-at-google@ffmpeg.org
> > > > > >
> > > > > wrote:
> > > > >
> > > > > > On Thu, Apr 7, 2022 at 12:44 AM Paul B Mahol 
> > > wrote:
> > > > > >
> > > > > > > On Wed, Apr 6, 2022 at 1:49 PM Paul B Mahol 
> > > > wrote:
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > On Tue, Apr 5, 2022 at 8:57 PM Wang Cao <
> > > > > > > wangcao-at-google@ffmpeg.org>
> > > > > > > > wrote:
> > > > > > > >
> > > > > > > >> On Mon, Apr 4, 2022 at 3:28 PM Marton Balint  >
> > > > wrote:
> > > > > > > >>
> > > > > > > >> >
> > > > > > > >> >
> > > > > > > >> > On Mon, 4 Apr 2022, Paul B Mahol wrote:
> > > > > > > >> >
> > > > > > > >> > > On Sun, Mar 27, 2022 at 11:41 PM Marton Balint <
> > > c...@passwd.hu
> > > > >
> > > > > > > wrote:
> > > > > > > >> > >
> > > > > > > >> > >>
> > > > > > > >> > >>
> > > > > > > >> > >> On Sat, 26 Mar 2022, Wang Cao wrote:
> > > > > > > >> > >>
> > > > > > > >> > >>> The change in the commit will add some samples to the
> > end
> > > of
> > > > > the
> > > > > > > >> audio
> > > > > > > >> > >>> stream. The intention is to add a "zero_delay" option
> > > > > eventually
> > > > > > > to
> > > > > > > >> not
> > > > > > > >> > >>> have the delay in the begining the output from
> alimiter
> > > due
> > > > to
> > > > > > > >> > >>> lookahead.
> > > > > > > >> > >>
> > > > > > > >> > >> I was very much suprised to see that the alimiter
> filter
> > > > > actually
> > > > > > > >> delays
> > > > > > > >> > >> the audio - as in extra samples are inserted in the
> > > beginning
> > > > > and
> > > > > > > >> some
> > > > > > > >> > >> samples are cut in the end. This trashes A-V sync, so
> it
> > > is a
> > > > > bug
> > > > > > > >> IMHO.
> > > > > > > >> > >>
> > > > > > > >> > >> So unless somebody has some valid usecase for the
> legacy
> > > way
> > > > of
> > > > > > > >> > operation
> > > > > > > >> > >> I'd just simply change it to be "zero delay" without
> any
> > > > > > additional
> > > > > > > >> user
> > > > > > > >> > >> option, in a single patch.
> > > > > > > >> > >>
> > > > > > > >> > >
> > > > > > > >> > >
> > > > > > > >> > > This is done by this patch in very complicated way and
> > also
> > > it
> > > > > > > really
> > > > > > > >> > > should be optional.
> > > > > > > >> >
> > > > > > > >> > But why does it make sense to keep the current (IMHO
> buggy)
> > > > > > > operational
> > > > > > > >> > mode which adds silence in the beginning and trims the
> end?
> > I
> > > > > > > understand
> > > > > > > >> > that the original implementation worked like this, but
> > > > libavfilter
> > > > > > has
> > > > > > > >> > packet timestamps and N:M filtering so there is absolutely
> > no
> > > > > reason
> > > > > > > to
> > > > > > > >> > use an 1:1 implementation and live with its limitations.
> > > > > > > >> >
> > > > > > > >> Hello Paul and Marton, thank you so much for taking time to
> > > review
> > > > > my
> > > > > > > >> patch.
> > > > > > > >> I totally understand that my patch may seem a little bit
> > > > complicated
> > > > > > > but I
> > > > > > > >> can
> > > > > > > >> show with a FATE test that if we set the alimiter to behave
> > as a
> > > > > > > >> passthrough filter,
> > > > > > > >> the output frames will be the same from "framecrc" with my
> > > patch.
> > > > > The
> > > > > > > >> existing
> > > > > > > >> behavior will not work for all gapless audio processing.
> > > > > > > >>
> > > > > > > >> The complete patch to fix this issue is at
> > > > > > > >>
> > > > > > > >>
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220330210314.2055201-1-wang...@google.com/
> > > > > > > >>
> > > > > > > >> Regarding Paul's concern, I personally don't have any
> > preference
> > > > > > whether
> > > > > > > >> to
> > > > > > > >> put
> > > > > > > >> the patch as an extra option or not. With respect to the
> > > > > > implementation,
> > > > > > > >> the patch
> > > > > > > >> is the best I can think of by preserving as much information
> > as
> > > > > > possible
> > > > > > > >> from input
> > > > > > > >> frames. I also understand it may break concept that
> > > "filter_frame"
> > > > > > > outputs
> > > > > > > >> one frame
> > > > > > > >> at a time. For alimiter with my patch, depending on the size
> > of
> > > > the
> > > > > > > >> lookahead buffer,
> > > > > > > >> it may take a few frames before one output frame can be
> > > generated.
> > > > > > This
> > > > > > > is
> > > > > > > >> inevitable
> > > > > > > >> to compensate 

[FFmpeg-devel] [PATCH] avfilter/alimiter: Add an option "comp_delay" that removes the delay introduced by lookahead buffer

2022-04-15 Thread Wang Cao
1. The option also flushes all the valid audio samples in the lookahead
   buffer so the audio integrity is preserved. Previously the the output
   audio will lose the amount of audio samples equal to the size of
   lookahead buffer
2. Add a FATE test to verify that when the filter is working as
   passthrough filter, all audio samples are properly handled from the
   input to the output.

Signed-off-by: Wang Cao 
---
 doc/filters.texi|  5 +++
 libavfilter/af_alimiter.c   | 74 +
 tests/fate/filter-audio.mak | 12 ++
 3 files changed, 91 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index a161754233..2af0953c89 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1978,6 +1978,11 @@ in release time while 1 produces higher release times.
 @item level
 Auto level output signal. Default is enabled.
 This normalizes audio back to 0dB if enabled.
+
+@item comp_delay
+Compensate the delay introduced by using the lookahead buffer set with attack
+parameter. Also flush the valid audio data in the lookahead buffer when the 
+stream hits EOF.
 @end table
 
 Depending on picked setting it is recommended to upsample input 2x or 4x times
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 133f98f165..d10a90859b 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -55,6 +55,12 @@ typedef struct AudioLimiterContext {
 int *nextpos;
 double *nextdelta;
 
+int lookahead_delay_samples;
+int lookahead_flush_samples;
+int64_t output_pts;
+int64_t next_output_pts;
+int comp_delay;
+
 double delta;
 int nextiter;
 int nextlen;
@@ -73,6 +79,7 @@ static const AVOption alimiter_options[] = {
 { "asc",   "enable asc",   OFFSET(auto_release), AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { "asc_level", "set asc level",OFFSET(asc_coeff),
AV_OPT_TYPE_DOUBLE, {.dbl=0.5},0,1, AF },
 { "level", "auto level",   OFFSET(auto_level),   AV_OPT_TYPE_BOOL, 
  {.i64=1},  0,1, AF },
+{ "comp_delay","compensate delay", OFFSET(comp_delay),   AV_OPT_TYPE_BOOL, 
  {.i64=0},  0,1, AF },
 { NULL }
 };
 
@@ -129,6 +136,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 AVFrame *out;
 double *buf;
 int n, c, i;
+int num_output_samples = in->nb_samples;
+int trim_offset;
 
 if (av_frame_is_writable(in)) {
 out = in;
@@ -271,10 +280,71 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
 if (in != out)
 av_frame_free();
+
+if (!s->comp_delay) {
+return ff_filter_frame(outlink, out);
+}
+
+if (s->output_pts == AV_NOPTS_VALUE) {
+s->output_pts = in->pts;
+}
+
+if (s->lookahead_delay_samples > 0) {
+// The current output frame is completely silence
+if (s->lookahead_delay_samples >= in->nb_samples) {
+s->lookahead_delay_samples -= in->nb_samples;
+return 0;
+}
+
+// Trim the silence part
+trim_offset = av_samples_get_buffer_size(
+NULL, inlink->ch_layout.nb_channels, s->lookahead_delay_samples,
+(enum AVSampleFormat)out->format, 1);
+out->data[0] += trim_offset;
+out->nb_samples = in->nb_samples - s->lookahead_delay_samples;
+s->lookahead_delay_samples = 0;
+num_output_samples = out->nb_samples;
+}
+
+if (s->lookahead_delay_samples < 0) {
+return AVERROR_BUG;
+}
+
+out->pts = s->output_pts;
+s->next_output_pts = s->output_pts + num_output_samples;
+s->output_pts = s->next_output_pts;

 return ff_filter_frame(outlink, out);
 }

+static int request_frame(AVFilterLink* outlink)
+{
+AVFilterContext *ctx = outlink->src;
+AudioLimiterContext *s = (AudioLimiterContext*)ctx->priv;
+int ret;
+AVFilterLink *inlink;
+AVFrame *silence_frame;
+
+ret = ff_request_frame(ctx->inputs[0]);
+
+if (ret != AVERROR_EOF || s->lookahead_flush_samples == 0 || 
!s->comp_delay) {
+  // Not necessarily an error, just not EOF.
+  return ret;
+}
+
+// We reach here when input filters have finished producing data (i.e. 
EOF),
+// but because of the attack param, s->buffer still has meaningful
+// audio content that needs flushing.
+inlink = ctx->inputs[0];
+// Pushes silence frame to flush valid audio in the s->buffer
+silence_frame = ff_get_audio_buffer(inlink, s->lookahead_flush_samples);
+ret = filter_frame(inlink, silence_frame);
+if (ret < 0) {
+  return ret;
+}
+return AVERROR_EOF;
+}
+
 static int config_input(AVFilterLink *inlink)
 {
 AVFilterContext *ctx = inlink->dst;
@@ -294,6 +364,9 @@ static int config_input(AVFilterLink *inlink)
 memset(s->nextpos, -1, obuffer_size * sizeof(*s->nextpos));
 s->buffer_size = inlink->sample_rate * s->attack * 
inlink->ch_layout.nb_channels;
 s->buffer_size -= 

Re: [FFmpeg-devel] Request For Comment no Matroska specs

2022-04-15 Thread Martijn van Beurden
As a gentle reminder, the Matroska specification can be commented on
until the 22th of this month, so for another 7 days, before it is
finalized and submitted to the IETF to start their review process. See
the message below for details

> Op vr 1 apr. 2022 14:53 schreef Steve Lhomme :
>>
>> On 2022-04-01 14:33, Steve Lhomme wrote:
>> > Hi ffmmpeg developers,
>> >
>> > As you may know, we are working hard on the Matroska specifications at
>> > the IETF. We already got EBML as an RFC [1]. We are in the process of
>> > finalizing the main Matroska document. Before we submit the document for
>> > formal review before "final" publishing, we would like people who know a
>> > bit about Matroska to review the current draft in case there are parts
>> > missing, hard to decipher or, even worse, bugs.
>> >
>> > This is a 200 pages document, so it may take a while. You can find draft
>> > 09 at [2]. It should explain what is found in Matroska 1 to 4. Some
>> > unused elements have been deprecated since the original informal
>> > specifications. These elements can be found in Annex A.
>>
>> I forgot to mention you can reply here or on the GitHub repository of
>> the specs [3] by creating an issue or even a Pull Request.
>>
>> [3] https://github.com/ietf-wg-cellar/matroska-specification
>>
>> > Thanks
>> >
>> > [1] https://datatracker.ietf.org/doc/rfc8794/
>> > [2] https://datatracker.ietf.org/doc/draft-ietf-cellar-matroska/

Op za 2 apr. 2022 om 11:27 schreef Martijn van Beurden :
>
>
> There is also a HTML version of the draft available, which is perhaps easier 
> to read:
> https://www.ietf.org/archive/id/draft-ietf-cellar-matroska-09.html
>
___
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 1/1] lavc/aarch64: add some neon pix_abs functions

2022-04-15 Thread Michael Niedermayer
On Thu, Apr 14, 2022 at 04:22:58PM +, Swinney, Jonathan wrote:
>  - ff_pix_abs16_neon
>  - ff_pix_abs16_xy2_neon
> 
> In direct micro benchmarks of these ff functions verses their C 
> implementations,
> these functions performed as follows on AWS Graviton 2:
> 
> ff_pix_abs16_neon:
> c:  benchmark ran 10 iterations in 0.955383 seconds
> ff: benchmark ran 10 iterations in 0.097669 seconds
> 
> ff_pix_abs16_xy2_neon:
> c:  benchmark ran 10 iterations in 1.916759 seconds
> ff: benchmark ran 10 iterations in 0.370729 seconds
> 
> Signed-off-by: Jonathan Swinney 
> ---
>  libavcodec/aarch64/Makefile  |   2 +
>  libavcodec/aarch64/me_cmp_init_aarch64.c |  39 +
>  libavcodec/aarch64/me_cmp_neon.S | 209 +++
>  libavcodec/me_cmp.c  |   2 +
>  libavcodec/me_cmp.h  |   1 +
>  libavcodec/x86/me_cmp.asm|   7 +
>  libavcodec/x86/me_cmp_init.c |   3 +
>  tests/checkasm/Makefile  |   2 +-
>  tests/checkasm/checkasm.c|   1 +
>  tests/checkasm/checkasm.h|   1 +
>  tests/checkasm/motion.c  | 155 +
>  11 files changed, 421 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/aarch64/me_cmp_init_aarch64.c
>  create mode 100644 libavcodec/aarch64/me_cmp_neon.S
>  create mode 100644 tests/checkasm/motion.c
> 
[...]
> diff --git a/libavcodec/x86/me_cmp.asm b/libavcodec/x86/me_cmp.asm
> index ad06d485ab..f73b9f9161 100644
> --- a/libavcodec/x86/me_cmp.asm
> +++ b/libavcodec/x86/me_cmp.asm
> @@ -255,6 +255,7 @@ hadamard8x8_diff %+ SUFFIX:
>  
>  HSUM m0, m1, eax
>  and rax, 0x
> +emms
>  ret
>  
>  hadamard8_16_wrapper 0, 14
> @@ -345,6 +346,7 @@ cglobal sse%1, 5,5,8, v, pix1, pix2, lsize, h
>  
>  HADDD m7, m1
>  movd eax, m7 ; return value
> +emms
>  RET
>  %endmacro

on which arm chip did you test this ?


[...]
> diff --git a/libavcodec/x86/me_cmp_init.c b/libavcodec/x86/me_cmp_init.c
> index 9af911bb88..b330868a38 100644
> --- a/libavcodec/x86/me_cmp_init.c
> +++ b/libavcodec/x86/me_cmp_init.c
> @@ -186,6 +186,8 @@ static int vsad_intra16_mmx(MpegEncContext *v, uint8_t 
> *pix, uint8_t *dummy,
>  : "r" (stride), "m" (h)
>  : "%ecx");
>  
> +emms_c();
> +
>  return tmp & 0x;
>  }
>  #undef SUM
> @@ -418,6 +420,7 @@ static inline int sum_mmx(void)
>  "paddw %%mm0, %%mm6 \n\t"
>  "movd %%mm6, %0 \n\t"
>  : "=r" (ret));
> +emms_c();
>  return ret & 0x;
>  }

hmmm

Also before the patch 
checkasm: all 6153 tests passed
after it
checkasm: all 3198 tests passed

thats on a x86-64

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


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 1/1] librtmp: use AVBPrint instead of char *

2022-04-15 Thread Tristan Matthews
This avoids having to do one pass to calculate the full length to allocate
followed by a second pass to actually append values.
---
 libavformat/librtmp.c | 124 +++---
 1 file changed, 33 insertions(+), 91 deletions(-)

diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
index 43013e46e0..b7e9fc81cf 100644
--- a/libavformat/librtmp.c
+++ b/libavformat/librtmp.c
@@ -25,6 +25,7 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/bprint.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "avformat.h"
@@ -38,6 +39,7 @@
 
 typedef struct LibRTMPContext {
 const AVClass *class;
+AVBPrint filename;
 RTMP rtmp;
 char *app;
 char *conn;
@@ -50,7 +52,6 @@ typedef struct LibRTMPContext {
 char *pageurl;
 char *client_buffer_time;
 int live;
-char *temp_filename;
 int buffer_size;
 } LibRTMPContext;
 
@@ -76,7 +77,7 @@ static int rtmp_close(URLContext *s)
 RTMP *r = >rtmp;
 
 RTMP_Close(r);
-av_freep(>temp_filename);
+av_bprint_finalize(>filename, NULL);
 return 0;
 }
 
@@ -97,8 +98,8 @@ static int rtmp_open(URLContext *s, const char *uri, int 
flags)
 LibRTMPContext *ctx = s->priv_data;
 RTMP *r = >rtmp;
 int rc = 0, level;
-char *filename = s->filename;
-int len = strlen(s->filename) + 1;
+/* This needs to stay allocated for as long as the RTMP context exists. */
+av_bprint_init(>filename, 0, AV_BPRINT_SIZE_UNLIMITED);
 
 switch (av_log_get_level()) {
 default:
@@ -112,118 +113,58 @@ static int rtmp_open(URLContext *s, const char *uri, int 
flags)
 RTMP_LogSetLevel(level);
 RTMP_LogSetCallback(rtmp_log);
 
-if (ctx->app)  len += strlen(ctx->app)  + sizeof(" app=");
-if (ctx->tcurl)len += strlen(ctx->tcurl)+ sizeof(" tcUrl=");
-if (ctx->pageurl)  len += strlen(ctx->pageurl)  + sizeof(" pageUrl=");
-if (ctx->flashver) len += strlen(ctx->flashver) + sizeof(" flashver=");
-
+av_bprintf(>filename, "%s", s->filename);
+if (ctx->app)
+av_bprintf(>filename, " app=%s", ctx->app);
+if (ctx->tcurl)
+av_bprintf(>filename, " tcUrl=%s", ctx->tcurl);
+if (ctx->pageurl)
+av_bprintf(>filename, " pageUrl=%s", ctx->pageurl);
+if (ctx->swfurl)
+av_bprintf(>filename, " swfUrl=%s", ctx->swfurl);
+if (ctx->flashver)
+av_bprintf(>filename, " flashVer=%s", ctx->flashver);
 if (ctx->conn) {
 char *sep, *p = ctx->conn;
-int options = 0;
-
 while (p) {
-options++;
+av_bprintf(>filename,  " conn=");
 p += strspn(p, " ");
 if (!*p)
 break;
 sep = strchr(p, ' ');
+if (sep)
+*sep = '\0';
+av_bprintf(>filename, "%s", p);
+
 if (sep)
 p = sep + 1;
 else
 break;
 }
-len += options * sizeof(" conn=");
-len += strlen(ctx->conn);
 }
-
 if (ctx->playpath)
-len += strlen(ctx->playpath) + sizeof(" playpath=");
+av_bprintf(>filename, " playpath=%s", ctx->playpath);
 if (ctx->live)
-len += sizeof(" live=1");
+av_bprintf(>filename, " live=1");
 if (ctx->subscribe)
-len += strlen(ctx->subscribe) + sizeof(" subscribe=");
-
+av_bprintf(>filename, " subscribe=%s", ctx->subscribe);
 if (ctx->client_buffer_time)
-len += strlen(ctx->client_buffer_time) + sizeof(" buffer=");
-
+av_bprintf(>filename, " buffer=%s", ctx->client_buffer_time);
 if (ctx->swfurl || ctx->swfverify) {
-len += sizeof(" swfUrl=");
-
 if (ctx->swfverify)
-len += strlen(ctx->swfverify) + sizeof(" swfVfy=1");
+av_bprintf(>filename, " swfUrl=%s swfVfy=1", ctx->swfverify);
 else
-len += strlen(ctx->swfurl);
+av_bprintf(>filename, " swfUrl=%s", ctx->swfurl);
 }
 
-if (!(ctx->temp_filename = filename = av_malloc(len)))
+if (!av_bprint_is_complete(>filename)) {
+av_bprint_finalize(>filename, NULL);
 return AVERROR(ENOMEM);
-
-av_strlcpy(filename, s->filename, len);
-if (ctx->app) {
-av_strlcat(filename, " app=", len);
-av_strlcat(filename, ctx->app, len);
-}
-if (ctx->tcurl) {
-av_strlcat(filename, " tcUrl=", len);
-av_strlcat(filename, ctx->tcurl, len);
-}
-if (ctx->pageurl) {
-av_strlcat(filename, " pageUrl=", len);
-av_strlcat(filename, ctx->pageurl, len);
-}
-if (ctx->swfurl) {
-av_strlcat(filename, " swfUrl=", len);
-av_strlcat(filename, ctx->swfurl, len);
-}
-if (ctx->flashver) {
-av_strlcat(filename, " flashVer=", len);
-av_strlcat(filename, ctx->flashver, len);
-}
-if (ctx->conn) {
-char *sep, *p = ctx->conn;
-while (p) {
-av_strlcat(filename, " conn=", len);
-  

Re: [FFmpeg-devel] [PATCH 1/1] librtmp: use AVBPrint instead of char *

2022-04-15 Thread Tristan Matthews
On Wed, Apr 13, 2022 at 3:40 PM Marton Balint  wrote:

>
>
> On Wed, 13 Apr 2022, Martin Storsjö wrote:
>
> > On Mon, 11 Apr 2022, Tristan Matthews wrote:
> >
> >>  This avoids having to do one pass to calculate the full length to
> allocate
> >>  followed by a second pass to actually append values.
> >>  ---
> >>  libavformat/librtmp.c | 123 +++---
> >>  1 file changed, 32 insertions(+), 91 deletions(-)
> >
> > Thanks, this patch looks good to me. I'll wait for a little while still
> if
> > Marton wants to comment on it, before I go ahead and push it.
>
> According to commit 865461099e062de5a3a109c2a5be98004c11d8bd the buffer
> passed to RTMP_SetupURL has to be kept as long as the RTMP context is
> alive.
>
>
Oh good catch, I should've dug deeper as to why ctx->temp_filename existed.

Best,
Tristan



> Regards,
> Marton
> ___
> 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 v14 4/4] avformat/image2: add Jpeg XL as image2 format

2022-04-15 Thread Andreas Rheinhardt
Leo Izen:
> This commit adds support to libavformat for muxing
> and demuxing Jpeg XL images as image2 streams.
> ---
>  MAINTAINERS|   1 +
>  libavformat/Makefile   |   1 +
>  libavformat/allformats.c   |   1 +
>  libavformat/img2.c |   1 +
>  libavformat/img2dec.c  |  18 ++
>  libavformat/img2enc.c  |   6 +-
>  libavformat/jpegxl_probe.c | 393 +
>  libavformat/jpegxl_probe.h |  32 +++
>  libavformat/mov.c  |   1 +
>  9 files changed, 451 insertions(+), 3 deletions(-)
>  create mode 100644 libavformat/jpegxl_probe.c
>  create mode 100644 libavformat/jpegxl_probe.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index faea84ebf1..46723972dc 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -439,6 +439,7 @@ Muxers/Demuxers:
>ipmovie.c Mike Melanson
>ircam*Paul B Mahol
>iss.c Stefan Gehrer
> +  jpegxl_probe.*Leo Izen
>jvdec.c   Peter Ross
>kvag.cZane van Iperen
>libmodplug.c  Clément Bœsch
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index d7182d6bd8..beecdf5a66 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -272,6 +272,7 @@ OBJS-$(CONFIG_IMAGE_GIF_PIPE_DEMUXER) += img2dec.o 
> img2.o
>  OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER)+= img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER)  += img2dec.o img2.o
> +OBJS-$(CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER)  += img2dec.o img2.o jpegxl_probe.o
>  OBJS-$(CONFIG_IMAGE_PAM_PIPE_DEMUXER) += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_PBM_PIPE_DEMUXER) += img2dec.o img2.o
>  OBJS-$(CONFIG_IMAGE_PCX_PIPE_DEMUXER) += img2dec.o img2.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 7c1d0ac38f..63876c468f 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 fe2ca7bfff..566ef873ca 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -88,6 +88,7 @@ const IdStrMap ff_img_tags[] = {
>  { AV_CODEC_ID_GEM,"ximg" },
>  { AV_CODEC_ID_GEM,"timg" },
>  { AV_CODEC_ID_VBN,"vbn"  },
> +{ AV_CODEC_ID_JPEGXL, "jxl"  },
>  { AV_CODEC_ID_NONE,   NULL   }
>  };
>  
> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> index 551b9d508e..627bb67212 100644
> --- a/libavformat/img2dec.c
> +++ b/libavformat/img2dec.c
> @@ -36,6 +36,7 @@
>  #include "avio_internal.h"
>  #include "internal.h"
>  #include "img2.h"
> +#include "jpegxl_probe.h"
>  #include "libavcodec/mjpeg.h"
>  #include "libavcodec/vbn.h"
>  #include "libavcodec/xwd.h"
> @@ -837,6 +838,22 @@ 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;
> +/* Raw codestreams all start with 0xff0a */
> +if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
> +return 0;
> +if (ff_jpegxl_verify_codestream_header(p->buf, p->buf_size) >= 0)

This will give a linking failure if the image_jpegxl_pipe_demuxer is
disabled.

> +return AVPROBE_SCORE_MAX - 2;
> +return 0;
> +}
> +
>  static int pcx_probe(const AVProbeData *p)
>  {
>  const uint8_t *b = p->buf;
> @@ -1176,6 +1193,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 ae351963d9..5ed97bb833 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 = 
> 

Re: [FFmpeg-devel] [PATCH v14 2/4] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-04-15 Thread Andreas Rheinhardt
Leo Izen:
> 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| 274 ++
>  8 files changed, 407 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 859a5005d4..faea84ebf1 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -194,6 +194,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 9c8965852b..c36d5dbc8b 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
> @@ -3331,6 +,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"
> @@ -6543,6 +6546,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 238568f2bb..93a90a5e52 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 90f46035d9..8fc3b3cc5f 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1061,6 +1061,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 585918da93..07f5bafd27 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -751,6 +751,7 @@ extern const FFCodec ff_libgsm_ms_encoder;
>  extern 

Re: [FFmpeg-devel] [PATCH v14 3/4] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-04-15 Thread Anton Khirnov
Quoting Leo Izen (2022-04-15 03:37:20)
> 
> On 4/14/22 13:49, Anton Khirnov wrote:
> > Quoting Leo Izen (2022-04-12 07:53:32)
> >> +
> >> +while (1) {
> >> +jret = JxlEncoderProcessOutput(ctx->encoder, _out, 
> >> );
> >> +if (jret == JXL_ENC_ERROR) {
> >> +av_log(avctx, AV_LOG_ERROR, "Unspecified libjxl error 
> >> occurred\n");
> >> +return AVERROR_EXTERNAL;
> >> +}
> >> +bytes_written = ctx->buffer_size - available;
> >> +/* all data passed has been encoded */
> >> +if (jret == JXL_ENC_SUCCESS)
> >> +break;
> >> +if (jret == JXL_ENC_NEED_MORE_OUTPUT) {
> > Is it possible for the encoder to return anything other than the three
> > codes you're handling? Won't you get into an infinite loop if it does?
> >
> It's just these three, according to the documentation. 
> https://libjxl.readthedocs.io/en/latest/api_encoder.html

So the end of the loop should be unreachable, as you always break,
continue or return before. I would put return AVERROR_EXTERNAL there
just in case.

Beyond that I have no more comments on the set.

-- 
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] avformat/nut: add float pixel formats support

2022-04-15 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 libavcodec/raw.c |  9 +
 libavformat/nut.c|  9 +
 tests/ref/fate/filter-pixdesc-gbrapf32be |  2 +-
 tests/ref/fate/filter-pixdesc-gbrapf32le |  2 +-
 tests/ref/fate/filter-pixdesc-gbrpf32be  |  2 +-
 tests/ref/fate/filter-pixdesc-gbrpf32le  |  2 +-
 tests/ref/fate/filter-pixdesc-grayf32be  |  2 +-
 tests/ref/fate/filter-pixdesc-grayf32le  |  2 +-
 tests/ref/fate/filter-pixfmts-copy   | 12 ++--
 tests/ref/fate/filter-pixfmts-crop   | 12 ++--
 tests/ref/fate/filter-pixfmts-field  | 12 ++--
 tests/ref/fate/filter-pixfmts-fieldorder | 12 ++--
 tests/ref/fate/filter-pixfmts-hflip  | 12 ++--
 tests/ref/fate/filter-pixfmts-il | 12 ++--
 tests/ref/fate/filter-pixfmts-null   | 12 ++--
 tests/ref/fate/filter-pixfmts-scale  | 12 ++--
 tests/ref/fate/filter-pixfmts-transpose  | 12 ++--
 tests/ref/fate/filter-pixfmts-vflip  | 12 ++--
 18 files changed, 84 insertions(+), 66 deletions(-)

diff --git a/libavcodec/raw.c b/libavcodec/raw.c
index a371bb36c4..2f23e8632d 100644
--- a/libavcodec/raw.c
+++ b/libavcodec/raw.c
@@ -165,6 +165,9 @@ static const PixelFormatTag raw_pix_fmt_tags[] = {
 { AV_PIX_FMT_YA8, MKTAG('Y', '2',  0 ,  8 ) },
 { AV_PIX_FMT_PAL8,MKTAG('P', 'A', 'L',  8 ) },
 
+{ AV_PIX_FMT_GRAYF32LE,MKTAG('Y', '1',  0 , 32 ) },
+{ AV_PIX_FMT_GRAYF32BE,MKTAG(32 ,  0 , '1', 'Y') },
+
 { AV_PIX_FMT_YUVA420P9LE,  MKTAG('Y', '4', 11 ,  9 ) },
 { AV_PIX_FMT_YUVA420P9BE,  MKTAG( 9 , 11 , '4', 'Y') },
 { AV_PIX_FMT_YUVA422P9LE,  MKTAG('Y', '4', 10 ,  9 ) },
@@ -200,6 +203,9 @@ static const PixelFormatTag raw_pix_fmt_tags[] = {
 { AV_PIX_FMT_GBRP16LE, MKTAG('G', '3', 00 , 16 ) },
 { AV_PIX_FMT_GBRP16BE, MKTAG(16 , 00 , '3', 'G') },
 
+{ AV_PIX_FMT_GBRPF32LE,MKTAG('G', '3', 00 , 32 ) },
+{ AV_PIX_FMT_GBRPF32BE,MKTAG(32 , 00 , '3', 'G') },
+
 { AV_PIX_FMT_GBRAP,MKTAG('G', '4', 00 ,  8 ) },
 { AV_PIX_FMT_GBRAP10LE,MKTAG('G', '4', 00 , 10 ) },
 { AV_PIX_FMT_GBRAP10BE,MKTAG(10 , 00 , '4', 'G') },
@@ -208,6 +214,9 @@ static const PixelFormatTag raw_pix_fmt_tags[] = {
 { AV_PIX_FMT_GBRAP16LE,MKTAG('G', '4', 00 , 16 ) },
 { AV_PIX_FMT_GBRAP16BE,MKTAG(16 , 00 , '4', 'G') },
 
+{ AV_PIX_FMT_GBRAPF32LE,   MKTAG('G', '4', 00 , 32 ) },
+{ AV_PIX_FMT_GBRAPF32BE,   MKTAG(32 , 00 , '4', 'G') },
+
 { AV_PIX_FMT_XYZ12LE,  MKTAG('X', 'Y', 'Z' , 36 ) },
 { AV_PIX_FMT_XYZ12BE,  MKTAG(36 , 'Z' , 'Y', 'X') },
 
diff --git a/libavformat/nut.c b/libavformat/nut.c
index 47ed152529..81093eb95b 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -165,6 +165,9 @@ const AVCodecTag ff_nut_video_tags[] = {
 { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1',   0,  14) },
 { AV_CODEC_ID_RAWVIDEO, MKTAG(14,0, '1', 'Y') },
 
+{ AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1',   0,  32) },
+{ AV_CODEC_ID_RAWVIDEO, MKTAG(32,0, '1', 'Y') },
+
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '3',   0,   8) },
 
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '3',   0,   9) },
@@ -178,6 +181,9 @@ const AVCodecTag ff_nut_video_tags[] = {
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '3',   0,  16) },
 { AV_CODEC_ID_RAWVIDEO, MKTAG(16,0, '3', 'G') },
 
+{ AV_CODEC_ID_RAWVIDEO, MKTAG('G', '3',   0,  32) },
+{ AV_CODEC_ID_RAWVIDEO, MKTAG(32,0, '3', 'G') },
+
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '4',   0,   8) },
 
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '4', 00 , 10 ) },
@@ -187,6 +193,9 @@ const AVCodecTag ff_nut_video_tags[] = {
 { AV_CODEC_ID_RAWVIDEO, MKTAG('G', '4', 00 , 16 ) },
 { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 00 , '4', 'G') },
 
+{ AV_CODEC_ID_RAWVIDEO, MKTAG('G', '4', 00 , 32 ) },
+{ AV_CODEC_ID_RAWVIDEO, MKTAG(32 , 00 , '4', 'G') },
+
 { AV_CODEC_ID_RAWVIDEO, MKTAG('X', 'Y', 'Z' , 36 ) },
 { AV_CODEC_ID_RAWVIDEO, MKTAG(36 , 'Z' , 'Y', 'X') },
 
diff --git a/tests/ref/fate/filter-pixdesc-gbrapf32be 
b/tests/ref/fate/filter-pixdesc-gbrapf32be
index 97d613ad09..0fa9475429 100644
--- a/tests/ref/fate/filter-pixdesc-gbrapf32be
+++ b/tests/ref/fate/filter-pixdesc-gbrapf32be
@@ -1 +1 @@
-pixdesc-gbrapf32be  a4fd00f17d746849f30597c496923107
+pixdesc-gbrapf32be  7df9917c31de0b14f516d20924a4907f
diff --git a/tests/ref/fate/filter-pixdesc-gbrapf32le 
b/tests/ref/fate/filter-pixdesc-gbrapf32le
index ef59306625..5964eaa8f1 100644
--- a/tests/ref/fate/filter-pixdesc-gbrapf32le
+++ b/tests/ref/fate/filter-pixdesc-gbrapf32le
@@ -1 +1 @@
-pixdesc-gbrapf32le  26af38a6975e2ce425e9fec477e6b2ba
+pixdesc-gbrapf32le  d8cd68b8902ab45c5894c4d43c457ed0
diff --git a/tests/ref/fate/filter-pixdesc-gbrpf32be 
b/tests/ref/fate/filter-pixdesc-gbrpf32be

Re: [FFmpeg-devel] [PATCH v8 5/6] fftools: Enable long path support on Windows (fixes #8885)

2022-04-15 Thread nil-admirari
No longer applies. New version are at: 
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-April/295391.html

From: Nil Admirari 
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v8 5/6] fftools: Enable long path support on 
Windows (fixes #8885)
Date: 28/03/2022 22:43:38 Europe/Moscow

---
fftools/Makefile | 5 +
fftools/fftools.manifest | 10 ++
fftools/manifest.rc | 3 +++
3 files changed, 18 insertions(+)
create mode 100644 fftools/fftools.manifest
create mode 100644 fftools/manifest.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index 5ebf50d..213f3f0 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -11,6 +11,11 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))

OBJS-ffmpeg += fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o

+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+
define DOFFTOOL
OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
$(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
new file mode 100644
index 000..30b7d8f
--- /dev/null
+++ b/fftools/fftools.manifest
@@ -0,0 +1,10 @@
+
+
+
+ 
+ 
+ http://schemas.microsoft.com/SMI/2016/WindowsSettings;>
+ true
+ 
+ 
+
diff --git a/fftools/manifest.rc b/fftools/manifest.rc
new file mode 100644
index 000..e436fa7
--- /dev/null
+++ b/fftools/manifest.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fftools.manifest"
-- 
2.32.0



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


[FFmpeg-devel] [PATCH v9 6/6] fftools: Use UTF-8 on Windows

2022-04-15 Thread Nil Admirari
---
 fftools/fftools.manifest | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
index 30b7d8fe..d1ac1e4e 100644
--- a/fftools/fftools.manifest
+++ b/fftools/fftools.manifest
@@ -3,8 +3,10 @@
 
   
   
-http://schemas.microsoft.com/SMI/2016/WindowsSettings;>
+http://schemas.microsoft.com/SMI/2016/WindowsSettings;
+ 
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings;>
   true
+  UTF-8
 
   
 
-- 
2.32.0



___
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 v9 1/6] libavutil/wchar_filename.h: Add whcartoutf8, wchartoansi and utf8toansi

2022-04-15 Thread Nil Admirari
These functions are going to be used in libavformat/avisynth.c
and fftools/cmdutils.c remove MAX_PATH limit.
---
 libavutil/wchar_filename.h | 51 ++
 1 file changed, 51 insertions(+)

diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index 90f08245..e22ffa8a 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -40,6 +40,57 @@ static inline int utf8towchar(const char *filename_utf8, 
wchar_t **filename_w)
 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
 return 0;
 }
+
+av_warn_unused_result
+static inline int wchartocp(const unsigned int code_page, const wchar_t 
*filename_w,
+char **filename)
+{
+const DWORD flags = code_page == CP_UTF8 ? MB_ERR_INVALID_CHARS : 0;
+const int num_chars = WideCharToMultiByte(code_page, flags, filename_w, -1,
+  NULL, 0, NULL, NULL);
+if (num_chars <= 0) {
+*filename = NULL;
+return 0;
+}
+*filename = av_calloc(num_chars, sizeof(char));
+if (!*filename) {
+errno = ENOMEM;
+return -1;
+}
+WideCharToMultiByte(code_page, flags, filename_w, -1,
+*filename, num_chars, NULL, NULL);
+return 0;
+}
+
+av_warn_unused_result
+static inline int wchartoutf8(const wchar_t *filename_w, char **filename)
+{
+return wchartocp(CP_UTF8, filename_w, filename);
+}
+
+av_warn_unused_result
+static inline int wchartoansi(const wchar_t *filename_w, char **filename)
+{
+return wchartocp(CP_THREAD_ACP, filename_w, filename);
+}
+
+av_warn_unused_result
+static inline int utf8toansi(const char *filename_utf8, char **filename)
+{
+wchar_t *filename_w = NULL;
+int ret = -1;
+if (utf8towchar(filename_utf8, _w))
+return -1;
+
+if (!filename_w) {
+*filename = NULL;
+return 0;
+}
+
+ret = wchartoansi(filename_w, filename);
+av_free(filename_w);
+return ret;
+}
 #endif
 
 #endif /* AVUTIL_WCHAR_FILENAME_H */
-- 
2.32.0



___
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 v9 4/6] fftools/cmdutils.c: Remove MAX_PATH limit and replace fopen with av_fopen_utf8

2022-04-15 Thread Nil Admirari
---
 fftools/cmdutils.c | 38 +-
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 5d7cdc3e..a66dbb22 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -37,6 +37,7 @@
 #include "libswresample/swresample.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
+#include "libavutil/avutil.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/display.h"
 #include "libavutil/mathematics.h"
@@ -50,6 +51,7 @@
 #include "opt_common.h"
 #ifdef _WIN32
 #include 
+#include "compat/w32dlfcn.h"
 #endif
 
 AVDictionary *sws_dict;
@@ -812,28 +814,43 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 {
 FILE *f = NULL;
 int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
 const char *base[3] = { getenv("FFMPEG_DATADIR"),
 getenv("HOME"),
 FFMPEG_DATADIR, };
 
 if (is_path) {
 av_strlcpy(filename, preset_name, filename_size);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
 base[2] = NULL;
 
-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoutf8(datadir_w, ))
+datadir = NULL;
+av_free(datadir_w);
+
+if (datadir)
 {
-for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+char *ls;
+for (ls = datadir; *ls; ls++)
 if (*ls == '\\') *ls = '/';
 
 if (ls = strrchr(datadir, '/'))
 {
-*ls = 0;
-strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - 
strlen(datadir));
-base[2] = datadir;
+const ptrdiff_t datadir_len = ls - datadir;
+const size_t desired_size = datadir_len + strlen("/ffpresets") 
+ 1;
+char *new_datadir = av_realloc_array(
+datadir, desired_size, sizeof *datadir);
+if (new_datadir) {
+datadir = new_datadir;
+datadir[datadir_len] = 0;
+strncat(datadir, "/ffpresets",  desired_size - 1 - 
datadir_len);
+base[2] = datadir;
+}
 }
 }
 #endif
@@ -842,17 +859,20 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 continue;
 snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
  i != 1 ? "" : "/.ffmpeg", preset_name);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 if (!f && codec_name) {
 snprintf(filename, filename_size,
  "%s%s/%s-%s.ffpreset",
  base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
  preset_name);
-f = fopen(filename, "r");
+f = av_fopen_utf8(filename, "r");
 }
 }
 }
 
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+av_free(datadir);
+#endif
 return f;
 }
 
-- 
2.32.0



___
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 v9 3/6] compat/w32dlfcn.h: Remove MAX_PATH limit and replace LoadLibraryExA with LoadLibraryExW

2022-04-15 Thread Nil Admirari
---
 compat/w32dlfcn.h | 78 ++-
 1 file changed, 64 insertions(+), 14 deletions(-)

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index 52a94efa..0f41f50b 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -25,6 +25,30 @@
 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
 #include "libavutil/wchar_filename.h"
 #endif
+
+static inline wchar_t *get_module_filename(const HMODULE module)
+{
+wchar_t *path = NULL, *new_path = NULL;
+DWORD path_size = 0, path_len = 0;
+
+do {
+path_size = path_size ? 2 * path_size : MAX_PATH;
+new_path = av_realloc_array(path, path_size, sizeof *path);
+if (!new_path) {
+av_free(path);
+return NULL;
+}
+path = new_path;
+path_len = GetModuleFileNameW(module, path, path_size);
+} while (path_len && path_size <= 32768 && path_size <= path_len);
+
+if (!path_len) {
+av_free(path);
+return NULL;
+}
+return path;
+}
+
 /**
  * Safe function used to open dynamic libs. This attempts to improve program 
security
  * by removing the current directory from the dll search path. Only dll's 
found in the
@@ -34,29 +58,53 @@
  */
 static inline HMODULE win32_dlopen(const char *name)
 {
+wchar_t *name_w = NULL;
+if (utf8towchar(name, _w))
+name_w = NULL;
 #if _WIN32_WINNT < 0x0602
 // Need to check if KB2533623 is available
 if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), 
"SetDefaultDllDirectories")) {
 HMODULE module = NULL;
-wchar_t *path = NULL, *name_w = NULL;
-DWORD pathlen;
-if (utf8towchar(name, _w))
+wchar_t *path = NULL, *new_path = NULL;
+DWORD pathlen, pathsize, namelen;
+if (!name_w)
 goto exit;
-path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+namelen = wcslen(name_w);
 // Try local directory first
-pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
-pathlen = wcsrchr(path, '\\') - path;
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+path = get_module_filename(NULL);
+if (!path)
 goto exit;
-path[pathlen] = '\\';
+new_path = wcsrchr(path, '\\');
+if (!new_path)
+goto exit;
+pathlen = new_path - path;
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 if (module == NULL) {
 // Next try System32 directory
-pathlen = GetSystemDirectoryW(path, MAX_PATH);
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
 goto exit;
-path[pathlen] = '\\';
+// Buffer is not enough in two cases:
+// 1. system directory + \ + module name
+// 2. system directory even without module name.
+if (pathlen + namelen + 2 > pathsize) {
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
+// Query again to handle case #2.
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
+goto exit;
+}
+path[pathlen] = L'\\';
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 }
@@ -73,15 +121,17 @@ exit:
 #   define LOAD_LIBRARY_SEARCH_SYSTEM320x0800
 #endif
 #if HAVE_WINRT
-wchar_t *name_w = NULL;
 int ret;
-if (utf8towchar(name, _w))
+if (!name_w)
 return NULL;
 ret = LoadPackagedLibrary(name_w, 0);
 av_free(name_w);
 return ret;
 #else
-return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
+/* filename may be be in CP_ACP */
+if (!name_w)
+return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR 
| LOAD_LIBRARY_SEARCH_SYSTEM32);
+return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
 #endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
-- 
2.32.0



___
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 v9 2/6] libavformat/avisynth.c: Remove MAX_PATH limit

2022-04-15 Thread Nil Admirari
---
 libavformat/avisynth.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8ba2bdea..f7bea8c3 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -34,6 +34,7 @@
 /* Platform-specific directives. */
 #ifdef _WIN32
   #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
   #undef EXTERN_C
   #define AVISYNTH_LIB "avisynth"
 #else
@@ -810,8 +811,7 @@ static int avisynth_open_file(AVFormatContext *s)
 AVS_Value arg, val;
 int ret;
 #ifdef _WIN32
-char filename_ansi[MAX_PATH * 4];
-wchar_t filename_wc[MAX_PATH * 4];
+char *filename_ansi = NULL;
 #endif
 
 if (ret = avisynth_context_create(s))
@@ -819,10 +819,12 @@ static int avisynth_open_file(AVFormatContext *s)
 
 #ifdef _WIN32
 /* Convert UTF-8 to ANSI code page */
-MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
-WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
-MAX_PATH * 4, NULL, NULL);
+if (utf8toansi(s->url, _ansi)) {
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
 arg = avs_new_value_string(filename_ansi);
+av_free(filename_ansi);
 #else
 arg = avs_new_value_string(s->url);
 #endif
-- 
2.32.0



___
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 v9 5/6] fftools: Enable long path support on Windows (fixes #8885)

2022-04-15 Thread Nil Admirari
---
 fftools/Makefile |  5 +
 fftools/fftools.manifest | 10 ++
 fftools/manifest.rc  |  3 +++
 3 files changed, 18 insertions(+)
 create mode 100644 fftools/fftools.manifest
 create mode 100644 fftools/manifest.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index 81ad6c4f..105ae5cc 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -15,6 +15,11 @@ OBJS-ffmpeg +=  \
 fftools/ffmpeg_mux.o\
 fftools/ffmpeg_opt.o\
 
+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/manifest.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/fftools.manifest b/fftools/fftools.manifest
new file mode 100644
index ..30b7d8fe
--- /dev/null
+++ b/fftools/fftools.manifest
@@ -0,0 +1,10 @@
+
+
+
+  
+  
+http://schemas.microsoft.com/SMI/2016/WindowsSettings;>
+  true
+
+  
+
diff --git a/fftools/manifest.rc b/fftools/manifest.rc
new file mode 100644
index ..e436fa73
--- /dev/null
+++ b/fftools/manifest.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fftools.manifest"
-- 
2.32.0



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