Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: avoid invalid reads in forced keyframe parsing

2023-03-11 Thread Anton Khirnov
Quoting Zhao Zhili (2023-03-10 15:44:56)
> 
> > From: ffmpeg-devel  On Behalf Of Anton 
> > Khirnov
> > Sent: 2023年3月10日 21:46
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: avoid invalid 
> > reads in forced keyframe parsing
> > 
> > Fixes #10243
> > ---
> >  fftools/ffmpeg_mux_init.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> > index b3cc502fdd..09d24ba8e5 100644
> > --- a/fftools/ffmpeg_mux_init.c
> > +++ b/fftools/ffmpeg_mux_init.c
> > @@ -2063,7 +2063,7 @@ static void parse_forced_key_frames(KeyframeForceCtx 
> > *kf, const Muxer *mux,
> >  if (next)
> >  *next++ = 0;
> > 
> > -if (!memcmp(p, "chapters", 8)) {
> > +if (strstr(p, "chapters") == p) {
> 
> Does strncmp() more efficient in this case?

I don't see the point of optimizing this code for speed. A strncmp call
is longer and less readable IMO.

-- 
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/6] lavc/decode: stop mangling last_pkt_props->opaque

2023-03-11 Thread Anton Khirnov
pushed to master and 6.0

-- 
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 v2 6/6] lavu/frame: deprecate AVFrame.pkt_{pos, size}

2023-03-11 Thread Anton Khirnov
These fields are supposed to store information about the packet the
frame was decoded from, specifically the byte offset it was stored at
and its size.

However,
- the fields are highly ad-hoc - there is no strong reason why
  specifically those (and not any other) packet properties should have a
  dedicated field in AVFrame; unlike e.g. the timestamps, there is no
  fundamental link between coded packet offset/size and decoded frames
- they only make sense for frames produced by decoding demuxed packets,
  and even then it is not always the case that the encoded data was
  stored in the file as a contiguous sequence of bytes (in order for pos
  to be well-defined)
- pkt_pos was added without much explanation, apparently to allow
  passthrough of this information through lavfi in order to handle byte
  seeking in ffplay. That is now implemented using arbitrary user data
  passthrough in AVFrame.opaque_ref.
- several filters use pkt_pos as a variable available to user-supplied
  expressions, but there seems to be no established motivation for using them.
- pkt_size was added for use in ffprobe, but that too is now handled
  without using this field. Additonally, the values of this field
  produced by libavcodec are flawed, as described in the previous
  ffprobe conversion commit.

In summary - these fields are ill-defined and insufficiently motivated,
so deprecate them.
---
 doc/filters.texi  | 35 
 libavcodec/av1dec.c   |  4 +++
 libavcodec/crystalhd.c|  6 -
 libavcodec/cuviddec.c |  6 -
 libavcodec/decode.c   | 18 -
 libavcodec/libuavs3d.c|  8 ++
 libavdevice/lavfi.c   |  8 ++
 libavfilter/af_ashowinfo.c|  3 +--
 libavfilter/af_volume.c   | 16 ---
 libavfilter/asrc_flite.c  |  4 +++
 libavfilter/avfilter.c|  8 ++
 libavfilter/f_select.c|  6 +
 libavfilter/f_sendcmd.c   |  8 ++
 libavfilter/setpts.c  | 16 +++
 libavfilter/vf_crop.c | 14 --
 libavfilter/vf_drawtext.c | 14 +-
 libavfilter/vf_eq.c   | 10 +--
 libavfilter/vf_eq.h   |  4 +++
 libavfilter/vf_overlay.c  | 18 ++---
 libavfilter/vf_overlay.h  |  2 ++
 libavfilter/vf_overlay_cuda.c | 24 -
 libavfilter/vf_scale.c| 30 +++--
 libavfilter/vf_scale_npp.c| 51 +--
 libavfilter/vf_showinfo.c |  3 +--
 libavfilter/vf_swaprect.c | 16 +--
 libavutil/frame.c |  8 ++
 libavutil/frame.h | 10 +++
 libavutil/version.h   |  1 +
 28 files changed, 291 insertions(+), 60 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 7a7b2ba4e79..a4591d1bed9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -299,7 +299,8 @@ timestamp expressed in seconds, NAN if the input timestamp 
is unknown
 sequential number of the input frame, starting from 0
 
 @item pos
-the position in the file of the input frame, NAN if unknown
+the position in the file of the input frame, NAN if unknown; deprecated, do
+not use
 
 @item w
 @item h
@@ -3005,10 +3006,6 @@ depends on the filter input pad, and is usually 
1/@var{sample_rate}.
 @item pts_time
 The presentation timestamp of the input frame in seconds.
 
-@item pos
-position of the frame in the input stream, -1 if this information in
-unavailable and/or meaningless (for example in case of synthetic audio)
-
 @item fmt
 The sample format.
 
@@ -7306,7 +7303,7 @@ number of samples consumed by the filter
 @item nb_samples
 number of samples in the current frame
 @item pos
-original frame position in the file
+original frame position in the file; deprecated, do not use
 @item pts
 frame PTS
 @item sample_rate
@@ -10428,7 +10425,8 @@ pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} 
is 1.
 The number of the input frame, starting from 0.
 
 @item pos
