Re: [FFmpeg-devel] [PATCH v3 0/8] add fd protocol

2023-01-10 Thread Xiang, Haihao
On Wo, 2023-01-11 at 11:18 +0800, zhilizhao(赵志立) wrote:
> > On Jan 9, 2023, at 11:17, zhilizhao(赵志立)  wrote:
> > 
> > > On Dec 15, 2022, at 01:10, Zhao Zhili  wrote:
> > > 
> > > From: Zhao Zhili 
> > > 
> > > v2:
> > > 1. Forbid pass file descriptor via fd:{num}, instead of -fd option
> > > 2. Set CLOEXEC
> > > 3. Prefer fd over pipe for fftools
> > > 
> > > v1: dup file descriptor
> > > 
> > > Zhao Zhili (8):
> > > avformat/file: add fd option for pipe
> > > avformat/file: reindent after the previous commit
> > > avformat/file: dup file descriptor for pipe
> > > avformat/file: add fd protocol
> > > fftools/ffmpeg_demux: disable stdin interaction for fd protocol
> > > fftools/ffplay: prefer fd over pipe for seek support
> > > fftools/ffprobe: prefer fd over pipe for seek support
> > > fftools/ffmpeg_demux: prefer fd over pipe for seek support
> > > 
> > > doc/protocols.texi  |  31 +++-
> > > fftools/ffmpeg_demux.c  |   3 +-
> > > fftools/ffplay.c|   2 +-
> > > fftools/ffprobe.c   |   4 +-
> > > libavformat/Makefile|   1 +
> > > libavformat/file.c  | 152 +++-
> > > libavformat/protocols.c |   1 +
> > > libavformat/version.h   |   4 +-
> > > 8 files changed, 156 insertions(+), 42 deletions(-)
> > 
> > Will apply soon unless there are objections.
> 
> Pushed.

It caused link error on Windows

INFO  - LDlibavformat/avformat-59.dll
INFO  -Creating library libavformat/avformat.lib and object
libavformat/avformat.exp
INFO  - file.o : error LNK2019: unresolved external symbol S_ISREG referenced in
function fd_open
INFO  - file.o : error LNK2019: unresolved external symbol S_ISBLK referenced in
function fd_open
INFO  - libavformat\avformat-59.dll : fatal error LNK1120: 2 unresolved
externals

Thanks
Haihao

> 
> > ___
> > 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 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] avutil/hwcontext_mediacodec: fix backward compatibility

2023-01-10 Thread Zhao Zhili
From: Zhao Zhili 

AVMediaCodecDeviceContext without surface or native_window is
useless, it shouldn't be created at all. Such dummy AVHWDeviceContext
is allowed before, and it's used by mpv player. Creating a ANativeWindow
automatically breaks such usecases.

So disable creating a ANativeWindow by default. It can be enabled
via the create_window flag, or by set the AVDictionary of
av_hwdevice_ctx_create(). The downside is that

ffmpeg -hwaccel mediacodec -i input.mp4 \
-c:a copy -c:v hevc_mediacodec output.mp4

use ByteBuffer mode which isn't as efficient as before. The upside
is libavfilter works now, which should be less surprise.

To enable create_window on ffmpeg command line, use
ffmpeg -hwaccel mediacodec \
-init_hw_device mediacodec=mediacodec,create_window=1 \
-i input.mp4 -c:a copy -c:v hevc_mediacodec output.mp4

Users should know what it is to enable create_window. It should
be OK to take sometime to figure out the option. And there are comments
inside hwcontext_mediacodec.h to help user figure it out.

Signed-off-by: Zhao Zhili 
---
 libavutil/hwcontext_mediacodec.c | 17 +
 libavutil/hwcontext_mediacodec.h | 16 +++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_mediacodec.c b/libavutil/hwcontext_mediacodec.c
index bb1779d34d..9ed6a8717a 100644
--- a/libavutil/hwcontext_mediacodec.c
+++ b/libavutil/hwcontext_mediacodec.c
@@ -39,11 +39,23 @@ typedef struct MediaCodecDeviceContext {
 static int mc_device_create(AVHWDeviceContext *ctx, const char *device,
 AVDictionary *opts, int flags)
 {
+const AVDictionaryEntry *entry = NULL;
+MediaCodecDeviceContext *s = ctx->hwctx;
+AVMediaCodecDeviceContext *dev = &s->ctx;
+
 if (device && device[0]) {
 av_log(ctx, AV_LOG_ERROR, "Device selection unsupported.\n");
 return AVERROR_UNKNOWN;
 }
 
+while ((entry = av_dict_iterate(opts, entry))) {
+if (!strcmp(entry->key, "create_window"))
+dev->create_window = atoi(entry->value);
+}
+
+av_log(ctx, AV_LOG_DEBUG, "%s createPersistentInputSurface\n",
+dev->create_window ? "Enable" : "Disable");
+
 return 0;
 }
 
@@ -59,6 +71,11 @@ static int mc_device_init(AVHWDeviceContext *ctx)
 if (dev->native_window)
 return 0;
 
+// For backward compatibility, don't return error for a dummy
+// AVHWDeviceContext without surface or native_window.
+if (!dev->create_window)
+return 0;
+
 s->libmedia = dlopen("libmediandk.so", RTLD_NOW);
 if (!s->libmedia)
 return AVERROR_UNKNOWN;
diff --git a/libavutil/hwcontext_mediacodec.h b/libavutil/hwcontext_mediacodec.h
index 920e17764f..fc0263cabc 100644
--- a/libavutil/hwcontext_mediacodec.h
+++ b/libavutil/hwcontext_mediacodec.h
@@ -36,12 +36,26 @@ typedef struct AVMediaCodecDeviceContext {
  * Pointer to ANativeWindow.
  *
  * It both surface and native_window is NULL, try to create it
- * automatically if OS support.
+ * automatically if create_window is true and OS support
+ * createPersistentInputSurface.
  *
  * It can be used as output surface for decoder and input surface for
  * encoder.
  */
 void *native_window;
+
+/**
+ * Enable createPersistentInputSurface automatically.
+ *
+ * Disabled by default.
+ *
+ * It can be enabled by setting this flag directly, or by setting
+ * AVDictionary of av_hwdevice_ctx_create(), with "create_window" as key.
+ * The second method is useful for ffmpeg cmdline, e.g., we can enable it
+ * via:
+ *   -init_hw_device mediacodec=mediacodec,create_window=1
+ */
+int create_window;
 } AVMediaCodecDeviceContext;
 
 #endif /* AVUTIL_HWCONTEXT_MEDIACODEC_H */
-- 
2.25.1

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

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


Re: [FFmpeg-devel] [PATCH] ffmpeg: apply discontinuity adjustment per-stream

2023-01-10 Thread Gyan Doshi




On 2023-01-11 01:40 am, Michael Niedermayer wrote:

On Tue, Jan 03, 2023 at 03:52:17PM +0530, Gyan Doshi wrote:

At present, the offset for discontinuity adjustment is applied per-file but
the check for discontinuity is intra-stream so the same discontinuity when
seen in multiple streams with copyts, leads to compounded adjustment of the
discontinuity offset. This introduces gaps in streams, leading to loss of sync
or even de facto loss of stream.

The ts_offset_discont parameter is transferred to InputStream and adjusted
based on intra-stream gaps.
---
Here's a simulated example to demonstrate the issue:
1) generate input
ffmpeg -f lavfi -i nullsrc=s=32x32:r=1,format=gray -f lavfi -i 
anullsrc=cl=mono:r=8000 -c:v libx264 -preset superfast -bf 0 -crf 50 -c:a aac 
-b:a 64k -muxpreload 0 -muxdelay 0 -output_ts_offset 95000 -t 10 
src-10s.ts

2) demo
ffmpeg -copyts -i "src-10.ts" -vf "showinfo=checksum=0" -af "ashowinfo" -f 
null - -report

==Before patch==

timestamp discontinuity for stream #0:1 (id=257, type=audio): -95443717689, new 
offset= 95443717689
timestamp discontinuity for stream #0:0 (id=256, type=video): -95443717689, new 
offset= 190887435378

[Parsed_ashowinfo_0 @ 02700af98800] n:0 pts:759998976 pts_time:94999.9
[Parsed_ashowinfo_0 @ 02700af98800] n:1 pts:76000 pts_time:95000
  ...
[Parsed_ashowinfo_0 @ 02700af98800] n:745202 pts:1523085824 pts_time:190386
[Parsed_ashowinfo_0 @ 02700af98800] n:745203 pts:1523086848 pts_time:190386
[Parsed_ashowinfo_0 @ 02700af98800] n:745204 pts:2286637614 pts_time:285830
[Parsed_ashowinfo_0 @ 02700af98800] n:745205 pts:2286638638 pts_time:285830


[Parsed_showinfo_0 @ 02700ec34700] n:   0 pts:855000 pts_time:95000
[Parsed_showinfo_0 @ 02700ec34700] n:   1 pts:855009 pts_time:95001
  ...
[Parsed_showinfo_0 @ 02700ec34700] n:95380 pts:1713420 pts_time:190380
[Parsed_showinfo_0 @ 02700ec34700] n:95381 pts:1713429 pts_time:190381
[Parsed_showinfo_0 @ 02700ec34700] n:95382 pts:25724314592 pts_time:285826
[Parsed_showinfo_0 @ 02700ec34700] n:95383 pts:25724404592 pts_time:285827

==After patch==

timestamp discontinuity for stream #0:1 (id=257, type=audio): -95443717689, new 
stream offset= 95443717689
timestamp discontinuity for stream #0:0 (id=256, type=video): -95443717689, new 
stream offset= 95443717689

[Parsed_ashowinfo_0 @ 023c773c8880] n:0 pts:759998976 pts_time:94999.9
[Parsed_ashowinfo_0 @ 023c773c8880] n:1 pts:76000 pts_time:95000
  ...
[Parsed_ashowinfo_0 @ 023c773c8880] n:745202 pts:1523085824 pts_time:190386
[Parsed_ashowinfo_0 @ 023c773c8880] n:745203 pts:1523086848 pts_time:190386
[Parsed_ashowinfo_0 @ 023c773c8880] n:745204 pts:1523087872 pts_time:190386
[Parsed_ashowinfo_0 @ 023c773c8880] n:745205 pts:1523088896 pts_time:190386


[Parsed_showinfo_0 @ 023c795d07c0] n:   0 pts:855000 pts_time:95000
[Parsed_showinfo_0 @ 023c795d07c0] n:   1 pts:855009 pts_time:95001
  ...
[Parsed_showinfo_0 @ 023c795d07c0] n:95380 pts:1713420 pts_time:190380
[Parsed_showinfo_0 @ 023c795d07c0] n:95381 pts:1713429 pts_time:190381
[Parsed_showinfo_0 @ 023c795d07c0] n:95382 pts:1713438 pts_time:190382
[Parsed_showinfo_0 @ 023c795d07c0] n:95383 pts:1713447 pts_time:190383



  fftools/ffmpeg.c | 12 ++--
  fftools/ffmpeg.h |  8 
  2 files changed, 10 insertions(+), 10 deletions(-)

I havent looked into this but i have a slightly ungood feeling about this
change
Yes, this is a hack. Ideal is to track and sync discontinuities at both 
file and stream level to avoid compound adjustments.

Let me rework this.

Regards,
Gyan

___
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 v3 2/2] avcodec/mediacodecdec: check ff_Build_SDK_INT return value

2023-01-10 Thread zhilizhao(赵志立)

> On Jan 10, 2023, at 21:37, Tomas Härdin  wrote:
> 
> tis 2023-01-10 klockan 19:35 +0800 skrev Zhao Zhili:
>> From: Zhao Zhili 
>> 
>> ---
>> v3: when target API <= 24 ==> when target API < 24
>> v2: add comments
>> 
>>  libavcodec/mediacodecdec.c | 8 +++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
>> index 11f655a9aa..21464900d1 100644
>> --- a/libavcodec/mediacodecdec.c
>> +++ b/libavcodec/mediacodecdec.c
>> @@ -415,7 +415,13 @@ static av_cold int
>> mediacodec_decode_init(AVCodecContext *avctx)
>> s->ctx->codec_name, ret);
>>  
>>  sdk_int = ff_Build_SDK_INT(avctx);
>> -if (sdk_int <= 23 &&
>> +/* ff_Build_SDK_INT can fail when target API < 24 and JVM isn't
>> available.
>> + * If we don't check sdk_int > 0, the workaround might be
>> enabled by
>> + * mistake.
>> + * JVM is required to make the workaround works reliably. On the
>> other hand,
>> + * missing a workaround should not be a serious issue, we do as
>> best we can.
>> + */
>> +if (sdk_int > 0 && sdk_int <= 23 &&
>>  strcmp(s->ctx->codec_name,
>> "OMX.amlogic.mpeg2.decoder.awesome") == 0) {
>>  av_log(avctx, AV_LOG_INFO, "Enabling workaround for %s on
>> API=%d\n",
>> s->ctx->codec_name, sdk_int);
> 
> Looks OK

Patchset pushed, thanks for the review.

> 
> /Tomas
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

___
ffmpeg-devel 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 4/4] avcodec/videotoolboxenc: fix error code

2023-01-10 Thread zhilizhao(赵志立)

> On Jan 4, 2023, at 10:38, Steven Liu  wrote:
> 
> Zhao Zhili  于2023年1月4日周三 10:35写道:
>> 
>> From: Zhao Zhili 
>> 
>> 1. Fix return 0 on success.
>> 2. Fix return OS error code passthrough.
>> ---
>> libavcodec/videotoolboxenc.c | 8 ++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> index 3b00e542cb..56971471e4 100644
>> --- a/libavcodec/videotoolboxenc.c
>> +++ b/libavcodec/videotoolboxenc.c
>> @@ -2555,6 +2555,7 @@ static int vtenc_populate_extradata(AVCodecContext   
>> *avctx,
>> pool = VTCompressionSessionGetPixelBufferPool(vtctx->session);
>> if(!pool){
>> av_log(avctx, AV_LOG_ERROR, "Error getting pixel buffer pool.\n");
>> +status = AVERROR_EXTERNAL;
>> goto pe_cleanup;
>> }
>> 
>> @@ -2564,6 +2565,7 @@ static int vtenc_populate_extradata(AVCodecContext   
>> *avctx,
>> 
>> if(status != kCVReturnSuccess){
>> av_log(avctx, AV_LOG_ERROR, "Error creating frame from pool: %d\n", 
>> status);
>> +status = AVERROR_EXTERNAL;
>> goto pe_cleanup;
>> }
>> 
>> @@ -2581,7 +2583,7 @@ static int vtenc_populate_extradata(AVCodecContext   
>> *avctx,
>>AV_LOG_ERROR,
>>"Error sending frame for extradata: %d\n",
>>status);
>> -
>> +status = AVERROR_EXTERNAL;
>> goto pe_cleanup;
>> }
>> 
>> @@ -2589,8 +2591,10 @@ static int vtenc_populate_extradata(AVCodecContext   
>> *avctx,
>> status = VTCompressionSessionCompleteFrames(vtctx->session,
>> kCMTimeIndefinite);
>> 
>> -if (status)
>> +if (status) {
>> +status = AVERROR_EXTERNAL;
>> goto pe_cleanup;
>> +}
>> 
>> status = vtenc_q_pop(vtctx, 0, &buf, NULL);
>> if (status) {
>> --
>> 2.35.3
>> 
>> ___
>> 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".
> 
> 
> LGTM

Pushed patch v2 with minor change of commit message, thanks for the review.

> 
> Thanks
> Steven
> 
> 
> 

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

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


Re: [FFmpeg-devel] [PATCH 2/3] avcodec/videotoolboxenc: pass error code through

2023-01-10 Thread zhilizhao(赵志立)


> On Jan 4, 2023, at 10:35, zhilizhao(赵志立)  wrote:
> 
> 
> 
>> On Jan 4, 2023, at 02:11, Tomas Härdin  wrote:
>> 
>> tis 2023-01-03 klockan 18:18 +0800 skrev Zhao Zhili:
>>> From: Zhao Zhili 
>>> 
>>> Signed-off-by: Zhao Zhili 
>>> ---
>>> libavcodec/videotoolboxenc.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/libavcodec/videotoolboxenc.c
>>> b/libavcodec/videotoolboxenc.c
>>> index 27db4e0d5e..3b00e542cb 100644
>>> --- a/libavcodec/videotoolboxenc.c
>>> +++ b/libavcodec/videotoolboxenc.c
>>> @@ -2156,7 +2156,7 @@ static int get_cv_pixel_info(
>>> 
>>> status = get_cv_pixel_format(avctx, av_format, av_color_range,
>>> color, &range_guessed);
>>> if (status)
>>> -return AVERROR(EINVAL);
>>> +return status;
>>> 
>>> if (range_guessed) {
>>> if (!vtctx->warned_color_range) {
>>> @@ -2338,7 +2338,7 @@ static int
>>> create_cv_pixel_buffer(AVCodecContext   *avctx,
>>> status
>>> );
>>> 
>>> -return AVERROR_EXTERNAL;
>>> +return status;
>> 
>> Are these guaranteed to always be negative?
> 
> Yes.

Patchset applied, thanks for the review.

> 
>> 
>> /Tomas
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> ___
> ffmpeg-devel 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 v3 0/8] add fd protocol

2023-01-10 Thread zhilizhao(赵志立)

> On Jan 9, 2023, at 11:17, zhilizhao(赵志立)  wrote:
> 
>> On Dec 15, 2022, at 01:10, Zhao Zhili  wrote:
>> 
>> From: Zhao Zhili 
>> 
>> v2:
>> 1. Forbid pass file descriptor via fd:{num}, instead of -fd option
>> 2. Set CLOEXEC
>> 3. Prefer fd over pipe for fftools
>> 
>> v1: dup file descriptor
>> 
>> Zhao Zhili (8):
>> avformat/file: add fd option for pipe
>> avformat/file: reindent after the previous commit
>> avformat/file: dup file descriptor for pipe
>> avformat/file: add fd protocol
>> fftools/ffmpeg_demux: disable stdin interaction for fd protocol
>> fftools/ffplay: prefer fd over pipe for seek support
>> fftools/ffprobe: prefer fd over pipe for seek support
>> fftools/ffmpeg_demux: prefer fd over pipe for seek support
>> 
>> doc/protocols.texi  |  31 +++-
>> fftools/ffmpeg_demux.c  |   3 +-
>> fftools/ffplay.c|   2 +-
>> fftools/ffprobe.c   |   4 +-
>> libavformat/Makefile|   1 +
>> libavformat/file.c  | 152 +++-
>> libavformat/protocols.c |   1 +
>> libavformat/version.h   |   4 +-
>> 8 files changed, 156 insertions(+), 42 deletions(-)
> 
> Will apply soon unless there are objections.

Pushed.

> ___
> 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] lavf/spdifdec: support EAC3

2023-01-10 Thread rcombs
Parsing should probably be enabled for all codecs, at least for headers,
but e.g. the AAC parser produces 1-byte packets of zero padding with it,
so I'm just enabling it for EAC3 for the moment.
---
 libavformat/spdifdec.c  |  19 +-
 tests/fate/spdif.mak|   3 +
 tests/ref/fate/spdif-eac3-remux | 659 
 3 files changed, 680 insertions(+), 1 deletion(-)
 create mode 100644 tests/ref/fate/spdif-eac3-remux

diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c
index 672133581a..7a6b77aae8 100644
--- a/libavformat/spdifdec.c
+++ b/libavformat/spdifdec.c
@@ -31,6 +31,7 @@
 #include "libavcodec/adts_parser.h"
 
 #include "avformat.h"
+#include "internal.h"
 #include "spdif.h"
 
 static int spdif_get_offset_and_codec(AVFormatContext *s,
@@ -93,6 +94,10 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
 *offset = 8192;
 *codec = AV_CODEC_ID_DTS;
 break;
+case IEC61937_EAC3:
+*offset = 24576;
+*codec = AV_CODEC_ID_EAC3;
+break;
 default:
 if (s) { /* be silent during a probe */
 avpriv_request_sample(s, "Data type 0x%04x in IEC 61937",
@@ -170,6 +175,16 @@ static int spdif_read_header(AVFormatContext *s)
 return 0;
 }
 
+static int spdif_get_pkt_size_bits(int type, int code)
+{
+switch (type & 0xff) {
+case IEC61937_EAC3:
+return code << 3;
+default:
+return code;
+}
+}
+
 int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 AVIOContext *pb = s->pb;
@@ -185,7 +200,7 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 
 data_type = avio_rl16(pb);
-pkt_size_bits = avio_rl16(pb);
+pkt_size_bits = spdif_get_pkt_size_bits(data_type, avio_rl16(pb));
 
 if (pkt_size_bits % 16)
 avpriv_request_sample(s, "Packet not ending at a 16-bit boundary");
@@ -218,6 +233,8 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
 }
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codecpar->codec_id = codec_id;
+if (codec_id == AV_CODEC_ID_EAC3)
+ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL;
 } else if (codec_id != s->streams[0]->codecpar->codec_id) {
 avpriv_report_missing_feature(s, "Codec change in IEC 61937");
 return AVERROR_PATCHWELCOME;
diff --git a/tests/fate/spdif.mak b/tests/fate/spdif.mak
index 093b8138e8..85627b2241 100644
--- a/tests/fate/spdif.mak
+++ b/tests/fate/spdif.mak
@@ -24,6 +24,9 @@ fate-spdif-dca-master-core: CMD = md5 -i 
$(TARGET_SAMPLES)/dts/master_audio_7.1_
 FATE_SPDIF-$(call DEMMUX, EAC3, SPDIF) += fate-spdif-eac3
 fate-spdif-eac3: CMD = md5 -i 
$(TARGET_SAMPLES)/eac3/csi_miami_stereo_128_spx.eac3 -c copy -f spdif
 
+FATE_SPDIF_REMUX-$(call ALLYES, EAC3_DEMUXER EAC3_DECODER SPDIF_MUXER 
SPDIF_DEMUXER) += fate-spdif-eac3-remux
+fate-spdif-eac3-remux: CMD = transcode eac3 
$(TARGET_SAMPLES)/eac3/csi_miami_stereo_128_spx.eac3 spdif "-c copy" "-c copy"
+
 FATE_SPDIF-$(call DEMMUX, MLP, SPDIF) += fate-spdif-mlp
 fate-spdif-mlp: CMD = md5 -i 
$(TARGET_SAMPLES)/lossless-audio/luckynight-partial.mlp -c copy -f spdif
 
diff --git a/tests/ref/fate/spdif-eac3-remux b/tests/ref/fate/spdif-eac3-remux
new file mode 100644
index 00..43399fefba
--- /dev/null
+++ b/tests/ref/fate/spdif-eac3-remux
@@ -0,0 +1,659 @@
+b881db03eb6370e057645396d1880260 *tests/data/fate/spdif-eac3-remux.spdif
+16023552 tests/data/fate/spdif-eac3-remux.spdif
+#tb 0: 1/9
+#media_type 0: audio
+#codec_id 0: eac3
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,  0,  0, 2880,  352, 0x0ae5a595
+0,   2880,   2880, 2880,  512, 0x2beaf79f
+0,   5760,   5760, 2880,  512, 0x29ddf9d6
+0,   8640,   8640, 2880,  512, 0xba0afa79
+0,  11520,  11520, 2880,  512, 0xe019f394
+0,  14400,  14400, 2880,  512, 0xf501f5ab
+0,  17280,  17280, 2880,  512, 0x5ed3f35c
+0,  20160,  20160, 2880,  512, 0xb2a5f67b
+0,  23040,  23040, 2880,  512, 0xdab3f328
+0,  25920,  25920, 2880,  512, 0x490dfa2e
+0,  28800,  28800, 2880,  512, 0x26dffa1d
+0,  31680,  31680, 2880,  512, 0xa8daf5cd
+0,  34560,  34560, 2880,  512, 0x823a01e1
+0,  37440,  37440, 2880,  512, 0xf2feee89
+0,  40320,  40320, 2880,  512, 0x58f5ebe2
+0,  43200,  43200, 2880,  512, 0x8618f679
+0,  46080,  46080, 2880,  512, 0xfbe3f0e9
+0,  48960,  48960, 2880,  512, 0xadc3f479
+0,  51840,  51840, 2880,  512, 0xe85ef861
+0,  54720,  54720, 2880,  512, 0x788cf985
+0,  57600,  57600, 2880,  512, 0x44cf00c1
+0,  60480,  60480, 2880,  512, 0x3398fbf8
+0,  63360,  63360, 2880,  512, 0xfbfafc32
+0,  66240,  66240,  

Re: [FFmpeg-devel] [PATCH v3 08/11] lavc/vaapi_hevc: Pass SCC parameters Through VA-API

2023-01-10 Thread Wang, Fei W



> -Original Message-
> From: Wang, Fei W 
> Sent: Tuesday, January 3, 2023 9:00 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Linjie Fu ; Linjie Fu ; 
> Wang,
> Fei W 
> Subject: [FFmpeg-devel][PATCH v3 08/11] lavc/vaapi_hevc: Pass SCC parameters
> Through VA-API
> 
> From: Linjie Fu 
> 
> Including sps/pps/slice parameters.
> 
> Signed-off-by: Linjie Fu 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_hevc.c | 52 +
>  1 file changed, 47 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index
> 20fb36adfa..73a8f5b4ce 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -124,7 +124,7 @@ static int vaapi_hevc_start_frame(AVCodecContext
> *avctx,
>  const HEVCPPS  *pps = h->ps.pps;
> 
>  const ScalingList *scaling_list = NULL;
> -int pic_param_size, err, i;
> +int pic_param_size, num_comps, pre_palette_size, err, i;
> 
>  VAPictureParameterBufferHEVC *pic_param =
> (VAPictureParameterBufferHEVC *)&pic->pic_param;
> 
> @@ -245,8 +245,46 @@ static int vaapi_hevc_start_frame(AVCodecContext
> *avctx,
>  for (i = 0; i < 6; i++)
>  pic->pic_param.rext.cr_qp_offset_list[i]= 
> pps->cr_qp_offset_list[i];
>  }
> +
> +pre_palette_size = pps->pps_palette_predictor_initializers_present_flag ?
> +   pps->pps_num_palette_predictor_initializers :
> +   (sps->sps_palette_predictor_initializers_present_flag 
> ?
> +   sps->sps_num_palette_predictor_initializers_minus1 + 
> 1 :
> +   0);
> +
> +if (avctx->profile == FF_PROFILE_HEVC_SCC) {
> +pic->pic_param.scc = (VAPictureParameterBufferHEVCScc) {
> +.screen_content_pic_fields.bits = {
> +.pps_curr_pic_ref_enabled_flag  = pps-
> >pps_curr_pic_ref_enabled_flag,
> +.palette_mode_enabled_flag  = sps-
> >palette_mode_enabled_flag,
> +.motion_vector_resolution_control_idc   = sps-
> >motion_vector_resolution_control_idc,
> +.intra_boundary_filtering_disabled_flag = sps-
> >intra_boundary_filtering_disabled_flag,
> +.residual_adaptive_colour_transform_enabled_flag
> += pps-
> >residual_adaptive_colour_transform_enabled_flag,
> +.pps_slice_act_qp_offsets_present_flag  = pps-
> >pps_slice_act_qp_offsets_present_flag,
> +},
> +.palette_max_size   = 
> sps->palette_max_size,
> +.delta_palette_max_predictor_size   = sps-
> >delta_palette_max_predictor_size,
> +.predictor_palette_size = 
> pre_palette_size,
> +.pps_act_y_qp_offset_plus5  = pps-
> >residual_adaptive_colour_transform_enabled_flag ?
> +  
> pps->pps_act_y_qp_offset + 5 : 0,
> +.pps_act_cb_qp_offset_plus5 = pps-
> >residual_adaptive_colour_transform_enabled_flag ?
> +  
> pps->pps_act_cb_qp_offset + 5 : 0,
> +.pps_act_cr_qp_offset_plus3 = pps-
> >residual_adaptive_colour_transform_enabled_flag ?
> +  
> pps->pps_act_cr_qp_offset + 3 : 0,
> +};
> +
> +num_comps = pps->monochrome_palette_flag ? 1 : 3;
> +for (int comp = 0; comp < num_comps; comp++)
> +for (int j = 0; j < pre_palette_size; j++)
> +pic->pic_param.scc.predictor_palette_entries[comp][j] =
> +pps->pps_palette_predictor_initializers_present_flag ?
> +pps->pps_palette_predictor_initializer[comp][j]:
> +sps->sps_palette_predictor_initializer[comp][j];
> +}
> +
>  #endif
> -pic_param_size = avctx->profile == FF_PROFILE_HEVC_REXT ?
> +pic_param_size = avctx->profile >= FF_PROFILE_HEVC_REXT ?
>  sizeof(pic->pic_param) : 
> sizeof(VAPictureParameterBufferHEVC);
> 
>  err = ff_vaapi_decode_make_param_buffer(avctx, &pic->pic, @@ -299,7
> +337,7 @@ static int vaapi_hevc_end_frame(AVCodecContext *avctx)
>  VASliceParameterBufferHEVC *last_slice_param =
> (VASliceParameterBufferHEVC *)&pic->last_slice_param;
>  int ret;
> 
> -int slice_param_size = avctx->profile == FF_PROFILE_HEVC_REXT ?
> +int slice_param_size = avctx->profile >= FF_PROFILE_HEVC_REXT ?
>  sizeof(pic->last_slice_param) :
> sizeof(VASliceParameterBufferHEVC);
> 
>  if (pic->last_size) {
> @@ -413,7 +451,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext
> *avctx,
>  VAAPIDecodePictureHEVC *pic = h->ref->hwaccel_picture_private;
>  VASliceParame

Re: [FFmpeg-devel] [PATCH v3 10/11] lavc/vaapi_hevc: Set correct rps type for scc

2023-01-10 Thread Wang, Fei W
> -Original Message-
> From: Wang, Fei W 
> Sent: Tuesday, January 3, 2023 9:00 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Linjie Fu ; Linjie Fu ; 
> Wang,
> Fei W 
> Subject: [FFmpeg-devel][PATCH v3 10/11] lavc/vaapi_hevc: Set correct rps type
> for scc
> 
> From: Linjie Fu 
> 
> According to 8.1.3 and 8.3.2.
> 
> Signed-off-by: Linjie Fu 
> Signed-off-by: Fei Wang 
> ---
>  libavcodec/vaapi_hevc.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index
> c10617a81a..29c75e88f0 100644
> --- a/libavcodec/vaapi_hevc.c
> +++ b/libavcodec/vaapi_hevc.c
> @@ -71,6 +71,7 @@ static void fill_vaapi_pic(VAPictureHEVC *va_pic, const
> HEVCFrame *pic, int rps_  static int find_frame_rps_type(const HEVCContext *h,
> const HEVCFrame *pic)  {
>  VASurfaceID pic_surf = ff_vaapi_get_surface_id(pic->frame);
> +const HEVCFrame *current_picture = h->ref;
>  int i;
> 
>  for (i = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) { @@ -88,6 +89,9 @@ 
> static
> int find_frame_rps_type(const HEVCContext *h, const HEVCFrame *pic)
>  return VA_PICTURE_HEVC_RPS_LT_CURR;
>  }
> 
> +if (h->ps.pps->pps_curr_pic_ref_enabled_flag && current_picture->poc ==
> pic->poc)
> +return VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
> +

FATE test report fail in patchwork:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230103125952.2707824-10-fei.w.w...@intel.com/
make: *** [fate-hevc-conformance-PS_A_VIDYO_3] Error 1
cpu_flags(raw) = 0x000813DB
cpu_flags_str(raw) = mmx mmxext sse sse2 sse3 ssse3 sse4.1 sse4.2 cmov aesni
cpu_flags(effective) = 0x000813DB
cpu_flags_str(effective) = mmx mmxext sse sse2 sse3 ssse3 sse4.1 sse4.2 cmov 
aesni
threads = 1 (cpu_count = 5)
make: Target 'fate' not remade because of errors.

Checked locally, no this problem. The patch only change vaapi hevc decoder, 
should not cause the FATE fail(Only native decoder will be used in FATE?). 
Assume wrong report in patchwork. 

Thanks
Fei

>  return 0;
>  }
> 
> --
> 2.25.1

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

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


[FFmpeg-devel] [PATCH v2] lavf/rtpenc_jpeg: Retrieve sampling factor from SOF0

2023-01-10 Thread Yeoh, Hoong Tee
In ff_rtp_send_jpeg, the type is defined based on PIX_FMT and
color-range parsed in. There is limitation on current design
where need to include support newly introduced PIX_FMT such as
AV_PIX_FMT_QSV and there might be more and more in future. Hence,
retrive the sampling factor from SOF0 in JPEG compressed header
directly. This introduces flexibility to handle different type of
new codec introduced in future.

Signed-off-by: Yeoh, Hoong Tee 
---
 libavformat/rtpenc_jpeg.c | 41 +--
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/libavformat/rtpenc_jpeg.c b/libavformat/rtpenc_jpeg.c
index 9111683..53be188 100644
--- a/libavformat/rtpenc_jpeg.c
+++ b/libavformat/rtpenc_jpeg.c
@@ -30,7 +30,7 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t 
*buf, int size)
 RTPMuxContext *s = s1->priv_data;
 const uint8_t *qtables[4] = { NULL };
 int nb_qtables = 0;
-uint8_t type;
+uint8_t type = 2; /* initialized non-0/1 value for RTP/JPEG type check*/
 uint8_t w, h;
 uint8_t *p;
 int off = 0; /* fragment offset of the current JPEG frame */
@@ -45,20 +45,6 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t 
*buf, int size)
 w = AV_CEIL_RSHIFT(s1->streams[0]->codecpar->width, 3);
 h = AV_CEIL_RSHIFT(s1->streams[0]->codecpar->height, 3);
 
-/* get the pixel format type or fail */
-if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ422P ||
-(s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG &&
- s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV422P)) {
-type = 0;
-} else if (s1->streams[0]->codecpar->format == AV_PIX_FMT_YUVJ420P ||
-   (s1->streams[0]->codecpar->color_range == AVCOL_RANGE_JPEG &&
-s1->streams[0]->codecpar->format == AV_PIX_FMT_YUV420P)) {
-type = 1;
-} else {
-av_log(s1, AV_LOG_ERROR, "Unsupported pixel format\n");
-return;
-}
-
 /* preparse the header for getting some info */
 for (i = 0; i < size; i++) {
 if (buf[i] != 0xff)
@@ -90,6 +76,23 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t 
*buf, int size)
"Only 1x1 chroma blocks are supported. Aborted!\n");
 return;
 }
+
+   /*
+* Find out the sampling factor in SOF0.
+* In SOF0, hsample/vsample is inserted in form of (2<<4) | (type ? 
2 : 1).
+* First 4-bit is hsample while Last 4-bit is vsample.
+*/
+
+/* Luma channel sampling factor in 4:2:2 chroma subsampling are 
2x1 */
+if (buf[i + 11] == 33) {
+type = 0;
+/* Luma channel sampling factor in 4:2:0 chroma subsampling are 
2x2 */
+} else if (buf[i + 11] == 34) {
+type = 1;
+} else {
+av_log(s1, AV_LOG_ERROR, "Unsupported pixel format\n");
+return;
+}
 } else if (buf[i + 1] == DHT) {
 int dht_size = AV_RB16(&buf[i + 2]);
 default_huffman_tables |= 1 << 4;
@@ -163,6 +166,14 @@ void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t 
*buf, int size)
 break;
 }
 }
+
+/* Check validity of RTP/JPEG type */
+if (type != 0 && type != 1) {
+av_log(s1, AV_LOG_ERROR,
+"Invalid RTP/JPEG type\n");
+return;
+}
+
 if (default_huffman_tables && default_huffman_tables != 31) {
 av_log(s1, AV_LOG_ERROR,
"RFC 2435 requires standard Huffman tables for jpeg\n");
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH v3] lavc/libvpx: remove thread limit

2023-01-10 Thread James Zern
On Tue, Jan 10, 2023 at 2:47 AM myp...@gmail.com  wrote:
>
> On Thu, Jan 5, 2023 at 6:42 PM Dmitrii Ovchinnikov
>  wrote:
> [...]
> > diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> > index 9aa5510c28..0627e13973 100644
> > --- a/libavcodec/libvpxenc.c
> > +++ b/libavcodec/libvpxenc.c
> > @@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
> >  enccfg.g_timebase.num = avctx->time_base.num;
> >  enccfg.g_timebase.den = avctx->time_base.den;
> >  enccfg.g_threads  =
> > -FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 
> > 16);
> > +avctx->thread_count ? avctx->thread_count : av_cpu_count();
> >  enccfg.g_lag_in_frames= ctx->lag_in_frames;
> >
> Do you check the change with the old version libvpx?  as I know, older
> versions libvpx setting the number of threads higher than 16 will
> cause a crash, so I think at least a version check needs to be added
>

Do you have a bug or version in mind? There were some performance
regressions [1] over the releases and some issues with changing the
number of tiles, but I don't remember a crash for a high thread count
(though there have been plenty of crashes related to threads in
general [2]). The range check predates 1.4.0, which is the minimum
required by ffmpeg.

[1] https://crbug.com/webm/1574
[2] https://crbug.com/webm/851
___
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 v3 1/4] avcodec/bswapdsp: remove unused cextern