-the position in the file of the input frame, NAN if unknown
+the position in the file of the input frame, NAN if unknown; deprecated,
+do not use
 
 @item t
 The timestamp expressed in seconds. It's NAN if the input timestamp is unknown.
@@ -12772,7 +12770,7 @@ frame count of the input frame starting from 0
 
 @item pos
 byte position of the corresponding packet in the input file, NAN if
-unspecified
+unspecified; deprecated, do not use
 
 @item r
 frame rate of the input video, NAN if the input frame rate is unknown
@@ -18151,7 +18149,8 @@ format. For example for the pixel format "yuv422p" 
@var{hsub} is 2 and
 the number of input frame, starting from 0
 
 @item pos
-the position in the file of the input frame, NAN if unknown
+the position in the file of the input frame, NAN if unknown; deprecated,
+do not use
 
 @item t
 The timestamp, expressed in seconds. It's NAN if the input timestamp is 
unknown.
@@ -18160,7 +18159,7 @@ The timestamp, expressed in seconds. It's NAN if the 
input timestamp is unknown.

Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: avoid invalid reads in forced keyframe parsing

2023-03-11 Thread Zhao Zhili


> -Original Message-
> From: ffmpeg-devel  On Behalf Of Anton 
> Khirnov
> Sent: 2023年3月11日 18:37
> To: 'FFmpeg development discussions and patches' 
> Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: avoid invalid 
> reads in forced keyframe parsing
> 
> Quoting Zhao Zhili (2023-03-10 15:44:56)
> >
> > > From: ffmpeg-devel  On Behalf Of Anton 
> > > Khirnov
> > > Sent: 2023年3月10日 21:46
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg_mux_init: avoid invalid 
> > > reads in forced keyframe parsing
> > >
> > > Fixes #10243
> > > ---
> > >  fftools/ffmpeg_mux_init.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> > > index b3cc502fdd..09d24ba8e5 100644
> > > --- a/fftools/ffmpeg_mux_init.c
> > > +++ b/fftools/ffmpeg_mux_init.c
> > > @@ -2063,7 +2063,7 @@ static void 
> > > parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux,
> > >  if (next)
> > >  *next++ = 0;
> > >
> > > -if (!memcmp(p, "chapters", 8)) {
> > > +if (strstr(p, "chapters") == p) {
> >
> > Does strncmp() more efficient in this case?
> 
> I don't see the point of optimizing this code for speed. A strncmp call
> is longer and less readable IMO.

This is a case for the need of a strstarts(). strncmp is more intuitive than 
strstr()
for this job.

https://github.com/torvalds/linux/blob/master/include/linux/string.h#L215

static inline bool strstarts(const char *str, const char *prefix)
{
return strncmp(str, prefix, strlen(prefix)) == 0;
}

> 
> --
> 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 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/3] avfilter: add avx2 filter_line function for bwdif

2023-03-11 Thread Thomas Mundt
Hi James,

Am Mo., 20. Feb. 2023 um 20:59 Uhr schrieb James Darnley :

> 2.24x faster (1925±1.3 vs. 859±2.2 decicycles) compared with ssse3
> ---
>  libavfilter/x86/vf_bwdif.asm| 29 -
>  libavfilter/x86/vf_bwdif_init.c | 12 
>  2 files changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/libavfilter/x86/vf_bwdif.asm b/libavfilter/x86/vf_bwdif.asm
> index 0b453da53b..5cc61435fd 100644
> --- a/libavfilter/x86/vf_bwdif.asm
> +++ b/libavfilter/x86/vf_bwdif.asm
> @@ -26,18 +26,22 @@
>
>  %include "libavutil/x86/x86util.asm"
>
> -SECTION_RODATA
> +SECTION_RODATA 32
>
> -pw_coefhf:  times 4 dw  1016, 5570
> -pw_coefhf1: times 8 dw -3801
> -pw_coefsp:  times 4 dw  5077, -981
> -pw_splfdif: times 4 dw  -768,  768
> +pw_coefhf:  times 8 dw  1016, 5570
> +pw_coefhf1: times 16 dw -3801
> +pw_coefsp:  times 8 dw  5077, -981
> +pw_splfdif: times 8 dw  -768,  768
>
>  SECTION .text
>
>  %macro LOAD8 2
> +%if mmsize == 32
> +pmovzxbw %1, %2
> +%else
>  movh %1, %2
>  punpcklbw%1, m7
> +%endif
>  %endmacro
>
>  %macro LOAD12 2
> @@ -45,8 +49,14 @@ SECTION .text
>  %endmacro
>
>  %macro DISP8 0
> +%if mmsize == 32
> +vextracti128  xm1,m2, 1
> +packuswb  xm2,   xm1
> +movu [dstq], xm2
> +%else
>  packuswb m2, m2
>  movh [dstq], m2
> +%endif
>  %endmacro
>
>  %macro DISP12 0
> @@ -244,8 +254,12 @@ cglobal bwdif_filter_line_12bit, 4, 9, 13, 0, dst,
> prev, cur, next, w, \
>prefs, mrefs, prefs2,
> mrefs2, \
>prefs3, mrefs3, prefs4, \
>mrefs4, parity, clip_max
> +%if mmsize == 32
> +vpbroadcastd m12, DWORD clip_maxm
>

I get a green pattern at bit depths > 8.
Looks good with:
vpbroadcastw m12, WORD clip_maxm

+%else
>  movdm12, DWORD clip_maxm
>  SPLATW  m12, m12, 0
> +%endif
>  %else
>  cglobal bwdif_filter_line_12bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
>prefs, mrefs, prefs2,
> mrefs2, \
> @@ -264,3 +278,8 @@ INIT_XMM ssse3
>  BWDIF
>  INIT_XMM sse2
>  BWDIF
> +
> +%if HAVE_AVX2_EXTERNAL && ARCH_X86_64
> +INIT_YMM avx2
> +BWDIF
> +%endif
> diff --git a/libavfilter/x86/vf_bwdif_init.c
> b/libavfilter/x86/vf_bwdif_init.c
> index ba7bc40c3d..f833318c10 100644
> --- a/libavfilter/x86/vf_bwdif_init.c
> +++ b/libavfilter/x86/vf_bwdif_init.c
> @@ -32,6 +32,10 @@ void ff_bwdif_filter_line_ssse3(void *dst, void *prev,
> void *cur, void *next,
>  int w, int prefs, int mrefs, int prefs2,
>  int mrefs2, int prefs3, int mrefs3, int
> prefs4,
>  int mrefs4, int parity, int clip_max);
> +void ff_bwdif_filter_line_avx2(void *dst, void *prev, void *cur, void
> *next,
> +   int w, int prefs, int mrefs, int prefs2,
> +   int mrefs2, int prefs3, int mrefs3, int
> prefs4,
> +   int mrefs4, int parity, int clip_max);
>
>  void ff_bwdif_filter_line_12bit_sse2(void *dst, void *prev, void *cur,
> void *next,
>   int w, int prefs, int mrefs, int
> prefs2,
> @@ -41,6 +45,10 @@ void ff_bwdif_filter_line_12bit_ssse3(void *dst, void
> *prev, void *cur, void *ne
>int w, int prefs, int mrefs, int
> prefs2,
>int mrefs2, int prefs3, int mrefs3,
> int prefs4,
>int mrefs4, int parity, int
> clip_max);
> +void ff_bwdif_filter_line_12bit_avx2(void *dst, void *prev, void *cur,
> void *next,
> + int w, int prefs, int mrefs, int
> prefs2,
> + int mrefs2, int prefs3, int mrefs3,
> int prefs4,
> + int mrefs4, int parity, int
> clip_max);
>
>  av_cold void ff_bwdif_init_x86(BWDIFContext *bwdif, int bit_depth)
>  {
> @@ -51,10 +59,14 @@ av_cold void ff_bwdif_init_x86(BWDIFContext *bwdif,
> int bit_depth)
>  bwdif->filter_line = ff_bwdif_filter_line_sse2;
>  if (EXTERNAL_SSSE3(cpu_flags))
>  bwdif->filter_line = ff_bwdif_filter_line_ssse3;
> +if (ARCH_X86_64 && EXTERNAL_AVX2(cpu_flags))
> +bwdif->filter_line = ff_bwdif_filter_line_avx2;
>  } else if (bit_depth <= 12) {
>  if (EXTERNAL_SSE2(cpu_flags))
>  bwdif->filter_line = ff_bwdif_filter_line_12bit_sse2;
>  if (EXTERNAL_SSSE3(cpu_flags))
>  bwdif->filter_line = ff_bwdif_filter_line_12bit_ssse3;
> +if (ARCH_X86_64 && EXTERNAL_AVX2(cpu_flags))
> +bwdif->filter_line = ff_bwdif_filter_line_12bit_avx2;
>  }
>  }
> --
> 2.39.1
___
ffmpeg-deve

Re: [FFmpeg-devel] [PATCH 2/3] checkasm: add test for bwdif

2023-03-11 Thread Thomas Mundt
Hi James,

Am Mo., 20. Feb. 2023 um 20:59 Uhr schrieb James Darnley :

> ---
>  tests/checkasm/Makefile   |  1 +
>  tests/checkasm/checkasm.c |  3 ++
>  tests/checkasm/checkasm.h |  1 +
>  tests/checkasm/vf_bwdif.c | 70 +++
>  tests/fate/checkasm.mak   |  1 +
>  5 files changed, 76 insertions(+)
>  create mode 100644 tests/checkasm/vf_bwdif.c
>
> diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
> index a6f06c7007..b6a43f181f 100644
> --- a/tests/checkasm/Makefile
> +++ b/tests/checkasm/Makefile
> @@ -40,6 +40,7 @@ CHECKASMOBJS-$(CONFIG_AVCODEC)  +=
> $(AVCODECOBJS-yes)
>  # libavfilter tests
>  AVFILTEROBJS-$(CONFIG_AFIR_FILTER) += af_afir.o
>  AVFILTEROBJS-$(CONFIG_BLEND_FILTER) += vf_blend.o
> +AVFILTEROBJS-$(CONFIG_BWDIF_FILTER)  += vf_bwdif.o
>  AVFILTEROBJS-$(CONFIG_COLORSPACE_FILTER) += vf_colorspace.o
>  AVFILTEROBJS-$(CONFIG_EQ_FILTER) += vf_eq.o
>  AVFILTEROBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
> diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
> index e96d84a7da..5e729cf0e0 100644
> --- a/tests/checkasm/checkasm.c
> +++ b/tests/checkasm/checkasm.c
> @@ -179,6 +179,9 @@ static const struct {
>  #if CONFIG_BLEND_FILTER
>  { "vf_blend", checkasm_check_blend },
>  #endif
> +#if CONFIG_BWDIF_FILTER
> +{ "vf_bwdif", checkasm_check_vf_bwdif },
> +#endif
>  #if CONFIG_COLORSPACE_FILTER
>  { "vf_colorspace", checkasm_check_colorspace },
>  #endif
> diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
> index 8744a81218..e9e73c6fa0 100644
> --- a/tests/checkasm/checkasm.h
> +++ b/tests/checkasm/checkasm.h
> @@ -82,6 +82,7 @@ void checkasm_check_utvideodsp(void);
>  void checkasm_check_v210dec(void);
>  void checkasm_check_v210enc(void);
>  void checkasm_check_vc1dsp(void);
> +void checkasm_check_vf_bwdif(void);
>  void checkasm_check_vf_eq(void);
>  void checkasm_check_vf_gblur(void);
>  void checkasm_check_vf_hflip(void);
> diff --git a/tests/checkasm/vf_bwdif.c b/tests/checkasm/vf_bwdif.c
> new file mode 100644
> index 00..e27f9b7494
> --- /dev/null
> +++ b/tests/checkasm/vf_bwdif.c
> @@ -0,0 +1,70 @@
> +/*
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU 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.
> + */
> +
> +#include 
> +#include "checkasm.h"
> +#include "libavcodec/internal.h"
> +#include "libavfilter/bwdif.h"
> +
> +#define WIDTH 256
> +
> +#define randomize_buffers(buf0, buf1, mask, count) \
> +for (size_t i; i < count; i++) \
> +buf0[i] = buf1[i] = rnd() & mask
> +
> +void checkasm_check_vf_bwdif(void)
> +{
> +BWDIFContext ctx_8, ctx_10, ctx_16;
> +
> +ff_bwdif_init_filter_line(&ctx_8, 8);
> +ff_bwdif_init_filter_line(&ctx_10, 10);
> +ff_bwdif_init_filter_line(&ctx_16, 16);
> +
> +if (check_func(ctx_8.filter_line, "bwdif8")) {
> +uint8_t prev0[9*WIDTH], prev1[9*WIDTH];
> +uint8_t next0[9*WIDTH], next1[9*WIDTH];
> +uint8_t cur0[9*WIDTH], cur1[9*WIDTH];
> +uint8_t dst0[WIDTH], dst1[WIDTH];
> +
> +declare_func(void, void *dst, void *prev, void *cur, void *next,
> +int w, int prefs, int mrefs, int prefs2, int
> mrefs2,
> +int prefs3, int mrefs3, int prefs4, int mrefs4,
> +int parity, int clip_max);
> +
> +randomize_buffers(prev0, prev1, 0xff, 9*WIDTH);
> +randomize_buffers(next0, next1, 0xff, 9*WIDTH);
> +randomize_buffers(cur0, cur1, 0xff, 9*WIDTH);
> +
> +call_ref(dst0, prev0 + 4*WIDTH, cur0 + 4*WIDTH, next0 + 4*WIDTH,
> WIDTH,
> +WIDTH, -WIDTH, 2*WIDTH, -2*WIDTH, 3*WIDTH, -3*WIDTH,
> 4*WIDTH, -4*WIDTH,
> +0, 0xff);
> +call_new(dst1, prev1 + 4*WIDTH, cur1 + 4*WIDTH, next1 + 4*WIDTH,
> WIDTH,
> +WIDTH, -WIDTH, 2*WIDTH, -2*WIDTH, 3*WIDTH, -3*WIDTH,
> 4*WIDTH, -4*WIDTH,
> +0, 0xff);
> +
> +if (memcmp(dst0, dst1, WIDTH)
> +|| memcmp(prev0, prev1, sizeof prev0)
> +|| memcmp(next0, next1, sizeof next0)
> +|| memcmp(cur0, cur1, sizeof cur0))
> +fail();
> +bench_new(dst1, prev1 + 4*WIDTH, cur1 + 4*WIDTH, next1 + 4*WIDTH,
> WIDTH,
> +WIDT

[FFmpeg-devel] [PATCH] tests/fate: add simple tests for libx264 and libx265

2023-03-11 Thread Anton Khirnov
Since these are external encoders not under our control, we cannot test
the encoded output exactly as is done for internal encoders. We can
still test however that the output is decodable and produces the
expected number of frames with expected dimensions, pixel formats, and
timestamps.
---
A minimal proof of concept, more tests for these and other external
encoders are welcome.

Samples were picked at a whim, better suggestions also welcome.
---
 tests/Makefile|  1 +
 tests/fate-run.sh | 16 +++
 tests/fate/enc_external.mak   | 10 +
 tests/ref/fate/libx264-simple | 85 +++
 tests/ref/fate/libx265-simple | 25 +++
 5 files changed, 137 insertions(+)
 create mode 100644 tests/fate/enc_external.mak
 create mode 100644 tests/ref/fate/libx264-simple
 create mode 100644 tests/ref/fate/libx265-simple

diff --git a/tests/Makefile b/tests/Makefile
index 1d50e1d175..8071bd829d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -178,6 +178,7 @@ include $(SRC_PATH)/tests/fate/dpcm.mak
 include $(SRC_PATH)/tests/fate/dvvideo.mak
 include $(SRC_PATH)/tests/fate/ea.mak
 include $(SRC_PATH)/tests/fate/exif.mak
+include $(SRC_PATH)/tests/fate/enc_external.mak
 # Must be included after lavf-video.mak
 include $(SRC_PATH)/tests/fate/ffmpeg.mak
 include $(SRC_PATH)/tests/fate/ffprobe.mak
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 61cc59acc0..e12279e4cf 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -282,6 +282,22 @@ stream_remux(){
 run ffprobe${PROGSUF}${EXECSUF} -bitexact $ffprobe_opts $tencfile || 
return
 }
 
+# this function is for testing external encoders,
+# where the precise output is not controlled by us
+# we can still test e.g. that the output can be decoded correctly
+enc_external(){
+srcfile=$1
+enc_fmt=$2
+enc_opt=$3
+probe_opt=$4
+
+srcfile=$(target_path $srcfile)
+encfile=$(target_path "${outdir}/${test}.${enc_fmt}")
+
+ffmpeg -i $srcfile $enc_opt -f $enc_fmt -y $encfile || return
+run ffprobe${PROGSUF}${EXECSUF} -bitexact $probe_opt $encfile || return
+}
+
 # FIXME: There is a certain duplication between the avconv-related helper
 # functions above and below that should be refactored.
 ffmpeg2="$target_exec ${target_path}/ffmpeg${PROGSUF}${EXECSUF}"
diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak
new file mode 100644
index 00..6492b52fa1
--- /dev/null
+++ b/tests/fate/enc_external.mak
@@ -0,0 +1,10 @@
+FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 H264, MOV, H264_DEMUXER) += 
fate-libx264-simple
+fate-libx264-simple: CMD = enc_external 
$(TARGET_SAMPLES)/h264-conformance/BA1_Sony_D.jsv \
+mp4 "-c:v libx264" "-show_entries frame=width,height,pix_fmt,pts,pkt_dts 
-of flat"
+
+FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += 
fate-libx265-simple
+fate-libx265-simple: CMD = enc_external 
$(TARGET_SAMPLES)/hevc-conformance/POC_A_Bossen_3.bit \
+mp4 "-c:v libx265" "-show_entries frame=width,height,pix_fmt,pts,pkt_dts 
-of flat"
+
+FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes)
+fate-enc-external: $(FATE_ENC_EXTERNAL-yes)
diff --git a/tests/ref/fate/libx264-simple b/tests/ref/fate/libx264-simple
new file mode 100644
index 00..b7f7e67c3b
--- /dev/null
+++ b/tests/ref/fate/libx264-simple
@@ -0,0 +1,85 @@
+frames.frame.0.pts=0
+frames.frame.0.pkt_dts=0
+frames.frame.0.width=176
+frames.frame.0.height=144
+frames.frame.0.pix_fmt="yuv420p"
+frames.frame.1.pts=512
+frames.frame.1.pkt_dts=512
+frames.frame.1.width=176
+frames.frame.1.height=144
+frames.frame.1.pix_fmt="yuv420p"
+frames.frame.2.pts=1024
+frames.frame.2.pkt_dts=1024
+frames.frame.2.width=176
+frames.frame.2.height=144
+frames.frame.2.pix_fmt="yuv420p"
+frames.frame.3.pts=1536
+frames.frame.3.pkt_dts=1536
+frames.frame.3.width=176
+frames.frame.3.height=144
+frames.frame.3.pix_fmt="yuv420p"
+frames.frame.4.pts=2048
+frames.frame.4.pkt_dts=2048
+frames.frame.4.width=176
+frames.frame.4.height=144
+frames.frame.4.pix_fmt="yuv420p"
+frames.frame.5.pts=2560
+frames.frame.5.pkt_dts=2560
+frames.frame.5.width=176
+frames.frame.5.height=144
+frames.frame.5.pix_fmt="yuv420p"
+frames.frame.6.pts=3072
+frames.frame.6.pkt_dts=3072
+frames.frame.6.width=176
+frames.frame.6.height=144
+frames.frame.6.pix_fmt="yuv420p"
+frames.frame.7.pts=3584
+frames.frame.7.pkt_dts=3584
+frames.frame.7.width=176
+frames.frame.7.height=144
+frames.frame.7.pix_fmt="yuv420p"
+frames.frame.8.pts=4096
+frames.frame.8.pkt_dts=4096
+frames.frame.8.width=176
+frames.frame.8.height=144
+frames.frame.8.pix_fmt="yuv420p"
+frames.frame.9.pts=4608
+frames.frame.9.pkt_dts=4608
+frames.frame.9.width=176
+frames.frame.9.height=144
+frames.frame.9.pix_fmt="yuv420p"
+frames.frame.10.pts=5120
+frames.frame.10.pkt_dts=5120
+frames.frame.10.width=176
+frames.frame.10.height=144
+frames.frame.10.pix_fmt="yuv420p"
+frames.frame.11.pts=5632
+frames.frame.11.pkt_dts=5632
+frames.frame.11.width=176
+frame

[FFmpeg-devel] [PATCH] Correct space color when using libopenjpeg

2023-03-11 Thread Wang Chuan

When decoding jp2 with palette, [color space] is determined when calling
[opj_decode]. Because of this, [pix_fmt] should be set after decoding.
Otherwise, [pix_fmt] will be set to AV_PIX_FMT_GRAY8 and output an wrong
image.

Signed-off-by: Wang Chuan 
---
 libavcodec/libopenjpegdec.c | 35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 206db07ec7..1a8d599840 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -399,6 +399,23 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 if (ret < 0)
 goto done;
 +ret = !opj_decode(dec, stream, image);
+
+if (ret) {
+av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
+ret = AVERROR_EXTERNAL;
+goto done;
+}
+
+for (i = 0; i < image->numcomps; i++) {
+if (!image->comps[i].data) {
+av_log(avctx, AV_LOG_ERROR,
+   "Image component %d contains no data.\n", i);
+ret = AVERROR_INVALIDDATA;
+goto done;
+}
+}
+
 if (avctx->pix_fmt != AV_PIX_FMT_NONE)
 if (!libopenjpeg_matches_pix_fmt(image, avctx->pix_fmt))
 avctx->pix_fmt = AV_PIX_FMT_NONE;
@@ -411,6 +428,7 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 ret = AVERROR_UNKNOWN;
 goto done;
 }
+
 for (i = 0; i < image->numcomps; i++)
 if (image->comps[i].prec > avctx->bits_per_raw_sample)
 avctx->bits_per_raw_sample = image->comps[i].prec;
@@ -418,23 +436,6 @@ static int libopenjpeg_decode_frame(AVCodecContext 
*avctx, AVFrame *picture,

 if ((ret = ff_thread_get_buffer(avctx, picture, 0)) < 0)
 goto done;
 -ret = !opj_decode(dec, stream, image);
-
-if (ret) {
-av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
-ret = AVERROR_EXTERNAL;
-goto done;
-}
-
-for (i = 0; i < image->numcomps; i++) {
-if (!image->comps[i].data) {
-av_log(avctx, AV_LOG_ERROR,
-   "Image component %d contains no data.\n", i);
-ret = AVERROR_INVALIDDATA;
-goto done;
-}
-}
-
 desc   = av_pix_fmt_desc_get(avctx->pix_fmt);
 pixel_size = desc->comp[0].step;
 ispacked   = libopenjpeg_ispacked(avctx->pix_fmt);
--
2.37.1 (Apple Git-137.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".