2023-01-10 Thread Mark Reid
On Tue, Jan 10, 2023 at 3:07 AM Anton Khirnov  wrote:

> Quoting Mark Reid (2023-01-06 19:09:10)
> > On Mon, Dec 26, 2022 at 1:31 PM Mark Reid  wrote:
> >
> > >
> > >
> > > On Mon, Dec 12, 2022 at 6:42 PM  wrote:
> > >
> > >> From: Mark Reid 
> > >>
> > >> ---
> > >>  libavcodec/x86/bswapdsp.asm | 2 --
> > >>  1 file changed, 2 deletions(-)
> > >>
> > >> diff --git a/libavcodec/x86/bswapdsp.asm b/libavcodec/x86/bswapdsp.asm
> > >> index 31c6c48a21..2aa235e13c 100644
> > >> --- a/libavcodec/x86/bswapdsp.asm
> > >> +++ b/libavcodec/x86/bswapdsp.asm
> > >> @@ -26,8 +26,6 @@
> > >>  SECTION_RODATA
> > >>  pb_bswap32: db 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12
> > >>
> > >> -cextern pb_80
> > >> -
> > >>  SECTION .text
> > >>
> > >>  ; %1 = aligned/unaligned
> > >> --
> > >> 2.31.1.windows.1
> > >>
> > >>
> > > ping
> > >
> >
> > ping
>
> Are you really duplicating a whole bunch of files from lavc in sws? I
> don't think that's anywhere remotely close to acceptable.
>
>
This was what I was suggested to do
http://ffmpeg.org/pipermail/ffmpeg-devel/2022-December/304667.html



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


[FFmpeg-devel] [PATCH v2] fate/imfdec: add audio test

2023-01-10 Thread pal
From: Pierre-Anthony Lemieux 

Improves the test material by using audio and video resources whose respective
temporal boundaries do not line up.

https://www.sandflow.com/public/countdown-audio-2023-01-10-2.zip

---
 tests/fate/imf.mak|   3 +
 tests/ref/fate/imf-cpl-with-audio | 207 ++
 2 files changed, 210 insertions(+)
 create mode 100644 tests/ref/fate/imf-cpl-with-audio

diff --git a/tests/fate/imf.mak b/tests/fate/imf.mak
index feb54d1361..49ab35e7d9 100644
--- a/tests/fate/imf.mak
+++ b/tests/fate/imf.mak
@@ -1,6 +1,9 @@
 FATE_IMF += fate-imf-cpl-with-repeat
 fate-imf-cpl-with-repeat: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown/CPL_bb2ce11c-1bb6-4781-8e69-967183d02b9b.xml 
-c:v copy
 
+FATE_IMF += fate-imf-cpl-with-audio
+fate-imf-cpl-with-audio: CMD = framecrc -f imf -i 
$(TARGET_SAMPLES)/imf/countdown-audio/CPL_688f4f63-a317-4271-99bf-51444ff39c5b.xml
 -c:a copy
+
 FATE_SAMPLES_FFMPEG-$(CONFIG_IMF_DEMUXER) += $(FATE_IMF)
 
 fate-imfdec: $(FATE_IMF)
diff --git a/tests/ref/fate/imf-cpl-with-audio 
b/tests/ref/fate/imf-cpl-with-audio
new file mode 100644
index 00..b8d70ca5d8
--- /dev/null
+++ b/tests/ref/fate/imf-cpl-with-audio
@@ -0,0 +1,207 @@
+#tb 0: 1/24
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x360
+#sar 0: 0/1
+#tb 1: 1/48000
+#media_type 1: audio
+#codec_id 1: pcm_s24le
+#sample_rate 1: 48000
+#channel_layout_name 1: stereo
+0,  0,  0,1,  1382400, 0x6a2c410c
+1,  0,  0, 1920,11520, 0x974f4bab
+1,   1920,   1920, 1920,11520, 0xdf793f69
+0,  1,  1,1,  1382400, 0x5f0c67d2
+1,   3840,   3840, 1920,11520, 0xfd69559a
+0,  2,  2,1,  1382400, 0x408e1262
+1,   5760,   5760, 1920,11520, 0x28fa469b
+0,  3,  3,1,  1382400, 0x3567d455
+1,   7680,   7680, 1920,11520, 0xe49161cf
+0,  4,  4,1,  1382400, 0x2312e68b
+1,   9600,   9600, 1920,11520, 0xb92c49ae
+0,  5,  5,1,  1382400, 0xe3d84ec2
+1,  11520,  11520, 1920,11520, 0xd2b75d46
+0,  6,  6,1,  1382400, 0xdbb3ab8c
+1,  13440,  13440, 1920,11520, 0xa13b5a9b
+0,  7,  7,1,  1382400, 0xeb250513
+1,  15360,  15360, 1920,11520, 0xfe804299
+0,  8,  8,1,  1382400, 0x26c3c8c0
+1,  17280,  17280, 1920,11520, 0x7a8654d4
+0,  9,  9,1,  1382400, 0xbc41a23e
+1,  19200,  19200, 1920,11520, 0x1a2e48a4
+0, 10, 10,1,  1382400, 0x49d6a8de
+1,  21120,  21120, 1920,11520, 0x20504669
+0, 11, 11,1,  1382400, 0x5e05cfa4
+1,  23040,  23040,  960, 5760, 0x74bf38f6
+0, 12, 12,1,  1382400, 0x01327a34
+1,  24000,  24000, 1920,11520, 0x974f4bab
+1,  25920,  25920, 1920,11520, 0xdf793f69
+0, 13, 13,1,  1382400, 0x06ce3c36
+1,  27840,  27840, 1920,11520, 0xfd69559a
+0, 14, 14,1,  1382400, 0x6aa24e6c
+1,  29760,  29760, 1920,11520, 0x28fa469b
+0, 15, 15,1,  1382400, 0x55d8b694
+1,  31680,  31680, 1920,11520, 0xe49161cf
+0, 16, 16,1,  1382400, 0xcc6f136d
+1,  33600,  33600, 1920,11520, 0xb92c49ae
+0, 17, 17,1,  1382400, 0xe92b6ce5
+1,  35520,  35520, 1920,11520, 0xd2b75d46
+0, 18, 18,1,  1382400, 0x664d30a1
+1,  37440,  37440, 1920,11520, 0xa13b5a9b
+0, 19, 19,1,  1382400, 0x09d80a1f
+1,  39360,  39360, 1920,11520, 0xfe804299
+0, 20, 20,1,  1382400, 0x2b58536e
+1,  41280,  41280, 1920,11520, 0x7a8654d4
+0, 21, 21,1,  1382400, 0xf24b7a34
+1,  43200,  43200, 1920,11520, 0x1a2e48a4
+0, 22, 22,1,  1382400, 0xe2a524c4
+1,  45120,  45120, 1920,11520, 0x20504669
+0, 23, 23,1,  1382400, 0xe841e6b7
+1,  47040,  47040, 1920,11520, 0x7ad44ba6
+0, 24, 24,1,  1382400, 0x6a2c410c
+1,  48960,  48960, 1920,11520, 0xc8934994
+0, 25, 25,1,  1382400, 0x5f0c67d2
+1,  50880,  50880, 1920,11520, 0x07ad70bb
+0, 26, 26,1,  1382400, 0x408e1262
+1,  52800,  52800, 1920,11520, 0x1ba75d9a
+0, 27, 27,1,  1382400, 0x3567d455
+1,  54720,  54720, 1920,11520, 0x0d4a435f
+0, 28, 28,1,  1382400, 0x2312e68b
+1,  56640,  56640, 1920,11520, 0x288b6c85
+0,

Re: [FFmpeg-devel] [PATCH 3/4] ffprobe: expose AVAmbientViewingEnvironment side data in AVFrames

2023-01-10 Thread James Almer

On 1/10/2023 6:19 PM, Jan Ekström wrote:

---
  fftools/ffprobe.c | 15 +++
  1 file changed, 15 insertions(+)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index d2f126d9d6..15c61e1c7c 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -33,6 +33,7 @@
  #include "libavformat/version.h"
  #include "libavcodec/avcodec.h"
  #include "libavcodec/version.h"
+#include "libavutil/ambient_viewing_environment.h"
  #include "libavutil/avassert.h"
  #include "libavutil/avstring.h"
  #include "libavutil/bprint.h"
@@ -2268,6 +2269,17 @@ static void print_dynamic_hdr_vivid(WriterContext *w, 
const AVDynamicHDRVivid *m
  }
  }
  
+static void print_ambient_viewing_environment(WriterContext *w,

+  const 
AVAmbientViewingEnvironment *env)
+{
+if (!env)
+return;
+
+print_q("ambient_illuminance", env->ambient_illuminance, '/');
+print_q("ambient_light_x", env->ambient_light_x, '/');
+print_q("ambient_light_y", env->ambient_light_y, '/');
+}
+
  static void print_pkt_side_data(WriterContext *w,
  AVCodecParameters *par,
  const AVPacketSideData *side_data,
@@ -2704,6 +2716,9 @@ static void show_frame(WriterContext *w, AVFrame *frame, 
AVStream *stream,
  } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
  AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
  print_dynamic_hdr_vivid(w, metadata);
+} else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
+print_ambient_viewing_environment(
+w, (const AVAmbientViewingEnvironment *)sd->data);
  }
  writer_print_section_footer(w);
  }


Should be ok.
___
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/4] avcodec/cbs_{h2645, sei}: add support for Ambient Viewing Environment SEI

2023-01-10 Thread James Almer

On 1/10/2023 6:19 PM, Jan Ekström wrote:

Defined by H.274, this SEI message is utilized by iPhones to save
the nominal ambient viewing environment for the display of recorded
HDR content.
---
  libavcodec/cbs_h2645.c   |  6 ++
  libavcodec/cbs_sei.h |  6 ++
  libavcodec/cbs_sei_syntax_template.c | 17 +
  3 files changed, 29 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 4ee06003c3..80e48829af 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1500,6 +1500,12 @@ static const SEIMessageTypeDescriptor 
cbs_sei_common_types[] = {
  sizeof(SEIRawAlternativeTransferCharacteristics),
  SEI_MESSAGE_RW(sei, alternative_transfer_characteristics),
  },
+{
+SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT,
+1, 0,
+sizeof(SEIRawAmbientViewingEnvironment),
+SEI_MESSAGE_RW(sei, ambient_viewing_environment),
+},
  SEI_MESSAGE_TYPE_END,
  };
  
diff --git a/libavcodec/cbs_sei.h b/libavcodec/cbs_sei.h

index c7a7a95be0..1c327a4689 100644
--- a/libavcodec/cbs_sei.h
+++ b/libavcodec/cbs_sei.h
@@ -65,6 +65,12 @@ typedef struct SEIRawAlternativeTransferCharacteristics {
  uint8_t preferred_transfer_characteristics;
  } SEIRawAlternativeTransferCharacteristics;
  
+typedef struct SEIRawAmbientViewingEnvironment {

+uint32_t ambient_illuminance;
+uint16_t ambient_light_x;
+uint16_t ambient_light_y;
+} SEIRawAmbientViewingEnvironment;
+
  typedef struct SEIRawMessage {
  uint32_t payload_type;
  uint32_t payload_size;
diff --git a/libavcodec/cbs_sei_syntax_template.c 
b/libavcodec/cbs_sei_syntax_template.c
index 0ef7b42ed9..6a7cc36dda 100644
--- a/libavcodec/cbs_sei_syntax_template.c
+++ b/libavcodec/cbs_sei_syntax_template.c
@@ -144,6 +144,23 @@ static int FUNC(alternative_transfer_characteristics)
  return 0;
  }
  
+static int FUNC(ambient_viewing_environment)

+(CodedBitstreamContext *ctx, RWContext *rw,
+ SEIRawAmbientViewingEnvironment *current,
+ SEIMessageState *state)
+{
+static const uint16_t max_ambient_light_value = 5;
+int err;
+
+HEADER("Ambient Viewing Environment");
+
+u(32, ambient_illuminance, 1, MAX_UINT_BITS(32));
+u(16, ambient_light_x, 0, max_ambient_light_value);
+u(16, ambient_light_y, 0, max_ambient_light_value);
+
+return 0;
+}
+
  static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
   SEIRawMessage *current)
  {


Should be ok.
___
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 4/4] avcodec/h2645_sei: add support for Ambient Viewing Environment SEI

2023-01-10 Thread James Almer

On 1/10/2023 6:19 PM, Jan Ekström wrote:

Defined by H.274, this SEI message is utilized by iPhones to save
the nominal ambient viewing environment for the display of recorded
HDR content. The contents of the message are exposed to API users
as AVFrame side data containing AVAmbientViewingEnvironment.

As the DV RPU test sample is from an iPhone and includes Ambient
Viewing Environment SEI messages, its test result gets updated.
---
  libavcodec/h2645_sei.c | 47 ++
  libavcodec/h2645_sei.h |  8 +++
  tests/ref/fate/hevc-dv-rpu | 12 ++
  3 files changed, 67 insertions(+)

diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 3ff89e4fdd..5083079cb1 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -25,6 +25,7 @@
  
  #include "config_components.h"
  
+#include "libavutil/ambient_viewing_environment.h"

  #include "libavutil/display.h"
  #include "libavutil/film_grain_params.h"
  #include "libavutil/pixdesc.h"
@@ -320,6 +321,31 @@ static int 
decode_alternative_transfer(H2645SEIAlternativeTransfer *s,
  return 0;
  }
  
+static int decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s,

+  GetByteContext *gb)
+{
+static const uint16_t max_ambient_light_value = 5;
+
+if (bytestream2_get_bytes_left(gb) < 8)
+return AVERROR_INVALIDDATA;
+
+s->ambient_illuminance = bytestream2_get_be32u(gb);
+if (!s->ambient_illuminance)
+return AVERROR_INVALIDDATA;
+
+s->ambient_light_x = bytestream2_get_be16u(gb);
+if (s->ambient_light_x > max_ambient_light_value)
+return AVERROR_INVALIDDATA;
+
+s->ambient_light_y = bytestream2_get_be16u(gb);
+if (s->ambient_light_y > max_ambient_light_value)
+return AVERROR_INVALIDDATA;
+
+s->present = 1;
+
+return 0;
+}
+
  static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics 
*h,
   enum AVCodecID codec_id, 
GetBitContext *gb)
  {
@@ -383,6 +409,9 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType 
type,
  return decode_frame_packing_arrangement(&h->frame_packing, gb, 
codec_id);
  case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
  return decode_alternative_transfer(&h->alternative_transfer, gbyte);
+case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT:
+return 
decode_ambient_viewing_environment(&h->ambient_viewing_environment,
+  gbyte);
  default:
  return FF_H2645_SEI_MESSAGE_UNHANDLED;
  }
@@ -609,6 +638,20 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
  avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
  }
  
+if (sei->ambient_viewing_environment.present) {

+H2645SEIAmbientViewingEnvironment *env =
+&sei->ambient_viewing_environment;
+
+AVAmbientViewingEnvironment *dst_env =
+av_ambient_viewing_environment_create_side_data(frame);
+if (!dst_env)
+return AVERROR(ENOMEM);
+
+dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 
1);
+dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 
5);
+dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 
5);
+}
+
  return 0;
  }
  
@@ -622,4 +665,8 @@ void ff_h2645_sei_reset(H2645SEI *s)

  av_freep(&s->unregistered.buf_ref);
  av_buffer_unref(&s->dynamic_hdr_plus.info);
  av_buffer_unref(&s->dynamic_hdr_vivid.info);
+
+s->ambient_viewing_environment = (H2645SEIAmbientViewingEnvironment){
+.present = 0


This is unnecessarily zeroing the whole struct by extension. Just set 
the one field alone.



+};
  }
diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h
index f3ee9af524..e07ae10376 100644
--- a/libavcodec/h2645_sei.h
+++ b/libavcodec/h2645_sei.h
@@ -76,6 +76,13 @@ typedef struct H2645SEIAlternativeTransfer {
  int preferred_transfer_characteristics;
  } H2645SEIAlternativeTransfer;
  
+typedef struct H2645SEIAmbientViewingEnvironment {

+int present;
+uint32_t ambient_illuminance;
+uint16_t ambient_light_x;
+uint16_t ambient_light_y;
+} H2645SEIAmbientViewingEnvironment;
+
  typedef struct H2645SEIFilmGrainCharacteristics {
  int present;
  int model_id;
@@ -108,6 +115,7 @@ typedef struct H2645SEI {
  H2645SEIDisplayOrientation display_orientation;
  H2645SEIAlternativeTransfer alternative_transfer;
  H2645SEIFilmGrainCharacteristics film_grain_characteristics;
+H2645SEIAmbientViewingEnvironment ambient_viewing_environment;
  } H2645SEI;
  
  enum {

diff --git a/tests/ref/fate/hevc-dv-rpu b/tests/ref/fate/hevc-dv-rpu
index 1980ab13ea..aaf0223eab 100644
--- a/tests/ref/fate/hevc-dv-rpu
+++ b/tests/ref/fate/hevc-dv-rpu
@@ -3,6 +3,12 @@
  side_data_type=H.26[45] User Data Unregistered SEI message
  [

Re: [FFmpeg-devel] [PATCH 2/4] avutil: introduce AVAmbientViewingEnvironment side data

2023-01-10 Thread James Almer

On 1/10/2023 6:19 PM, Jan Ekström wrote:

This enables exposing H.274 Ambient Viewing Environment
metadata in the framework.
---
  doc/APIchanges  |  6 +++
  libavutil/Makefile  |  2 +
  libavutil/ambient_viewing_environment.c | 51 ++
  libavutil/ambient_viewing_environment.h | 72 +
  libavutil/frame.c   |  1 +
  libavutil/frame.h   |  5 ++
  libavutil/version.h |  2 +-
  7 files changed, 138 insertions(+), 1 deletion(-)
  create mode 100644 libavutil/ambient_viewing_environment.c
  create mode 100644 libavutil/ambient_viewing_environment.h

diff --git a/doc/APIchanges b/doc/APIchanges
index 328028f293..f13b4f1149 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,12 @@ libavutil: 2021-04-27
  
  API changes, most recent first:
  
+2023-01-10 - xx - lavu 57.44.100 - ambient_viewing_environment.h


Mention frame.h here too.


+  Adds a new structure for holding H.274 Ambient Viewing Environment metadata,
+  AVAmbientViewingEnvironment.
+  Adds a new AVFrameSideDataType entry 
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
+  for it.
+
  2022-12-xx - xx - lavc 59.55.100 - avcodec.h
Add AV_HWACCEL_FLAG_UNSAFE_OUTPUT.
  
diff --git a/libavutil/Makefile b/libavutil/Makefile

index 3d9c07aea8..29b06665f5 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -4,6 +4,7 @@ DESC = FFmpeg utility library
  HEADERS = adler32.h \
aes.h \
aes_ctr.h \
+  ambient_viewing_environment.h \
attributes.h  \
audio_fifo.h  \
avassert.h\
@@ -102,6 +103,7 @@ BUILT_HEADERS = avconfig.h  
\
  OBJS = adler32.o\
 aes.o\
 aes_ctr.o\
+   ambient_viewing_environment.o\
 audio_fifo.o \
 avstring.o   \
 avsscanf.o   \
diff --git a/libavutil/ambient_viewing_environment.c 
b/libavutil/ambient_viewing_environment.c
new file mode 100644
index 00..e7d150796e
--- /dev/null
+++ b/libavutil/ambient_viewing_environment.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 Jan Ekström 
+ *
+ * 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
+ */
+
+#include 
+#include "ambient_viewing_environment.h"
+#include "frame.h"


Nit: no need for this one since it's included by the above header.


+#include "mem.h"
+
+AVAmbientViewingEnvironment *av_ambient_viewing_environment_alloc(size_t *size)
+{
+AVAmbientViewingEnvironment *env =
+av_mallocz(sizeof(AVAmbientViewingEnvironment));
+if (!env)
+return NULL;
+
+ if (size)
+*size = sizeof(*env);
+
+return env;
+}
+
+AVAmbientViewingEnvironment 
*av_ambient_viewing_environment_create_side_data(AVFrame *frame)
+{
+AVFrameSideData *side_data =
+av_frame_new_side_data(frame,
+   AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT,
+   sizeof(AVAmbientViewingEnvironment));
+if (!side_data)
+return NULL;
+
+memset(side_data->data, 0, side_data->size);
+
+return (AVAmbientViewingEnvironment *)side_data->data;
+}
diff --git a/libavutil/ambient_viewing_environment.h 
b/libavutil/ambient_viewing_environment.h
new file mode 100644
index 00..e5e4ac2173
--- /dev/null
+++ b/libavutil/ambient_viewing_environment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2023 Jan Ekström 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * m

[FFmpeg-devel] [PATCH 4/4] avcodec/h2645_sei: add support for Ambient Viewing Environment SEI

2023-01-10 Thread Jan Ekström
Defined by H.274, this SEI message is utilized by iPhones to save
the nominal ambient viewing environment for the display of recorded
HDR content. The contents of the message are exposed to API users
as AVFrame side data containing AVAmbientViewingEnvironment.

As the DV RPU test sample is from an iPhone and includes Ambient
Viewing Environment SEI messages, its test result gets updated.
---
 libavcodec/h2645_sei.c | 47 ++
 libavcodec/h2645_sei.h |  8 +++
 tests/ref/fate/hevc-dv-rpu | 12 ++
 3 files changed, 67 insertions(+)

diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 3ff89e4fdd..5083079cb1 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -25,6 +25,7 @@
 
 #include "config_components.h"
 
+#include "libavutil/ambient_viewing_environment.h"
 #include "libavutil/display.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/pixdesc.h"
@@ -320,6 +321,31 @@ static int 
decode_alternative_transfer(H2645SEIAlternativeTransfer *s,
 return 0;
 }
 
+static int 
decode_ambient_viewing_environment(H2645SEIAmbientViewingEnvironment *s,
+  GetByteContext *gb)
+{
+static const uint16_t max_ambient_light_value = 5;
+
+if (bytestream2_get_bytes_left(gb) < 8)
+return AVERROR_INVALIDDATA;
+
+s->ambient_illuminance = bytestream2_get_be32u(gb);
+if (!s->ambient_illuminance)
+return AVERROR_INVALIDDATA;
+
+s->ambient_light_x = bytestream2_get_be16u(gb);
+if (s->ambient_light_x > max_ambient_light_value)
+return AVERROR_INVALIDDATA;
+
+s->ambient_light_y = bytestream2_get_be16u(gb);
+if (s->ambient_light_y > max_ambient_light_value)
+return AVERROR_INVALIDDATA;
+
+s->present = 1;
+
+return 0;
+}
+
 static int decode_film_grain_characteristics(H2645SEIFilmGrainCharacteristics 
*h,
  enum AVCodecID codec_id, 
GetBitContext *gb)
 {
@@ -383,6 +409,9 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType 
type,
 return decode_frame_packing_arrangement(&h->frame_packing, gb, 
codec_id);
 case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
 return decode_alternative_transfer(&h->alternative_transfer, gbyte);
+case SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT:
+return 
decode_ambient_viewing_environment(&h->ambient_viewing_environment,
+  gbyte);
 default:
 return FF_H2645_SEI_MESSAGE_UNHANDLED;
 }
@@ -609,6 +638,20 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
 }
 
+if (sei->ambient_viewing_environment.present) {
+H2645SEIAmbientViewingEnvironment *env =
+&sei->ambient_viewing_environment;
+
+AVAmbientViewingEnvironment *dst_env =
+av_ambient_viewing_environment_create_side_data(frame);
+if (!dst_env)
+return AVERROR(ENOMEM);
+
+dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 
1);
+dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 
5);
+dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 
5);
+}
+
 return 0;
 }
 
@@ -622,4 +665,8 @@ void ff_h2645_sei_reset(H2645SEI *s)
 av_freep(&s->unregistered.buf_ref);
 av_buffer_unref(&s->dynamic_hdr_plus.info);
 av_buffer_unref(&s->dynamic_hdr_vivid.info);
+
+s->ambient_viewing_environment = (H2645SEIAmbientViewingEnvironment){
+.present = 0
+};
 }
diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h
index f3ee9af524..e07ae10376 100644
--- a/libavcodec/h2645_sei.h
+++ b/libavcodec/h2645_sei.h
@@ -76,6 +76,13 @@ typedef struct H2645SEIAlternativeTransfer {
 int preferred_transfer_characteristics;
 } H2645SEIAlternativeTransfer;
 
+typedef struct H2645SEIAmbientViewingEnvironment {
+int present;
+uint32_t ambient_illuminance;
+uint16_t ambient_light_x;
+uint16_t ambient_light_y;
+} H2645SEIAmbientViewingEnvironment;
+
 typedef struct H2645SEIFilmGrainCharacteristics {
 int present;
 int model_id;
@@ -108,6 +115,7 @@ typedef struct H2645SEI {
 H2645SEIDisplayOrientation display_orientation;
 H2645SEIAlternativeTransfer alternative_transfer;
 H2645SEIFilmGrainCharacteristics film_grain_characteristics;
+H2645SEIAmbientViewingEnvironment ambient_viewing_environment;
 } H2645SEI;
 
 enum {
diff --git a/tests/ref/fate/hevc-dv-rpu b/tests/ref/fate/hevc-dv-rpu
index 1980ab13ea..aaf0223eab 100644
--- a/tests/ref/fate/hevc-dv-rpu
+++ b/tests/ref/fate/hevc-dv-rpu
@@ -3,6 +3,12 @@
 side_data_type=H.26[45] User Data Unregistered SEI message
 [/SIDE_DATA]
 [SIDE_DATA]
+side_data_type=Ambient viewing environment
+ambient_illuminance=314/1
+ambient_light_x=15635/5
+ambient_light_y=16450/5
+[/SIDE_DATA]
+[SIDE_DATA]
 s

[FFmpeg-devel] [PATCH 3/4] ffprobe: expose AVAmbientViewingEnvironment side data in AVFrames

2023-01-10 Thread Jan Ekström
---
 fftools/ffprobe.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index d2f126d9d6..15c61e1c7c 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -33,6 +33,7 @@
 #include "libavformat/version.h"
 #include "libavcodec/avcodec.h"
 #include "libavcodec/version.h"
+#include "libavutil/ambient_viewing_environment.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
@@ -2268,6 +2269,17 @@ static void print_dynamic_hdr_vivid(WriterContext *w, 
const AVDynamicHDRVivid *m
 }
 }
 
+static void print_ambient_viewing_environment(WriterContext *w,
+  const 
AVAmbientViewingEnvironment *env)
+{
+if (!env)
+return;
+
+print_q("ambient_illuminance", env->ambient_illuminance, '/');
+print_q("ambient_light_x", env->ambient_light_x, '/');
+print_q("ambient_light_y", env->ambient_light_y, '/');
+}
+
 static void print_pkt_side_data(WriterContext *w,
 AVCodecParameters *par,
 const AVPacketSideData *side_data,
@@ -2704,6 +2716,9 @@ static void show_frame(WriterContext *w, AVFrame *frame, 
AVStream *stream,
 } else if (sd->type == AV_FRAME_DATA_DYNAMIC_HDR_VIVID) {
 AVDynamicHDRVivid *metadata = (AVDynamicHDRVivid *)sd->data;
 print_dynamic_hdr_vivid(w, metadata);
+} else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
+print_ambient_viewing_environment(
+w, (const AVAmbientViewingEnvironment *)sd->data);
 }
 writer_print_section_footer(w);
 }
-- 
2.39.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 2/4] avutil: introduce AVAmbientViewingEnvironment side data

2023-01-10 Thread Jan Ekström
This enables exposing H.274 Ambient Viewing Environment
metadata in the framework.
---
 doc/APIchanges  |  6 +++
 libavutil/Makefile  |  2 +
 libavutil/ambient_viewing_environment.c | 51 ++
 libavutil/ambient_viewing_environment.h | 72 +
 libavutil/frame.c   |  1 +
 libavutil/frame.h   |  5 ++
 libavutil/version.h |  2 +-
 7 files changed, 138 insertions(+), 1 deletion(-)
 create mode 100644 libavutil/ambient_viewing_environment.c
 create mode 100644 libavutil/ambient_viewing_environment.h

diff --git a/doc/APIchanges b/doc/APIchanges
index 328028f293..f13b4f1149 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,12 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2023-01-10 - xx - lavu 57.44.100 - ambient_viewing_environment.h
+  Adds a new structure for holding H.274 Ambient Viewing Environment metadata,
+  AVAmbientViewingEnvironment.
+  Adds a new AVFrameSideDataType entry 
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
+  for it.
+
 2022-12-xx - xx - lavc 59.55.100 - avcodec.h
   Add AV_HWACCEL_FLAG_UNSAFE_OUTPUT.
 
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 3d9c07aea8..29b06665f5 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -4,6 +4,7 @@ DESC = FFmpeg utility library
 HEADERS = adler32.h \
   aes.h \
   aes_ctr.h \
+  ambient_viewing_environment.h \
   attributes.h  \
   audio_fifo.h  \
   avassert.h\
@@ -102,6 +103,7 @@ BUILT_HEADERS = avconfig.h  
\
 OBJS = adler32.o\
aes.o\
aes_ctr.o\
+   ambient_viewing_environment.o\
audio_fifo.o \
avstring.o   \
avsscanf.o   \
diff --git a/libavutil/ambient_viewing_environment.c 
b/libavutil/ambient_viewing_environment.c
new file mode 100644
index 00..e7d150796e
--- /dev/null
+++ b/libavutil/ambient_viewing_environment.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 Jan Ekström 
+ *
+ * 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
+ */
+
+#include 
+#include "ambient_viewing_environment.h"
+#include "frame.h"
+#include "mem.h"
+
+AVAmbientViewingEnvironment *av_ambient_viewing_environment_alloc(size_t *size)
+{
+AVAmbientViewingEnvironment *env =
+av_mallocz(sizeof(AVAmbientViewingEnvironment));
+if (!env)
+return NULL;
+
+ if (size)
+*size = sizeof(*env);
+
+return env;
+}
+
+AVAmbientViewingEnvironment 
*av_ambient_viewing_environment_create_side_data(AVFrame *frame)
+{
+AVFrameSideData *side_data =
+av_frame_new_side_data(frame,
+   AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT,
+   sizeof(AVAmbientViewingEnvironment));
+if (!side_data)
+return NULL;
+
+memset(side_data->data, 0, side_data->size);
+
+return (AVAmbientViewingEnvironment *)side_data->data;
+}
diff --git a/libavutil/ambient_viewing_environment.h 
b/libavutil/ambient_viewing_environment.h
new file mode 100644
index 00..e5e4ac2173
--- /dev/null
+++ b/libavutil/ambient_viewing_environment.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2023 Jan Ekström 
+ *
+ * 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

[FFmpeg-devel] [PATCH 1/4] avcodec/cbs_{h2645, sei}: add support for Ambient Viewing Environment SEI

2023-01-10 Thread Jan Ekström
Defined by H.274, this SEI message is utilized by iPhones to save
the nominal ambient viewing environment for the display of recorded
HDR content.
---
 libavcodec/cbs_h2645.c   |  6 ++
 libavcodec/cbs_sei.h |  6 ++
 libavcodec/cbs_sei_syntax_template.c | 17 +
 3 files changed, 29 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 4ee06003c3..80e48829af 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1500,6 +1500,12 @@ static const SEIMessageTypeDescriptor 
cbs_sei_common_types[] = {
 sizeof(SEIRawAlternativeTransferCharacteristics),
 SEI_MESSAGE_RW(sei, alternative_transfer_characteristics),
 },
+{
+SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT,
+1, 0,
+sizeof(SEIRawAmbientViewingEnvironment),
+SEI_MESSAGE_RW(sei, ambient_viewing_environment),
+},
 SEI_MESSAGE_TYPE_END,
 };
 
diff --git a/libavcodec/cbs_sei.h b/libavcodec/cbs_sei.h
index c7a7a95be0..1c327a4689 100644
--- a/libavcodec/cbs_sei.h
+++ b/libavcodec/cbs_sei.h
@@ -65,6 +65,12 @@ typedef struct SEIRawAlternativeTransferCharacteristics {
 uint8_t preferred_transfer_characteristics;
 } SEIRawAlternativeTransferCharacteristics;
 
+typedef struct SEIRawAmbientViewingEnvironment {
+uint32_t ambient_illuminance;
+uint16_t ambient_light_x;
+uint16_t ambient_light_y;
+} SEIRawAmbientViewingEnvironment;
+
 typedef struct SEIRawMessage {
 uint32_t payload_type;
 uint32_t payload_size;
diff --git a/libavcodec/cbs_sei_syntax_template.c 
b/libavcodec/cbs_sei_syntax_template.c
index 0ef7b42ed9..6a7cc36dda 100644
--- a/libavcodec/cbs_sei_syntax_template.c
+++ b/libavcodec/cbs_sei_syntax_template.c
@@ -144,6 +144,23 @@ static int FUNC(alternative_transfer_characteristics)
 return 0;
 }
 
+static int FUNC(ambient_viewing_environment)
+(CodedBitstreamContext *ctx, RWContext *rw,
+ SEIRawAmbientViewingEnvironment *current,
+ SEIMessageState *state)
+{
+static const uint16_t max_ambient_light_value = 5;
+int err;
+
+HEADER("Ambient Viewing Environment");
+
+u(32, ambient_illuminance, 1, MAX_UINT_BITS(32));
+u(16, ambient_light_x, 0, max_ambient_light_value);
+u(16, ambient_light_y, 0, max_ambient_light_value);
+
+return 0;
+}
+
 static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
  SEIRawMessage *current)
 {
-- 
2.39.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".


Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

2023-01-10 Thread Paul B Mahol
On 1/10/23, Helmrich, Christian  wrote:
> Hi,
>
> please find attached a patch (relative to FFmpeg master as of early January
> 10, 2023)
> adding avfilter support for extended perceptually weighted peak
> signal-to-noise ratio
> (XPSNR) measurements for videos, as described in the related addition to
> filters.texi.
>
> The XPSNR code was originally vectorized using SIMD intrinsics, but we
> concluded that
> FFmpeg code requires asm instead of such intrinsics, so we let gcc
> auto-convert these

So its better to use that instead of human written assembly?
Does clang generate faster code without this asm?

> instructions to pure assembly; see the vf_xpsnr.asm file. If the added asm
> code is too
> lengthy, intrinsics would be possible, or something else is missing, please
> let us know.
>

Please remove SLICE_THREADS related flag as there is no call to
execute to filter in slices.
Please remove stdbool.h header and adapt code to compile without it.

> Best,
>
> Christian Helmrich and Christian Stoffers
> Fraunhofer HHI
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] ffmpeg: apply discontinuity adjustment per-stream

2023-01-10 Thread Michael Niedermayer
On Tue, Jan 03, 2023 at 03:52:17PM +0530, Gyan Doshi wrote:
> At present, the offset for discontinuity adjustment is applied per-file but
> the check for discontinuity is intra-stream so the same discontinuity when
> seen in multiple streams with copyts, leads to compounded adjustment of the
> discontinuity offset. This introduces gaps in streams, leading to loss of sync
> or even de facto loss of stream.
> 
> The ts_offset_discont parameter is transferred to InputStream and adjusted
> based on intra-stream gaps.
> ---
> Here's a simulated example to demonstrate the issue:
> 1) generate input
> ffmpeg -f lavfi -i nullsrc=s=32x32:r=1,format=gray -f lavfi -i 
> anullsrc=cl=mono:r=8000 -c:v libx264 -preset superfast -bf 0 -crf 50 -c:a aac 
> -b:a 64k -muxpreload 0 -muxdelay 0 -output_ts_offset 95000 -t 10 
> src-10s.ts
> 
> 2) demo
> ffmpeg -copyts -i "src-10.ts" -vf "showinfo=checksum=0" -af "ashowinfo" 
> -f null - -report
> 
> ==Before patch==
> 
> timestamp discontinuity for stream #0:1 (id=257, type=audio): -95443717689, 
> new offset= 95443717689
> timestamp discontinuity for stream #0:0 (id=256, type=video): -95443717689, 
> new offset= 190887435378
> 
> [Parsed_ashowinfo_0 @ 02700af98800] n:0 pts:759998976 pts_time:94999.9
> [Parsed_ashowinfo_0 @ 02700af98800] n:1 pts:76000 pts_time:95000
>  ... 
> [Parsed_ashowinfo_0 @ 02700af98800] n:745202 pts:1523085824 
> pts_time:190386
> [Parsed_ashowinfo_0 @ 02700af98800] n:745203 pts:1523086848 
> pts_time:190386
> [Parsed_ashowinfo_0 @ 02700af98800] n:745204 pts:2286637614 
> pts_time:285830
> [Parsed_ashowinfo_0 @ 02700af98800] n:745205 pts:2286638638 
> pts_time:285830
> 
> 
> [Parsed_showinfo_0 @ 02700ec34700] n:   0 pts:855000 pts_time:95000
> [Parsed_showinfo_0 @ 02700ec34700] n:   1 pts:855009 pts_time:95001
>  ... 
> [Parsed_showinfo_0 @ 02700ec34700] n:95380 pts:1713420 pts_time:190380
> [Parsed_showinfo_0 @ 02700ec34700] n:95381 pts:1713429 pts_time:190381
> [Parsed_showinfo_0 @ 02700ec34700] n:95382 pts:25724314592 pts_time:285826
> [Parsed_showinfo_0 @ 02700ec34700] n:95383 pts:25724404592 pts_time:285827
> 
> ==After patch==
> 
> timestamp discontinuity for stream #0:1 (id=257, type=audio): -95443717689, 
> new stream offset= 95443717689
> timestamp discontinuity for stream #0:0 (id=256, type=video): -95443717689, 
> new stream offset= 95443717689
> 
> [Parsed_ashowinfo_0 @ 023c773c8880] n:0 pts:759998976 pts_time:94999.9
> [Parsed_ashowinfo_0 @ 023c773c8880] n:1 pts:76000 pts_time:95000
>  ... 
> [Parsed_ashowinfo_0 @ 023c773c8880] n:745202 pts:1523085824 
> pts_time:190386
> [Parsed_ashowinfo_0 @ 023c773c8880] n:745203 pts:1523086848 
> pts_time:190386
> [Parsed_ashowinfo_0 @ 023c773c8880] n:745204 pts:1523087872 
> pts_time:190386
> [Parsed_ashowinfo_0 @ 023c773c8880] n:745205 pts:1523088896 
> pts_time:190386
> 
> 
> [Parsed_showinfo_0 @ 023c795d07c0] n:   0 pts:855000 pts_time:95000
> [Parsed_showinfo_0 @ 023c795d07c0] n:   1 pts:855009 pts_time:95001
>  ... 
> [Parsed_showinfo_0 @ 023c795d07c0] n:95380 pts:1713420 pts_time:190380
> [Parsed_showinfo_0 @ 023c795d07c0] n:95381 pts:1713429 pts_time:190381
> [Parsed_showinfo_0 @ 023c795d07c0] n:95382 pts:1713438 pts_time:190382
> [Parsed_showinfo_0 @ 023c795d07c0] n:95383 pts:1713447 pts_time:190383
> 
> 
> 
>  fftools/ffmpeg.c | 12 ++--
>  fftools/ffmpeg.h |  8 
>  2 files changed, 10 insertions(+), 10 deletions(-)

I havent looked into this but i have a slightly ungood feeling about this
change

thx

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

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato


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] ffmpeg: apply discontinuity adjustment per-stream

2023-01-10 Thread Gyan Doshi




On 2023-01-10 04:32 pm, Anton Khirnov wrote:

Quoting Gyan Doshi (2023-01-03 11:22:17)

At present, the offset for discontinuity adjustment is applied per-file but
the check for discontinuity is intra-stream so the same discontinuity when
seen in multiple streams with copyts, leads to compounded adjustment of the
discontinuity offset. This introduces gaps in streams, leading to loss of sync
or even de facto loss of stream.

The ts_offset_discont parameter is transferred to InputStream and adjusted
based on intra-stream gaps.

I never had much use for this feature, but I wonder if adding different
offsets to different streams isn't going against the whole point of
timestamps, which is synchronizing them.


A robust method would have to look at the inter-stream delta among first 
packets in each stream after the jump,

which neither the existing code nor my changes do.

The existing code compares dts against next_dts for the stream where the 
jump is first seen, and derives the offset from that.
That offset adjustment applied to all other streams may not preserve the 
inter-stream deltas for the packets after the jump
since inter-frame intervals in each stream will be different. In 
practice, the discrepancy is going to be minor, except for pathological

inputs.

But this patch avoids the compounded adjustment currently being applied, 
which makes the output defunct, or worse frozen and

a CPU/memory hog if video encoding is CFR.

Regards,
Gyan

___
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/vf_cropdetect: add ability to change limit/reset at runtime

2023-01-10 Thread Paul B Mahol
On 1/10/23, Jeffrey CHAPUIS  wrote:
> Hello,
> I decided to continue on a simpler path without 'reset/reset_count', it was
> only to experiment anyway, 'limit' is the main goal.
> 'limit' is added to the metadata to control that the result is associated to
> a change at runtime, it's after scaling with bitdetph but that's not really
> a problem (at least for me, we can always store the parameter before any
> alteration).
>
>>+if (!strcmp(cmd, "limit")) {
>>+if (s->limit < 1.0)
>>+s->limit *= (1 << s->bitdepth) - 1;
>>+s->frame_nb = s->reset_count;
>>+}
> Should i remove the if statement here ? or keep it for future change
> eventually.

Split variables, keep one variable settable by user and unchanged by filter.

>
> Notes I didn't think about?
>
> Thunderbird altered the patch somehow (remove empty new lines), it's edited
> manually.

Attach patch instead.


Avoid using strcmp to check for this variable change, instead check
with previous and new value in process function.

>
> Signed-off-by: Ashyni 
> ---
>  doc/filters.texi   | 12 +
>  libavfilter/vf_cropdetect.c| 32 ++--
>  tests/ref/fate/filter-metadata-cropdetect  | 60 +++---
>  tests/ref/fate/filter-metadata-cropdetect1 | 14 ++---
>  tests/ref/fate/filter-metadata-cropdetect2 | 14 ++---
>  5 files changed, 84 insertions(+), 48 deletions(-)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 9c3233914..0fc562409 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -10560,6 +10560,18 @@ ffmpeg -flags2 +export_mvs -i file.mp4 -vf
> cropdetect=mode=mvedges,metadata=mode
>  @end example
>  @end itemize
>
> +@subsection Commands
> +
> +This filter supports the following commands:
> +@table @option
> +@item limit
> +
> +The command accepts the same syntax of the corresponding option.
> +
> +If the specified expression is not valid, it is kept at its current
> +value.
> +@end table
> +
>  @anchor{cue}
>  @section cue
>
>  diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
> index 7e985fb27..1e752192d 100644
> --- a/libavfilter/vf_cropdetect.c
> +++ b/libavfilter/vf_cropdetect.c
> @@ -48,6 +48,7 @@ typedef struct CropDetectContext {
>  int mode;
>  int window_size;
>  int mv_threshold;
> +int bitdepth;
>  float   low, high;
>  uint8_t low_u8, high_u8;
>  uint8_t  *filterbuf;
> @@ -207,8 +208,10 @@ static int config_input(AVFilterLink *inlink)
>
>  av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc);
>
> +s->bitdepth = desc->comp[0].depth;
> +
>  if (s->limit < 1.0)
> -s->limit *= (1 << desc->comp[0].depth) - 1;
> +s->limit *= (1 << s->bitdepth) - 1;
>
>  s->x1 = inlink->w - 1;
>  s->y1 = inlink->h - 1;
> @@ -422,22 +425,42 @@ static int filter_frame(AVFilterLink *inlink, AVFrame
> *frame)
>  SET_META("lavfi.cropdetect.h",  h);
>  SET_META("lavfi.cropdetect.x",  x);
>  SET_META("lavfi.cropdetect.y",  y);
> +SET_META("lavfi.cropdetect.limit", limit);
>
>  av_log(ctx, AV_LOG_INFO,
> -   "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d pts:%"PRId64"
> t:%f crop=%d:%d:%d:%d\n",
> +   "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d pts:%"PRId64"
> t:%f limit:%d crop=%d:%d:%d:%d\n",
> s->x1, s->x2, s->y1, s->y2, w, h, x, y, frame->pts,
> frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts *
> av_q2d(inlink->time_base),
> -   w, h, x, y);
> +   limit, w, h, x, y);
>  }
>
>  return ff_filter_frame(inlink->dst->outputs[0], frame);
>  }
>
> +static int process_command(AVFilterContext *ctx, const char *cmd, const
> char *args,
> +   char *res, int res_len, int flags)
> +{
> +CropDetectContext *s = ctx->priv;
> +int ret;
> +
> +if ((ret = ff_filter_process_command(ctx, cmd, args, res, res_len,
> flags)) < 0)
> +return ret;
> +
> +if (!strcmp(cmd, "limit")) {
> +if (s->limit < 1.0)
> +s->limit *= (1 << s->bitdepth) - 1;
> +s->frame_nb = s->reset_count;
> +}
> +
> +return 0;
> +}
> +
>  #define OFFSET(x) offsetof(CropDetectContext, x)
>  #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM |
> AV_OPT_FLAG_RUNTIME_PARAM
>
>  static const AVOption cropdetect_options[] = {
> -{ "limit", "Threshold below which the pixel is considered black",
> OFFSET(limit),   AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, FLAGS
> },
> +{ "limit", "Threshold below which the pixel is considered black",
> OFFSET(limit),   AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535,
> TFLAGS },
>  { "round", "Value by which the width/height should be divisible",
> OFFSET(round),   AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
>  { "reset", "Recalculate the crop area after this many fr

[FFmpeg-devel] [PATCH 2/2] fate: update test reference data to include AV_PKT_FLAG_FIXED_DURATION

2023-01-10 Thread Miguel Borges de Freitas
From: Miguel Borges de Freitas 

Updates some of the test reference data to include the new
AV_PKT_FLAG_FIXED_DURATION (this is the case for most matroska
subtitles)

Signed-off-by: Miguel Borges de Freitas 
---
 tests/ref/fate/matroska-dvbsub-remux   | 84 ++--
 tests/ref/fate/matroska-zero-length-block  |  4 +-
 tests/ref/fate/matroska-zlib-decompression |  2 +-
 tests/ref/fate/shortest-sub| 92 +++---
 4 files changed, 91 insertions(+), 91 deletions(-)

diff --git a/tests/ref/fate/matroska-dvbsub-remux 
b/tests/ref/fate/matroska-dvbsub-remux
index b7346b8f55..16e5ce9a34 100644
--- a/tests/ref/fate/matroska-dvbsub-remux
+++ b/tests/ref/fate/matroska-dvbsub-remux
@@ -8,45 +8,45 @@
 #tb 1: 1/1000
 #media_type 1: subtitle
 #codec_id 1: dvb_subtitle
-0,  0,  0,  280,   14, 0x05f400e1
-1,  0,  0,0,   14, 0x05f400e1
-0,280,280, 5000,   14, 0x066400f1
-1,280,280,0,   14, 0x066400f1
-0,   5280,   5280, 5020,   14, 0x06d40101
-1,   5280,   5280,0,   14, 0x06d40101
-0,  10300,  10300, 3600,   14, 0x07440111
-1,  10300,  10300,0,   14, 0x07440111
-0,  13900,  13900,  220,   14, 0x07b40121
-1,  13900,  13900,0,   14, 0x07b40121
-0,  14120,  14120, 1440,   14, 0x08240131
-1,  14120,  14120,0,   14, 0x08240131
-0,  15560,  15560,   40,   14, 0x08940141
-1,  15560,  15560,0,   14, 0x08940141
-0,  15600,  15600,  160,  944, 0x454c0939
-1,  15600,  15600,0,  944, 0x454c0939
-0,  15760,  15760,  240,  630, 0x49dbb35f
-1,  15760,  15760,0,  630, 0x49dbb35f
-0,  16000,  16000,  340,  344, 0xb1eb63ed
-1,  16000,  16000,0,  344, 0xb1eb63ed
-0,  16340,  16340,  600,  966, 0xb8a61edf
-1,  16340,  16340,0,  966, 0xb8a61edf
-0,  16940,  16940,  460,  470, 0x80597fba
-1,  16940,  16940,0,  470, 0x80597fba
-0,  17400,  17400,  360, 1212, 0x554768d6
-1,  17400,  17400,0, 1212, 0x554768d6
-0,  17760,  17760,  220, 4804, 0xab67ddbe
-1,  17760,  17760,0, 4804, 0xab67ddbe
-0,  17980,  17980,  960, 1016, 0x15e42d56
-1,  17980,  17980,0, 1016, 0x15e42d56
-0,  18940,  18940,  220,  456, 0x57917e6f
-1,  18940,  18940,0,  456, 0x57917e6f
-0,  19160,  19160,  260,  830, 0xcff3efde
-1,  19160,  19160,0,  830, 0xcff3efde
-0,  19420,  19420,  100,  860, 0xd89903b6
-1,  19420,  19420,0,  860, 0xd89903b6
-0,  19520,  19520,  220, 4426, 0x01eb43f1
-1,  19520,  19520,0, 4426, 0x01eb43f1
-0,  19740,  19740,  220, 1132, 0xedda51a8
-1,  19740,  19740,0, 1132, 0xedda51a8
-0,  19960,  19960,0,  466, 0x9c957e09
-1,  19960,  19960,0,  466, 0x9c957e09
+0,  0,  0,  280,   14, 0x05f400e1, F=0x21
+1,  0,  0,0,   14, 0x05f400e1, F=0x21
+0,280,280, 5000,   14, 0x066400f1, F=0x21
+1,280,280,0,   14, 0x066400f1, F=0x21
+0,   5280,   5280, 5020,   14, 0x06d40101, F=0x21
+1,   5280,   5280,0,   14, 0x06d40101, F=0x21
+0,  10300,  10300, 3600,   14, 0x07440111, F=0x21
+1,  10300,  10300,0,   14, 0x07440111, F=0x21
+0,  13900,  13900,  220,   14, 0x07b40121, F=0x21
+1,  13900,  13900,0,   14, 0x07b40121, F=0x21
+0,  14120,  14120, 1440,   14, 0x08240131, F=0x21
+1,  14120,  14120,0,   14, 0x08240131, F=0x21
+0,  15560,  15560,   40,   14, 0x08940141, F=0x21
+1,  15560,  15560,0,   14, 0x08940141, F=0x21
+0,  15600,  15600,  160,  944, 0x454c0939, F=0x21
+1,  15600,  15600,0,  944, 0x454c0939, F=0x21
+0,  15760,  15760,  240,  630, 0x49dbb35f, F=0x21
+1,  15760,  15760,0,  630, 0x49dbb35f, F=0x21
+0,  16000,  16000,  340,  344, 0xb1eb63ed, F=0x21
+1,  16000,  16000,0,  344, 0xb1eb63ed, F=0x21
+0,  16340,  16340,  600,  966, 0xb8a61edf, F=0x21
+1,  16340,  16340,0,  966, 0xb8a61edf, F=0x21
+0,  16940,  16940,  460,  470, 0x80597fba, F=0x21
+1,  16940,  16940,0,  470, 0x80597fba, F=0x21
+0,  17400,  17400,  360, 1212, 0x554768d6, F=0x21
+1,  17400,  17400,0, 

[FFmpeg-devel] [PATCH 1/2] libavformat/matroskadec: set fixed duration for subtitles

2023-01-10 Thread Miguel Borges de Freitas
From: Miguel Borges de Freitas 

The matroska specification states the start time and duration of
subtitle entries are encoded in the block TimeStamp
and BlockDuration. Furthermore, for all subtitle formats except
S_HDMV/PGS the BlockDuration must always be defined and have an
absolute value even if it is simply 0. ffmpeg assumes that a duration
of 0 means the duration is still unknown and tries to adjust based on
the next packet pts. This is wrong for all formats except S_HDMV/PGS.
Since changing the semantics of duration 0 is not an option (touches
too many parts of the code) this change introduces
AV_PKT_FLAG_FIXED_DURATION flag which decoders might use to flag the
duration of a given packet should not be changed.

Signed-off-by: Miguel Borges de Freitas 
---
 libavcodec/packet.h   | 5 +
 libavformat/demux.c   | 3 ++-
 libavformat/matroskadec.c | 4 
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index f28e7e7011..699dcc6f79 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -446,6 +446,11 @@ typedef struct AVPacketList {
  * be discarded by the decoder.  I.e. Non-reference frames.
  */
 #define AV_PKT_FLAG_DISPOSABLE 0x0010
+/**
+ * Flag is used to indicate packets in which the duration is absolute
+ * and should not be changed.
+ */
+#define AV_PKT_FLAG_FIXED_DURATION 0x0020
 
 enum AVSideDataParamChangeFlags {
 #if FF_API_OLD_CHANNEL_LAYOUT
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2dfd82a63c..471be5d3dd 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -914,7 +914,8 @@ static void update_initial_durations(AVFormatContext *s, 
AVStream *st,
 pktl->pkt.dts = cur_dts;
 if (!sti->avctx->has_b_frames)
 pktl->pkt.pts = cur_dts;
-pktl->pkt.duration = duration;
+if ((pktl->pkt.flags & AV_PKT_FLAG_FIXED_DURATION) != 
AV_PKT_FLAG_FIXED_DURATION)
+pktl->pkt.duration = duration;
 } else
 break;
 cur_dts = pktl->pkt.dts + pktl->pkt.duration;
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d582f566a2..e887f43e1a 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3673,6 +3673,10 @@ static int matroska_parse_frame(MatroskaDemuxContext 
*matroska,
 pkt->pos = pos;
 pkt->duration = lace_duration;
 
+if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && 
+st->codecpar->codec_id != AV_CODEC_ID_HDMV_PGS_SUBTITLE)
+pkt->flags |= AV_PKT_FLAG_FIXED_DURATION;
+
 res = avpriv_packet_list_put(&matroska->queue, pkt, NULL, 0);
 if (res < 0) {
 av_packet_unref(pkt);
-- 
ffmpeg-codebot

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

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


[FFmpeg-devel] [PATCH 0/2] libavformat/matroskadec: set fixed duration for subtitles

2023-01-10 Thread ffmpegagent
The matroska specification states the start time and duration of subtitle
entries are encoded in the block TimeStamp and BlockDuration. Furthermore,
for all subtitle formats except S_HDMV/PGS the BlockDuration must always be
defined and have an absolute value even if it is simply 0. ffmpeg assumes
that a duration of 0 means the duration is still unknown and tries to adjust
based on the next packet pts. This is wrong for all formats except
S_HDMV/PGS. Since changing the semantics of duration 0 is not an option
(touches too many parts of the code) this change introduces
AV_PKT_FLAG_FIXED_DURATION flag which decoders might use to flag the
duration of a given packet should not be changed.

Signed-off-by: Miguel Borges de Freitas ene...@kodi.tv



This is my attempt at fixing https://trac.ffmpeg.org/ticket/10135 Initially
reported to Kodi in https://github.com/xbmc/xbmc/issues/21625

Miguel Borges de Freitas (2):
  libavformat/matroskadec: set fixed duration for subtitles
  fate: update test reference data to include AV_PKT_FLAG_FIXED_DURATION

 libavcodec/packet.h|  5 ++
 libavformat/demux.c|  3 +-
 libavformat/matroskadec.c  |  4 +
 tests/ref/fate/matroska-dvbsub-remux   | 84 ++--
 tests/ref/fate/matroska-zero-length-block  |  4 +-
 tests/ref/fate/matroska-zlib-decompression |  2 +-
 tests/ref/fate/shortest-sub| 92 +++---
 7 files changed, 102 insertions(+), 92 deletions(-)


base-commit: 94aa70d757af6b0e0919250f9def2a819aa00358
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-48%2Fenen92%2Fass_mkv_fixed_subs-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-48/enen92/ass_mkv_fixed_subs-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/48
-- 
ffmpeg-codebot
___
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/2] avcodec/mediacodec_wrapper: get api level via NDK method

2023-01-10 Thread Tomas Härdin
tis 2023-01-10 klockan 19:30 +0800 skrev Zhao Zhili:
> From: Zhao Zhili 
> 
> android_get_device_api_level() is a static inline before API level
> 29. It was implemented via __system_property_get(). We can do the
> same thing, but I don't want to mess up with __system_property_get.
> ---
>  libavcodec/mediacodec_wrapper.c | 18 ++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/libavcodec/mediacodec_wrapper.c
> b/libavcodec/mediacodec_wrapper.c
> index 4d6e9487b8..34ec2134aa 100644
> --- a/libavcodec/mediacodec_wrapper.c
> +++ b/libavcodec/mediacodec_wrapper.c
> @@ -2513,6 +2513,21 @@ FFAMediaCodec*
> ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk
>  int ff_Build_SDK_INT(AVCodecContext *avctx)
>  {
>  int ret = -1;
> +
> +#if __ANDROID_API__ >= 24
> +    // android_get_device_api_level() is a static inline before API
> level 29.
> +    // dlsym() might doesn't work.
> +    //
> +    // We can implement android_get_device_api_level() by
> +    // __system_property_get(), but __system_property_get() has
> created a lot of
> +    // troubles and is deprecated. So avoid using
> __system_property_get() for
> +    // now.
> +    //
> +    // Hopy we can remove the conditional compilation finally by
> bumping the
> +    // required API level.
> +    //
> +    ret = android_get_device_api_level();
> +#else
>  JNIEnv *env = NULL;
>  jclass versionClass;
>  jfieldID sdkIntFieldID;
> @@ -2522,5 +2537,8 @@ int ff_Build_SDK_INT(AVCodecContext *avctx)
>  sdkIntFieldID = (*env)->GetStaticFieldID(env, versionClass,
> "SDK_INT", "I");
>  ret = (*env)->GetStaticIntField(env, versionClass,
> sdkIntFieldID);
>  (*env)->DeleteLocalRef(env, versionClass);
> +#endif
> +    av_log(avctx, AV_LOG_DEBUG, "device api level %d\n", ret);
> +
>  return ret;
>  }

Looks OK

/Tomas


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

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


Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec/mediacodecdec: check ff_Build_SDK_INT return value

2023-01-10 Thread Tomas Härdin
tis 2023-01-10 klockan 19:35 +0800 skrev Zhao Zhili:
> From: Zhao Zhili 
> 
> ---
> v3: when target API <= 24 ==> when target API < 24
> v2: add comments
> 
>  libavcodec/mediacodecdec.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> index 11f655a9aa..21464900d1 100644
> --- a/libavcodec/mediacodecdec.c
> +++ b/libavcodec/mediacodecdec.c
> @@ -415,7 +415,13 @@ static av_cold int
> mediacodec_decode_init(AVCodecContext *avctx)
>     s->ctx->codec_name, ret);
>  
>  sdk_int = ff_Build_SDK_INT(avctx);
> -    if (sdk_int <= 23 &&
> +    /* ff_Build_SDK_INT can fail when target API < 24 and JVM isn't
> available.
> + * If we don't check sdk_int > 0, the workaround might be
> enabled by
> + * mistake.
> + * JVM is required to make the workaround works reliably. On the
> other hand,
> + * missing a workaround should not be a serious issue, we do as
> best we can.
> + */
> +    if (sdk_int > 0 && sdk_int <= 23 &&
>  strcmp(s->ctx->codec_name,
> "OMX.amlogic.mpeg2.decoder.awesome") == 0) {
>  av_log(avctx, AV_LOG_INFO, "Enabling workaround for %s on
> API=%d\n",
>     s->ctx->codec_name, sdk_int);

Looks OK

/Tomas

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

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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_cropdetect: add ability to change limit/reset at runtime

2023-01-10 Thread Jeffrey CHAPUIS
Hello,
I decided to continue on a simpler path without 'reset/reset_count', it was 
only to experiment anyway, 'limit' is the main goal.
'limit' is added to the metadata to control that the result is associated to a 
change at runtime, it's after scaling with bitdetph but that's not really a 
problem (at least for me, we can always store the parameter before any 
alteration).

>+if (!strcmp(cmd, "limit")) {
>+if (s->limit < 1.0)
>+s->limit *= (1 << s->bitdepth) - 1;
>+s->frame_nb = s->reset_count;
>+}
Should i remove the if statement here ? or keep it for future change eventually.

Notes I didn't think about?

Thunderbird altered the patch somehow (remove empty new lines), it's edited 
manually.

Signed-off-by: Ashyni 
---
 doc/filters.texi   | 12 +
 libavfilter/vf_cropdetect.c| 32 ++--
 tests/ref/fate/filter-metadata-cropdetect  | 60 +++---
 tests/ref/fate/filter-metadata-cropdetect1 | 14 ++---
 tests/ref/fate/filter-metadata-cropdetect2 | 14 ++---
 5 files changed, 84 insertions(+), 48 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 9c3233914..0fc562409 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -10560,6 +10560,18 @@ ffmpeg -flags2 +export_mvs -i file.mp4 -vf 
cropdetect=mode=mvedges,metadata=mode
 @end example
 @end itemize

+@subsection Commands
+
+This filter supports the following commands:
+@table @option
+@item limit
+
+The command accepts the same syntax of the corresponding option.
+
+If the specified expression is not valid, it is kept at its current
+value.
+@end table
+
 @anchor{cue}
 @section cue

 diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c
index 7e985fb27..1e752192d 100644
--- a/libavfilter/vf_cropdetect.c
+++ b/libavfilter/vf_cropdetect.c
@@ -48,6 +48,7 @@ typedef struct CropDetectContext {
 int mode;
 int window_size;
 int mv_threshold;
+int bitdepth;
 float   low, high;
 uint8_t low_u8, high_u8;
 uint8_t  *filterbuf;
@@ -207,8 +208,10 @@ static int config_input(AVFilterLink *inlink)

 av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc);

+s->bitdepth = desc->comp[0].depth;
+ 
 if (s->limit < 1.0)
-s->limit *= (1 << desc->comp[0].depth) - 1;
+s->limit *= (1 << s->bitdepth) - 1;

 s->x1 = inlink->w - 1;
 s->y1 = inlink->h - 1;
@@ -422,22 +425,42 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
*frame)
 SET_META("lavfi.cropdetect.h",  h);
 SET_META("lavfi.cropdetect.x",  x);
 SET_META("lavfi.cropdetect.y",  y);
+SET_META("lavfi.cropdetect.limit", limit);

 av_log(ctx, AV_LOG_INFO,
-   "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d pts:%"PRId64" t:%f 
crop=%d:%d:%d:%d\n",
+   "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d pts:%"PRId64" t:%f 
limit:%d crop=%d:%d:%d:%d\n",
s->x1, s->x2, s->y1, s->y2, w, h, x, y, frame->pts,
frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * 
av_q2d(inlink->time_base),
-   w, h, x, y);
+   limit, w, h, x, y);
 }

 return ff_filter_frame(inlink->dst->outputs[0], frame);
 }

+static int process_command(AVFilterContext *ctx, const char *cmd, const char 
*args,
+   char *res, int res_len, int flags)
+{
+CropDetectContext *s = ctx->priv;
+int ret;
+
+if ((ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags)) 
< 0)
+return ret;
+
+if (!strcmp(cmd, "limit")) {
+if (s->limit < 1.0)
+s->limit *= (1 << s->bitdepth) - 1;
+s->frame_nb = s->reset_count;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(CropDetectContext, x)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | 
AV_OPT_FLAG_RUNTIME_PARAM

 static const AVOption cropdetect_options[] = {
-{ "limit", "Threshold below which the pixel is considered black", 
OFFSET(limit),   AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, FLAGS },
+{ "limit", "Threshold below which the pixel is considered black", 
OFFSET(limit),   AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, TFLAGS },
 { "round", "Value by which the width/height should be divisible", 
OFFSET(round),   AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
 { "reset", "Recalculate the crop area after this many frames",
OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, FLAGS },
 { "skip",  "Number of initial frames to skip",
OFFSET(skip),AV_OPT_TYPE_INT, { .i64 = 2 },  0, INT_MAX, FLAGS },
@@ -481,4 +504,5 @@ const AVFilter ff_vf_cropdetect = {
 FILTER_OUTPUTS(avfilter_vf_cropdetect_outputs),
 FILTER_PIXFMTS_ARRAY(pix_fmts),
 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | 
AVFILTER_FLAG_METADATA_ONLY,
+.process_

Re: [FFmpeg-devel] [PATCH v1 00/11] Add support for H266/VVC

2023-01-10 Thread myp...@gmail.com
On Tue, Jan 10, 2023 at 10:56 AM Nuo Mi  wrote:
>
> Hi Thomas
> It works for me.
>
> BTW, I will send out a C version of VVC native decoder very soon.
> Please also help review and improve it.
> Thank you.
Ha, it's great news
>
> On Tue, Jan 3, 2023 at 10:02 PM Thomas Siedel 
> wrote:
>
> > On Thu, 15 Dec 2022 at 10:11, Thomas Siedel 
> > wrote:
> >
> >> On Tue, 13 Dec 2022 at 07:19, Nuo Mi  wrote:
> >>
> >>> Hi Thomas,
> >>> Thank you for sending the patch set.
> >>> It seems the patchset is based on
> >>> https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=3487
> >>> Please do not change the author's name.
> >>>
> >>> thank you
> >>>
> >>
> >> Some code regarding VVC parsing is based on another FFmpeg fork. This
> >> fork had been based on your patch set, it seems.
> >> On top of this, I did additional modifications to the parsing code and
> >> added the other code regarding format support and the decoder and encoder
> >> integration.
> >>
> >> It was not my intent to hide you as an author of the parsing code.
> >> Your patch set has been in an unmerged state for over 1.5 years now
> >> without new progress, so I assumed that these patches are kind of
> >> discontinued.
> >> Therefore I started submitting my own patchset to get VVC integrated into
> >> FFmpeg.
> >> I kept your original copyright notices in libavformat/vvcdec.c and
> >> livavcodec/vvc_parser.c.
> >> Apart from this, I am not sure how / where else this could be documented
> >> and how other authors can be appropriately referenced.
> >>
> >> Could you explain in more detail what you mean by changing the author's
> >> name?
> >> Do you have any suggestions on what to do in this case or how to change
> >> it?
> >>
> >>
> > I just submitted a new version of the patch set.
> > Among other changes, I now put you as the author of the first three
> > patches, as most of their content is based on your original patch set.
> > I made some modifications to them, so I added myself as a co-author.
> > For patches 4 and 5, I put you as the co-author because some of their
> > content is based on your original patch set, but only to a smaller extent.
> > All other patches are independent.
> >
> > I hope that this solution is OK for you. If not, please let me know.
> >
> >
> >>
> >> On Wed, Oct 19, 2022 at 3:26 PM  wrote:
> >>>
>  From: Thomas Siedel 
> 
>  This patch set adds H266/VVC support.
>  This includes parsing, muxing, demuxing, decoding and encoding.
>  Decoding is done using the external library VVdeC
>  (https://github.com/fraunhoferhhi/vvdec.git) and can be enabled with
>  --enable-libvvdec.
>  Encoding is done using the external library VVenC
>  (https://github.com/fraunhoferhhi/vvenc.git) and can be enabled with
>  --enable-libvvenc.
> 
>  Thomas Siedel (11):
>    avcodec: add enum types for H266/VVC
>    avcodec: add cbs for H266/VVC
>    avcodec: enable cbs for H266/VVC
>    avcodec: add bitstream parser for H266/VVC
>    avcodec: add MP4 to annexb support for H266/VVC
>    avformat: add demuxer and probe support for H266/VVC
>    avformat: add muxer support for H266/VVC
>    avcodec: add external decoder libvvdec for H266/VVC
>    avcodec: add external encoder libvvenc for H266/VVC
>    avformat: add ts stream types for H266/VVC
>    avcodec: increase minor version for H266/VVC
> 
>   configure |   16 +-
>   libavcodec/Makefile   |6 +
>   libavcodec/allcodecs.c|2 +
>   libavcodec/bitstream_filters.c|2 +
>   libavcodec/cbs.c  |6 +
>   libavcodec/cbs_h2645.c|  384 +++-
>   libavcodec/cbs_h266.h |  791 +++
>   libavcodec/cbs_h266_syntax_template.c | 3010 +
>   libavcodec/cbs_internal.h |3 +-
>   libavcodec/cbs_sei.c  |   29 +
>   libavcodec/h2645_parse.c  |   71 +-
>   libavcodec/h266_metadata_bsf.c|  145 ++
>   libavcodec/libvvdec.c |  511 +
>   libavcodec/libvvenc.c |  432 
>   libavcodec/parsers.c  |1 +
>   libavcodec/version.h  |2 +-
>   libavcodec/vvc.h  |  142 ++
>   libavcodec/vvc_mp4toannexb_bsf.c  |  318 +++
>   libavcodec/vvc_paramset.c |  972 
>   libavcodec/vvc_paramset.h |  429 
>   libavcodec/vvc_parse_extradata.c  |  241 ++
>   libavcodec/vvc_parse_extradata.h  |   36 +
>   libavcodec/vvc_parser.c   |  588 +
>   libavformat/Makefile  |8 +-
>   libavformat/allformats.c  |2 +
>   libavformat/demux.c   |7 +-
>   libavformat/isom.c|1 +
>   libavformat/isom_tags.c 

Re: [FFmpeg-devel] [PATCH v3 1/4] avcodec/bswapdsp: remove unused cextern

2023-01-10 Thread Anton Khirnov
Quoting Mark Reid (2023-01-06 19:09:10)
> On Mon, Dec 26, 2022 at 1:31 PM Mark Reid  wrote:
> 
> >
> >
> > On Mon, Dec 12, 2022 at 6:42 PM  wrote:
> >
> >> From: Mark Reid 
> >>
> >> ---
> >>  libavcodec/x86/bswapdsp.asm | 2 --
> >>  1 file changed, 2 deletions(-)
> >>
> >> diff --git a/libavcodec/x86/bswapdsp.asm b/libavcodec/x86/bswapdsp.asm
> >> index 31c6c48a21..2aa235e13c 100644
> >> --- a/libavcodec/x86/bswapdsp.asm
> >> +++ b/libavcodec/x86/bswapdsp.asm
> >> @@ -26,8 +26,6 @@
> >>  SECTION_RODATA
> >>  pb_bswap32: db 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12
> >>
> >> -cextern pb_80
> >> -
> >>  SECTION .text
> >>
> >>  ; %1 = aligned/unaligned
> >> --
> >> 2.31.1.windows.1
> >>
> >>
> > ping
> >
> 
> ping

Are you really duplicating a whole bunch of files from lavc in sws? I
don't think that's anywhere remotely close to acceptable.

-- 
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] ffmpeg: apply discontinuity adjustment per-stream

2023-01-10 Thread Anton Khirnov
Quoting Gyan Doshi (2023-01-03 11:22:17)
> At present, the offset for discontinuity adjustment is applied per-file but
> the check for discontinuity is intra-stream so the same discontinuity when
> seen in multiple streams with copyts, leads to compounded adjustment of the
> discontinuity offset. This introduces gaps in streams, leading to loss of sync
> or even de facto loss of stream.
> 
> The ts_offset_discont parameter is transferred to InputStream and adjusted
> based on intra-stream gaps.

I never had much use for this feature, but I wonder if adding different
offsets to different streams isn't going against the whole point of
timestamps, which is synchronizing them.

Also, this could REALLY use tests.

-- 
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 v3] lavc/libvpx: remove thread limit

2023-01-10 Thread myp...@gmail.com
On Thu, Jan 5, 2023 at 6:42 PM Dmitrii Ovchinnikov
 wrote:
>
> From: Dmitrii Ovchinnikov 
>
> This change improves the performance and multicore
>  scalability of the vp9 codec for streaming single-pass encoded videos. The
>  current thread limit for ffmpeg codecs is 16 (MAX_AUTO_THREADS in
>  pthread_internal.h) due to a limitation in H.264 codec that prevents more
>  than 16 threads being used.
>
> Increasing the thread limit to 64 for vp9 improves
> the performance for encoding 4K raw videos for streaming by up to 47%
> compared to 16 threads, and from 20-30% for 32 threads, with the same quality
> as measured by the VMAF score.
>
> Did not need to add a check for limit in libvpx as it is already present
> in libvpx/vp9/vp9_cx_iface.c:
>   RANGE_CHECK_HI(cfg, g_threads, 64);
> As demonstrated by following message when -threads is set to anything more 
> than 64
> [libvpx-vp9 @ 0x30ed380]   Additional information: g_threads out of range 
> [..64]
>
> ---
>  libavcodec/libvpxdec.c | 2 +-
>  libavcodec/libvpxenc.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
> index 9cd2c56caf..19407092d0 100644
> --- a/libavcodec/libvpxdec.c
> +++ b/libavcodec/libvpxdec.c
> @@ -88,7 +88,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>  const struct vpx_codec_iface *iface)
>  {
>  struct vpx_codec_dec_cfg deccfg = {
> -.threads = FFMIN(avctx->thread_count ? avctx->thread_count : 
> av_cpu_count(), 16)
> +.threads = avctx->thread_count ? avctx->thread_count : av_cpu_count()
>  };
>
>  av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index 9aa5510c28..0627e13973 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
>  enccfg.g_timebase.num = avctx->time_base.num;
>  enccfg.g_timebase.den = avctx->time_base.den;
>  enccfg.g_threads  =
> -FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 
> 16);
> +avctx->thread_count ? avctx->thread_count : av_cpu_count();
>  enccfg.g_lag_in_frames= ctx->lag_in_frames;
>
Do you check the change with the old version libvpx?  as I know, older
versions libvpx setting the number of threads higher than 16 will
cause a crash, so I think at least a version check needs to be added

>  if (avctx->flags & AV_CODEC_FLAG_PASS1)
> --
> 2.38.1.windows.1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] vaapi_encode_h264: Only set pic_order_cnt_type to 0 with B-frames

2023-01-10 Thread David Rosca
On Mon, Jan 9, 2023 at 10:11 PM Mark Thompson  wrote:
>
> On 09/01/2023 07:37, David Rosca wrote:
> > On Mon, Jan 9, 2023 at 3:22 AM Xiang, Haihao  wrote:
> >>
> >> On Do, 2022-12-29 at 22:20 +0100, David Rosca wrote:
> >>> ---
> >>>   libavcodec/vaapi_encode_h264.c | 2 +-
> >>>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/libavcodec/vaapi_encode_h264.c 
> >>> b/libavcodec/vaapi_encode_h264.c
> >>> index dd17be2..d6926c4 100644
> >>> --- a/libavcodec/vaapi_encode_h264.c
> >>> +++ b/libavcodec/vaapi_encode_h264.c
> >>> @@ -350,7 +350,7 @@ static int
> >>> vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
> >>>   sps->chroma_format_idc= 1;
> >>>
> >>>   sps->log2_max_frame_num_minus4 = 4;
> >>> -sps->pic_order_cnt_type= 0;
> >>> +sps->pic_order_cnt_type= ctx->max_b_depth ? 0 : 2;
> >>
> >>
> >> pic_order_cnt_type (0) should work for ctx->max_b_depth == 0. If 2 is 
> >> preferred
> >> for your vaapi driver, it would be better to query the capability from the
> >> driver, like as what commit 9f02e033875185409c861846f209b04a3be339d2 did.
> >
> > It's not about an encoder, but rather about decoder. Some decoders
> > (namely the Snapdragon HW decoder)
> > will buffer frames when pic_order_cnt_type == 0 (in case the frames
> > will be reordered?) which results
> > in undesired increased latency. Setting pic_order_cnt_type to 2 will
> > fix this problem, and it is also what
> > libx264 does [0].
>
> Has that decoder bug been reported to the vendor so that they can fix it?

I haven't and I'm not sure where I would check if it was already
reported by someone else. I wasn't even sure it's a bug since all
encoders I have tried so far (x264, nvenc, amf) will output
pic_order_cnt_type=2 when configured for low latency encoding.

>
> The decoder should be reading the stream buffering from 
> max_num_reorder_frames in the VUI parameters, which is set at as expected 
> .
>
> The change to using POC type 2 is not unreasonable to save a few bits, but to 
> do it you will also need to fix all of the POC values to actually match the 
> type 2 behaviour (the current type 0 setup steps by 1 on frames because 
> interlacing is not supported, but type 2 always steps by 2 - see §8.2.1.3).
>
> - Mark
> ___
> 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 v2] vaapi_encode_h264: Only set pic_order_cnt_type to 0 with B-frames

2023-01-10 Thread David Rosca
v2: frame_num steps by 2

---
 libavcodec/vaapi_encode_h264.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c
index 7a6b54ab6f..8093c47179 100644
--- a/libavcodec/vaapi_encode_h264.c
+++ b/libavcodec/vaapi_encode_h264.c
@@ -349,7 +349,7 @@ static int 
vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
 sps->chroma_format_idc= 1;
 
 sps->log2_max_frame_num_minus4 = 4;
-sps->pic_order_cnt_type= 0;
+sps->pic_order_cnt_type= ctx->max_b_depth ? 0 : 2;
 sps->log2_max_pic_order_cnt_lsb_minus4 = 4;
 
 sps->max_num_ref_frames = priv->dpb_frames;
@@ -621,7 +621,10 @@ static int 
vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
 } else {
 av_assert0(prev);
 
-hpic->frame_num = hprev->frame_num + prev->is_reference;
+hpic->frame_num = hprev->frame_num;
+if (prev->is_reference) {
+hpic->frame_num += ctx->max_b_depth ? 1 : 2;
+}
 
 hpic->last_idr_frame = hprev->last_idr_frame;
 hpic->idr_pic_id = hprev->idr_pic_id;
-- 
2.39.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".