[FFmpeg-devel] [PATCH] avformat/hls: Add option to retry failed segments for hls

2022-10-10 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream 
recording.
Add an option to retry a failed segment to ensure the output file is a complete 
stream.

Signed-off-by: gnattu 
---
libavformat/hls.c | 15 ++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
  int http_persistent;
  int http_multiple;
  int http_seekable;
+int seg_max_retry;
  AVIOContext *playlist_pb;
  HLSCryptoContext  crypto_ctx;
} HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
  int ret;
  int just_opened = 0;
  int reload_count = 0;
+int segment_retries = 0;
  struct segment *seg;

restart:
@@ -1563,9 +1565,18 @@ reload:
  av_log(v->parent, AV_LOG_WARNING, "Failed to open segment %"PRId64" 
of playlist %d\n",
 v->cur_seq_no,
 v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
  goto reload;
  }
+segment_retries = 0;
  just_opened = 1;
  }

@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
  OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
  {"seg_format_options", "Set options for segment demuxer",
  OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
  {NULL}
};

-- 
2.37.0 (Apple Git-136)

___
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] avformat/hls: Add option to retry failed segments for hls

2022-10-10 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream 
recording.
Add an option to retry a failed segment to ensure the output file is a complete 
stream.

Signed-off-by: gnattu 
---
Previous version was trashed by my email client, sorry.
 libavformat/hls.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",
v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
 {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH v3] avformat/hls: Add option to retry failed segments for hls

2022-10-10 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream
recording.
Add an option to retry a failed segment to ensure the output file is
a complete stream.

Signed-off-by: gnattu 
---
Fixed commit message wrap
 libavformat/hls.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",
v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
 {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH v4] avformat/hls: Add option to retry failed segments for hls

2022-10-12 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream
recording.
Add an option to retry a failed segment to ensure the output file is
a complete stream.

Signed-off-by: gnattu 
---
v4 added docs explaining the seg_max_retry option

 doc/demuxers.texi |  4 
 libavformat/hls.c | 15 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2b6dd86c2a..3e09a0f14e 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -401,6 +401,10 @@ Use HTTP partial requests for downloading HTTP segments.
 
 @item seg_format_options
 Set options for the demuxer of media segments using a list of key=value pairs 
separated by @code{:}.
+
+@item seg_max_retry
+Maximum number of times to reload a segment on error, useful when segment skip 
on network error is not desired.
+Default value is 0.
 @end table
 
 @section image2
diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",
v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
 {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH v4] avformat/hls: Add option to retry failed segments for hls

2022-10-19 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream
recording.
Add an option to retry a failed segment to ensure the output file is
a complete stream.

Signed-off-by: gnattu 
---
v4 added documentation for the new seg_max_try option

 doc/demuxers.texi |  4 
 libavformat/hls.c | 15 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2b6dd86c2a..3e09a0f14e 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -401,6 +401,10 @@ Use HTTP partial requests for downloading HTTP segments.
 
 @item seg_format_options
 Set options for the demuxer of media segments using a list of key=value pairs 
separated by @code{:}.
+
+@item seg_max_retry
+Maximum number of times to reload a segment on error, useful when segment skip 
on network error is not desired.
+Default value is 0.
 @end table
 
 @section image2
diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",
v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
 {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

___
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 v5] avformat/hls: Add option to retry failed segments for hls

2022-10-20 Thread gnattu
Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream
recording.
Add an option to retry a failed segment to ensure the output file is
a complete stream.

Signed-off-by: gnattu 
---
v5 changed coding style as requested
v4 added documentation for the new seg_max_try option

 doc/demuxers.texi |  4 
 libavformat/hls.c | 15 ++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 2b6dd86c2a..3e09a0f14e 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -401,6 +401,10 @@ Use HTTP partial requests for downloading HTTP segments.
 
 @item seg_format_options
 Set options for the demuxer of media segments using a list of key=value pairs 
separated by @code{:}.
+
+@item seg_max_retry
+Maximum number of times to reload a segment on error, useful when segment skip 
on network error is not desired.
+Default value is 0.
 @end table
 
 @section image2
diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2a5ffb927f 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, int 
buf_size)
 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
 
 restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",
v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",
+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no++;
+segment_retries = 0;
+} else {
+segment_retries++;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 
@@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS},
 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
 {NULL}
 };
 
-- 
2.37.0 (Apple Git-136)

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

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


[FFmpeg-devel] [PATCH] avformat/hls: Add option to retry failed segments for hls

2022-10-10 Thread Gnattu OC

Current HLS implementation simply skip a failed segment to catch up
the stream, but this is not optimal for some use cases like livestream 
recording.
Add an option to retry a failed segment to ensure the output file is a 
complete stream.


Signed-off-by: gnattu 
---
 libavformat/hls.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index e622425e80..2b977f9132 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -225,6 +225,7 @@ typedef struct HLSContext {
 int http_persistent;
 int http_multiple;
 int http_seekable;
+int seg_max_retry;
 AVIOContext *playlist_pb;
 HLSCryptoContext  crypto_ctx;
 } HLSContext;
@@ -1472,6 +1473,7 @@ static int read_data(void *opaque, uint8_t *buf, 
int buf_size)

 int ret;
 int just_opened = 0;
 int reload_count = 0;
+int segment_retries = 0;
 struct segment *seg;
  restart:
@@ -1563,9 +1565,18 @@ reload:
 av_log(v->parent, AV_LOG_WARNING, "Failed to open segment 
%"PRId64" of playlist %d\n",

v->cur_seq_no,
v->index);
-v->cur_seq_no += 1;
+if (segment_retries >= c->seg_max_retry) {
+av_log(v->parent, AV_LOG_WARNING, "Segment %"PRId64" of 
playlist %d failed too many times, skipping\n",

+   v->cur_seq_no,
+   v->index);
+v->cur_seq_no += 1;
+segment_retries = 0;
+} else {
+segment_retries += 1;
+}
 goto reload;
 }
+segment_retries = 0;
 just_opened = 1;
 }
 @@ -2549,6 +2560,8 @@ static const AVOption hls_options[] = {
 OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, 
FLAGS},

 {"seg_format_options", "Set options for segment demuxer",
 OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 
0, FLAGS},
+{"seg_max_retry", "Maximum number of times to reload a segment on 
error.",
+ OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, 
FLAGS},

 {NULL}
 };
 -- 2.37.0 (Apple Git-136)

___
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] lavc/videotoolboxenc: add MJPEG support

2024-03-28 Thread gnattu via ffmpeg-devel
For example:
./ffmpeg -hwaccel videotoolbox\
   -i INPUT -c:v mjpeg_videotoolbox\
out.mp4

This encoder does not have many options and can only use ``-q:v` to control 
quality.

Signed-off-by: Gnattu OC 
---
 Changelog|  1 +
 configure|  2 ++
 libavcodec/Makefile  |  1 +
 libavcodec/allcodecs.c   |  1 +
 libavcodec/videotoolboxenc.c | 39 +---
 5 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index e83a00e35c..b73a44f9ad 100644
--- a/Changelog
+++ b/Changelog
@@ -38,6 +38,7 @@ version 7.0:
 - ffplay with hwaccel decoding support (depends on vulkan renderer via 
libplacebo)
 - dnn filter libtorch backend
 - Android content URIs protocol
+- VideoToolbox MJPEG encoder
 
 
 version 6.1:
diff --git a/configure b/configure
index 2a1d22310b..52a0ee762f 100755
--- a/configure
+++ b/configure
@@ -3474,6 +3474,8 @@ hevc_videotoolbox_encoder_deps="pthreads"
 hevc_videotoolbox_encoder_select="atsc_a53 videotoolbox_encoder"
 prores_videotoolbox_encoder_deps="pthreads"
 prores_videotoolbox_encoder_select="videotoolbox_encoder"
+mjpeg_videotoolbox_encoder_deps="pthreads"
+mjpeg_videotoolbox_encoder_select="videotoolbox_encoder"
 libaom_av1_decoder_deps="libaom"
 libaom_av1_encoder_deps="libaom"
 libaom_av1_encoder_select="extract_extradata_bsf"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9ce6d445c1..f59b2ae691 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -503,6 +503,7 @@ OBJS-$(CONFIG_MJPEGB_DECODER)  += mjpegbdec.o
 OBJS-$(CONFIG_MJPEG_CUVID_DECODER) += cuviddec.o
 OBJS-$(CONFIG_MJPEG_QSV_ENCODER)   += qsvenc_jpeg.o
 OBJS-$(CONFIG_MJPEG_VAAPI_ENCODER) += vaapi_encode_mjpeg.o
+OBJS-$(CONFIG_MJPEG_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_MLP_DECODER) += mlpdec.o mlpdsp.o
 OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2386b450a6..f8a90fdca2 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -879,6 +879,7 @@ extern const FFCodec ff_mpeg4_mediacodec_encoder;
 extern const FFCodec ff_mpeg4_omx_encoder;
 extern const FFCodec ff_mpeg4_v4l2m2m_encoder;
 extern const FFCodec ff_prores_videotoolbox_encoder;
+extern const FFCodec ff_mjpeg_videotoolbox_encoder;
 extern const FFCodec ff_vc1_cuvid_decoder;
 extern const FFCodec ff_vp8_cuvid_decoder;
 extern const FFCodec ff_vp8_mediacodec_decoder;
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 15c34d59c3..0574edab56 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -547,6 +547,7 @@ static CMVideoCodecType get_cm_codec_type(AVCodecContext 
*avctx,
 else
 return MKBETAG('a','p','c','n'); // 
kCMVideoCodecType_AppleProRes422
 }
+case AV_CODEC_ID_MJPEG: return kCMVideoCodecType_JPEG;
 default:   return 0;
 }
 }
@@ -1233,7 +1234,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
   kVTCompressionPropertyKey_Quality,
   quality_num);
 CFRelease(quality_num);
-} else if (avctx->codec_id != AV_CODEC_ID_PRORES) {
+} else if (avctx->codec_id != AV_CODEC_ID_PRORES && avctx->codec_id != 
AV_CODEC_ID_MJPEG) {
 bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
   kCFNumberSInt32Type,
   &bit_rate);
@@ -1347,7 +1348,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 }
 }
 
-if (avctx->gop_size > 0 && avctx->codec_id != AV_CODEC_ID_PRORES) {
+if (avctx->gop_size > 0 && avctx->codec_id != AV_CODEC_ID_PRORES && 
avctx->codec_id != AV_CODEC_ID_MJPEG) {
 CFNumberRef interval = CFNumberCreate(kCFAllocatorDefault,
   kCFNumberIntType,
   &avctx->gop_size);
@@ -1496,7 +1497,7 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
 }
 }
 
-if (!vtctx->has_b_frames && avctx->codec_id != AV_CODEC_ID_PRORES) {
+if (!vtctx->has_b_frames && avctx->codec_id != AV_CODEC_ID_PRORES && 
avctx->codec_id != AV_CODEC_ID_MJPEG) {
 status = VTSessionSetProperty(vtctx->session,
   
kVTCompressionPropertyKey_AllowFrameReordering,
   kCFBooleanFalse);
@@ -2844,6 +2845,13 @@ static const enum AVPixelFormat prores_pix_fmts[] = {
 AV_PIX_FMT_NONE
 };
 
+static const enum AVPixelFormat mjpeg_pix_fmts[] = {
+ 

[FFmpeg-devel] [PATCH] avfilter: add vf_overlay_videotoolbox

2024-02-20 Thread gnattu via ffmpeg-devel
Overlay filter for VideoToolbox hwframes. Unlike most hardware
overlay filters, this filter does not require the two inputs to
have the same pixel format; instead, it will perform format
conversion automatically with hardware accelerated methods.

Signed-off-by: Gnattu OC 
---
 Changelog |   1 +
 configure |   1 +
 libavfilter/Makefile  |   3 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/metal/utils.h |   7 +
 libavfilter/metal/utils.m |  28 +
 .../metal/vf_overlay_videotoolbox.metal   |  58 ++
 libavfilter/vf_overlay_videotoolbox.m | 504 ++
 8 files changed, 603 insertions(+)
 create mode 100644 libavfilter/metal/vf_overlay_videotoolbox.metal
 create mode 100644 libavfilter/vf_overlay_videotoolbox.m

diff --git a/Changelog b/Changelog
index 610ee61dd6..3ecfdab81b 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - a C11-compliant compiler is now required; note that this requirement
   will be bumped to C17 in the near future, so consider updating your
   build environment if it lacks C17 support
+- VideoToolbox overlay filter
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 23066efa32..a7c349d126 100755
--- a/configure
+++ b/configure
@@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..330924fadf 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
vf_overlay_opencl.o opencl.o \
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o 
vaapi_vpp.o
 OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o 
vulkan_filter.o
+OBJS-$(CONFIG_OVERLAY_VIDEOTOOLBOX_FILTER) += vf_overlay_videotoolbox.o \
+
metal/vf_overlay_videotoolbox.metallib.o \
+metal/utils.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o 
opencl/pad.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 149bf50997..ec9d975ecb 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -389,6 +389,7 @@ extern const AVFilter ff_vf_overlay_qsv;
 extern const AVFilter ff_vf_overlay_vaapi;
 extern const AVFilter ff_vf_overlay_vulkan;
 extern const AVFilter ff_vf_overlay_cuda;
+extern const AVFilter ff_vf_overlay_videotoolbox;
 extern const AVFilter ff_vf_owdenoise;
 extern const AVFilter ff_vf_pad;
 extern const AVFilter ff_vf_pad_opencl;
diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h
index 7350d42a35..a2142b6472 100644
--- a/libavfilter/metal/utils.h
+++ b/libavfilter/metal/utils.h
@@ -56,4 +56,11 @@ CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass,
MTLPixelFormat format)
API_AVAILABLE(macos(10.11), 
ios(8.0));
 
+CVMetalTextureRef ff_metal_texture_from_non_planer_pixbuf(void *avclass,
+   CVMetalTextureCacheRef 
textureCache,
+   CVPixelBufferRef pixbuf,
+   int plane,
+   MTLPixelFormat format)
+API_AVAILABLE(macos(10.11), ios(8.0));
+
 #endif /* AVFILTER_METAL_UTILS_H */
diff --git a/libavfilter/metal/utils.m b/libavfilter/metal/utils.m
index f365d3ceea..b6a4ba16ff 100644
--- a/libavfilter/metal/utils.m
+++ b/libavfilter/metal/utils.m
@@ -74,3 +74,31 @@ CVMetalTextureRef ff_metal_texture_from_pixbuf(void *ctx,
 
 return tex;
 }
+
+CVMetalTextureRef ff_metal_texture_from_non_planer_pixbuf(void *ctx,
+   CVMetalTextureCacheRef 
textureCache,
+   CVPixelBufferRef pixbuf,
+   int plane,
+   MTLPixelFormat format)
+{
+CVMetalTextureRef tex = NULL;
+CVReturn ret;
+
+ret = CVMetalTextureCacheCreateTextureFromImage(
+NULL,
+textureCache,
+ 

[FFmpeg-devel] [PATCH v2] Overlay filter for VideoToolbox hwframes. Unlike most hardware overlay filters, this filter does not require the two inputs to have the same pixel format; instead, it will pe

2024-02-20 Thread gnattu via ffmpeg-devel
Signed-off-by: Gnattu OC 
---
 Changelog |  1 +
 configure |  1 +
 doc/filters.texi  | 52 +++
 libavfilter/Makefile  |  3 +++
 libavfilter/allfilters.c  |  1 +
 libavfilter/metal/utils.h |  1 -
 libavfilter/metal/utils.m |  7 --
 7 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 610ee61dd6..3ecfdab81b 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - a C11-compliant compiler is now required; note that this requirement
   will be bumped to C17 in the near future, so consider updating your
   build environment if it lacks C17 support
+- VideoToolbox overlay filter
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 23066efa32..a7c349d126 100755
--- a/configure
+++ b/configure
@@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
diff --git a/doc/filters.texi b/doc/filters.texi
index e0436a5755..bfb77562cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19033,6 +19033,58 @@ See @ref{framesync}.
 
 This filter also supports the @ref{framesync} options.
 
+@section overlay_videotoolbox
+
+Overlay one video on top of another.
+
+This is the VideoToolbox variant of the @ref{overlay} filter.
+It takes two inputs and has one output. The first input is the "main" video on 
which the second input is overlaid.
+It only accepts VideoToolbox frames. The underlying input pixel formats do not 
have to match.
+Different input pixel formats and color spaces will be automatically converted 
using hardware accelerated methods.
+The final output will have the same pixel format and color space as the "main" 
input.
+
+The filter accepts the following options:
+
+@table @option
+
+@item x
+Set the x coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item y
+Set the y coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item eof_action
+See @ref{framesync}.
+
+@item shortest
+See @ref{framesync}.
+
+@item repeatlast
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay an image LOGO at the top-left corner of the INPUT video.
+The INPUT video is in nv12 format and the LOGO image is in rgba format.
+@example
+-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
-filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
[a][b]overlay_videotoolbox" OUTPUT
+@end example
+@item
+Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
+The INPUT video is in p010 format and the LOGO image is in nv12 format.
+The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
+@example
+-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
[1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
+@end example
+
+@end itemize
+
 @section owdenoise
 
 Apply Overcomplete Wavelet denoiser.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..ea1389ab57 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
vf_overlay_opencl.o opencl.o \
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o 
vaapi_vpp.o
 OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o 
vulkan_filter.o
+OBJS-$(CONFIG_OVERLAY_VIDEOTOOLBOX_FILTER) += vf_overlay_videotoolbox.o 
framesync.o \
+
metal/vf_overlay_videotoolbox.metallib.o \
+metal/utils.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o 
opencl/pad.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 149bf50997..ec9d975ecb 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -389,6 +389,7 @@ extern const AVFilter ff_vf_overlay_qsv;
 extern const AVFilter ff_vf_overlay_vaapi;
 extern const AVFilter ff_vf_overlay_vulkan;
 extern const AVFilter ff_vf_overlay_cuda;
+extern const AVFilter ff_vf_overlay_videotoolbox;
 extern const AVFilter ff_vf_owdenoise;
 extern const AVFilter ff_vf_pad;
 extern const AVFilter ff_vf_pad_opencl;
diff --git a/libavfilter/metal/u

[FFmpeg-devel] [PATCH v2] avfilter: add vf_overlay_videotoolbox

2024-02-20 Thread gnattu via ffmpeg-devel
Overlay filter for VideoToolbox hwframes. Unlike most hardware
overlay filters, this filter does not require the two inputs to
have the same pixel format; instead, it will perform format
conversion automatically with hardware accelerated methods.

Signed-off-by: Gnattu OC 
---
 Changelog |  1 +
 configure |  1 +
 doc/filters.texi  | 52 +++
 libavfilter/Makefile  |  3 +++
 libavfilter/allfilters.c  |  1 +
 libavfilter/metal/utils.h |  1 -
 libavfilter/metal/utils.m |  7 --
 7 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 610ee61dd6..3ecfdab81b 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - a C11-compliant compiler is now required; note that this requirement
   will be bumped to C17 in the near future, so consider updating your
   build environment if it lacks C17 support
+- VideoToolbox overlay filter
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 23066efa32..a7c349d126 100755
--- a/configure
+++ b/configure
@@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
diff --git a/doc/filters.texi b/doc/filters.texi
index e0436a5755..bfb77562cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19033,6 +19033,58 @@ See @ref{framesync}.
 
 This filter also supports the @ref{framesync} options.
 
+@section overlay_videotoolbox
+
+Overlay one video on top of another.
+
+This is the VideoToolbox variant of the @ref{overlay} filter.
+It takes two inputs and has one output. The first input is the "main" video on 
which the second input is overlaid.
+It only accepts VideoToolbox frames. The underlying input pixel formats do not 
have to match.
+Different input pixel formats and color spaces will be automatically converted 
using hardware accelerated methods.
+The final output will have the same pixel format and color space as the "main" 
input.
+
+The filter accepts the following options:
+
+@table @option
+
+@item x
+Set the x coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item y
+Set the y coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item eof_action
+See @ref{framesync}.
+
+@item shortest
+See @ref{framesync}.
+
+@item repeatlast
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay an image LOGO at the top-left corner of the INPUT video.
+The INPUT video is in nv12 format and the LOGO image is in rgba format.
+@example
+-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
-filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
[a][b]overlay_videotoolbox" OUTPUT
+@end example
+@item
+Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
+The INPUT video is in p010 format and the LOGO image is in nv12 format.
+The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
+@example
+-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
[1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
+@end example
+
+@end itemize
+
 @section owdenoise
 
 Apply Overcomplete Wavelet denoiser.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..ea1389ab57 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
vf_overlay_opencl.o opencl.o \
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o 
vaapi_vpp.o
 OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o 
vulkan_filter.o
+OBJS-$(CONFIG_OVERLAY_VIDEOTOOLBOX_FILTER) += vf_overlay_videotoolbox.o 
framesync.o \
+
metal/vf_overlay_videotoolbox.metallib.o \
+metal/utils.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o 
opencl/pad.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 149bf50997..ec9d975ecb 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -389,6 +389,7 @@ extern const AVFilter ff_vf_overlay_qsv;
 extern const AVFilter ff_vf_overlay_vaapi;
 extern const AVFilter ff_vf_overlay_vulk

[FFmpeg-devel] [PATCH v3] avfilter: add vf_overlay_videotoolbox

2024-02-20 Thread gnattu via ffmpeg-devel
Overlay filter for VideoToolbox hwframes. Unlike most hardware
overlay filters, this filter does not require the two inputs to
have the same pixel format; instead, it will perform format
conversion automatically with hardware accelerated methods.

Signed-off-by: Gnattu OC 
---
 Changelog |   1 +
 configure |   1 +
 doc/filters.texi  |  52 ++
 libavfilter/Makefile  |   3 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/metal/utils.h |   1 -
 libavfilter/metal/utils.m |   7 +-
 .../metal/vf_overlay_videotoolbox.metal   |  58 ++
 libavfilter/vf_overlay_videotoolbox.m | 551 ++
 9 files changed, 672 insertions(+), 3 deletions(-)
 create mode 100644 libavfilter/metal/vf_overlay_videotoolbox.metal
 create mode 100644 libavfilter/vf_overlay_videotoolbox.m

diff --git a/Changelog b/Changelog
index 610ee61dd6..3ecfdab81b 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - a C11-compliant compiler is now required; note that this requirement
   will be bumped to C17 in the near future, so consider updating your
   build environment if it lacks C17 support
+- VideoToolbox overlay filter
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 23066efa32..a7c349d126 100755
--- a/configure
+++ b/configure
@@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
diff --git a/doc/filters.texi b/doc/filters.texi
index e0436a5755..bfb77562cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19033,6 +19033,58 @@ See @ref{framesync}.
 
 This filter also supports the @ref{framesync} options.
 
+@section overlay_videotoolbox
+
+Overlay one video on top of another.
+
+This is the VideoToolbox variant of the @ref{overlay} filter.
+It takes two inputs and has one output. The first input is the "main" video on 
which the second input is overlaid.
+It only accepts VideoToolbox frames. The underlying input pixel formats do not 
have to match.
+Different input pixel formats and color spaces will be automatically converted 
using hardware accelerated methods.
+The final output will have the same pixel format and color space as the "main" 
input.
+
+The filter accepts the following options:
+
+@table @option
+
+@item x
+Set the x coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item y
+Set the y coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item eof_action
+See @ref{framesync}.
+
+@item shortest
+See @ref{framesync}.
+
+@item repeatlast
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay an image LOGO at the top-left corner of the INPUT video.
+The INPUT video is in nv12 format and the LOGO image is in rgba format.
+@example
+-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
-filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
[a][b]overlay_videotoolbox" OUTPUT
+@end example
+@item
+Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
+The INPUT video is in p010 format and the LOGO image is in nv12 format.
+The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
+@example
+-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
[1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
+@end example
+
+@end itemize
+
 @section owdenoise
 
 Apply Overcomplete Wavelet denoiser.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..ea1389ab57 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
vf_overlay_opencl.o opencl.o \
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o 
vaapi_vpp.o
 OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o 
vulkan_filter.o
+OBJS-$(CONFIG_OVERLAY_VIDEOTOOLBOX_FILTER) += vf_overlay_videotoolbox.o 
framesync.o \
+
metal/vf_overlay_videotoolbox.metallib.o \
+metal/utils.o
 OBJS-$(CONFIG_OWDENOISE_FILTER)  += vf_owdenoise.o
 OBJS-$(CONFIG_PAD_FILTER)+= vf_pad.o
 OBJS-$(CONFIG_PAD_OPENCL_FILTER) 

[FFmpeg-devel] [PATCH] hwcontext_videotoolbox: add vt_device_derive

2024-02-22 Thread gnattu via ffmpeg-devel
There is no device context to be setup, nor devices to be
selected with VideoToolbox. Just a simple return would allow
us to use derived device in filters like
`hwupload=derive_device=videotoolbox`

Signed-off-by: Gnattu OC 
---
 libavutil/hwcontext_videotoolbox.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index fe469dc161..d13199eca7 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -759,6 +759,14 @@ static int vt_device_create(AVHWDeviceContext *ctx, const 
char *device,
 return 0;
 }
 
+static int vt_device_derive(AVHWDeviceContext *device_ctx,
+AVHWDeviceContext *src_ctx, AVDictionary *opts,
+int flags)
+{
+// There is no context to be setup with VT, just return.
+return 0;
+}
+
 const HWContextType ff_hwcontext_type_videotoolbox = {
 .type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
 .name = "videotoolbox",
@@ -766,6 +774,7 @@ const HWContextType ff_hwcontext_type_videotoolbox = {
 .frames_priv_size = sizeof(VTFramesContext),
 
 .device_create= vt_device_create,
+.device_derive= vt_device_derive,
 .frames_hwctx_size= sizeof(AVVTFramesContext),
 .frames_init  = vt_frames_init,
 .frames_get_buffer= vt_get_buffer,
-- 
2.39.3 (Apple Git-145)

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

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


[FFmpeg-devel] [PATCH v4] avfilter: add vf_overlay_videotoolbox

2024-02-27 Thread gnattu via ffmpeg-devel
Overlay filter for VideoToolbox hwframes. Unlike most hardware
overlay filters, this filter does not require the two inputs to
have the same pixel format; instead, it will perform format
conversion automatically with hardware accelerated methods.

Signed-off-by: Gnattu OC 
---
Changes from v3:

- Fixes an issue that 8bit depth BGRA overlay frames are not correctly 
converted to 16bit
- Added a constraint to input pixel formats as VideoToolbox cannot convert all 
of its hardwareframes

 Changelog |   1 +
 configure |   1 +
 doc/filters.texi  |  52 ++
 libavfilter/Makefile  |   3 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/metal/utils.m |   7 +-
 .../metal/vf_overlay_videotoolbox.metal   |  58 ++
 libavfilter/vf_overlay_videotoolbox.m | 609 ++
 8 files changed, 730 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/metal/vf_overlay_videotoolbox.metal
 create mode 100644 libavfilter/vf_overlay_videotoolbox.m

diff --git a/Changelog b/Changelog
index 610ee61dd6..3ecfdab81b 100644
--- a/Changelog
+++ b/Changelog
@@ -27,6 +27,7 @@ version :
 - a C11-compliant compiler is now required; note that this requirement
   will be bumped to C17 in the near future, so consider updating your
   build environment if it lacks C17 support
+- VideoToolbox overlay filter
 
 version 6.1:
 - libaribcaption decoder
diff --git a/configure b/configure
index 23066efa32..a7c349d126 100755
--- a/configure
+++ b/configure
@@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
diff --git a/doc/filters.texi b/doc/filters.texi
index e0436a5755..bfb77562cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19033,6 +19033,58 @@ See @ref{framesync}.
 
 This filter also supports the @ref{framesync} options.
 
+@section overlay_videotoolbox
+
+Overlay one video on top of another.
+
+This is the VideoToolbox variant of the @ref{overlay} filter.
+It takes two inputs and has one output. The first input is the "main" video on 
which the second input is overlaid.
+It only accepts VideoToolbox frames. The underlying input pixel formats do not 
have to match.
+Different input pixel formats and color spaces will be automatically converted 
using hardware accelerated methods.
+The final output will have the same pixel format and color space as the "main" 
input.
+
+The filter accepts the following options:
+
+@table @option
+
+@item x
+Set the x coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item y
+Set the y coordinate of the overlaid video on the main video.
+Default value is @code{0}.
+
+@item eof_action
+See @ref{framesync}.
+
+@item shortest
+See @ref{framesync}.
+
+@item repeatlast
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay an image LOGO at the top-left corner of the INPUT video.
+The INPUT video is in nv12 format and the LOGO image is in rgba format.
+@example
+-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
-filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
[a][b]overlay_videotoolbox" OUTPUT
+@end example
+@item
+Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
+The INPUT video is in p010 format and the LOGO image is in nv12 format.
+The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
+@example
+-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
[1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
+@end example
+
+@end itemize
+
 @section owdenoise
 
 Apply Overcomplete Wavelet denoiser.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..ea1389ab57 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
vf_overlay_opencl.o opencl.o \
 OBJS-$(CONFIG_OVERLAY_QSV_FILTER)+= vf_overlay_qsv.o framesync.o
 OBJS-$(CONFIG_OVERLAY_VAAPI_FILTER)  += vf_overlay_vaapi.o framesync.o 
vaapi_vpp.o
 OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o 
vulkan_filter.o
+OBJS-$(CONFIG_OVERLAY_VIDEOTOOLBOX_FILTER) += vf_overlay_videotoolbox.o 
framesync.o \
+
metal/vf_overlay_videotoolbox.metallib.o \
+metal/utils.o
 

[FFmpeg-devel] [PATCH] avutil/hwcontext_videotoolbox: Check CVBufferCopyAttachments during configure

2024-07-21 Thread gnattu via ffmpeg-devel
The __builtin_available function does not do compile time check
for the availablity of the CVBufferCopyAttachments function
which will fail the build. Check the availability during configure.

Signed-off-by: Gnattu OC 
---
 configure | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configure b/configure
index f6f5c29fea..54171dd4e5 100755
--- a/configure
+++ b/configure
@@ -2366,6 +2366,7 @@ SYSTEM_FUNCS="
 clock_gettime
 closesocket
 CommandLineToArgvW
+CVBufferCopyAttachments
 fcntl
 getaddrinfo
 getauxval
@@ -6684,6 +6685,7 @@ enabled videotoolbox && {
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo"
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo"
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
+check_func_headers CoreVideo/CVBuffer.h CVBufferCopyAttachments 
"-framework CoreVideo"
 }
 
 enabled metal && test_cmd $metalcc -v || disable metal
-- 
2.39.3 (Apple Git-146)

___
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] avutil/hwcontext_videotoolbox: Check CVBufferCopyAttachments during configure

2024-07-21 Thread gnattu via ffmpeg-devel
The __builtin_available function does not do compile time check
for the availablity of the CVBufferCopyAttachments function
which will fail the build. Check the availability during configure.

Signed-off-by: Gnattu OC 
---
 configure  |  2 ++
 libavutil/hwcontext_videotoolbox.c | 12 +---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index f6f5c29fea..54171dd4e5 100755
--- a/configure
+++ b/configure
@@ -2366,6 +2366,7 @@ SYSTEM_FUNCS="
 clock_gettime
 closesocket
 CommandLineToArgvW
+CVBufferCopyAttachments
 fcntl
 getaddrinfo
 getauxval
@@ -6684,6 +6685,7 @@ enabled videotoolbox && {
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferColorPrimaries_ITU_R_2020 "-framework CoreVideo"
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferTransferFunction_ITU_R_2020 "-framework CoreVideo"
 check_func_headers CoreVideo/CVImageBuffer.h 
kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
+check_func_headers CoreVideo/CVBuffer.h CVBufferCopyAttachments 
"-framework CoreVideo"
 }
 
 enabled metal && test_cmd $metalcc -v || disable metal
diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index ab7556936d..c55d478004 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -592,15 +592,13 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
 if (__builtin_available(macOS 10.8, iOS 10, *)) {
 CFDictionaryRef attachments = NULL;
+#if HAVE_CVBUFFERCOPYATTACHMENTS
 if (__builtin_available(macOS 12.0, iOS 15.0, *))
 attachments = CVBufferCopyAttachments(pixbuf, 
kCVAttachmentMode_ShouldPropagate);
-#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 12) || \
-(TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 15)
-else {
-CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf, 
kCVAttachmentMode_ShouldPropagate);
-if (tmp)
-attachments = CFDictionaryCreateCopy(NULL, tmp);
-}
+#else
+CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf, 
kCVAttachmentMode_ShouldPropagate);
+if (tmp)
+attachments = CFDictionaryCreateCopy(NULL, tmp);
 #endif
 if (attachments) {
 colorspace = 
CVImageBufferCreateColorSpaceFromAttachments(attachments);
-- 
2.39.3 (Apple Git-146)

___
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_videotoolbox: Allocate attachments dictionary

2024-08-01 Thread gnattu via ffmpeg-devel
From: Gnattu OC 

Allocate a dedicated attachments dictionary instead of trying to get
one from the pixel buffer. The attachments got from the pixel buffer
confuses the CVImageBufferCreateColorSpaceFromAttachments method and
will make it to output a wrong colorspace that causes problem like
#10884.

Signed-off-by: gnattu 
---
 libavutil/hwcontext_videotoolbox.c | 35 ++
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index 1794459943..dda6ada1af 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -569,11 +569,19 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 CGColorSpaceRef colorspace = NULL;
 CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
 Float32 gamma = 0;
+CFMutableDictionaryRef attachments = NULL;
+attachments = CFDictionaryCreateMutable(NULL, 0,
+&kCFTypeDictionaryKeyCallBacks,
+&kCFTypeDictionaryValueCallBacks);
+if (!attachments)
+return AVERROR(ENOMEM);
 
 colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace);
-if (colormatrix)
+if (colormatrix) {
+CFDictionarySetValue(attachments, kCVImageBufferYCbCrMatrixKey, 
colormatrix);
 CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey,
-colormatrix, kCVAttachmentMode_ShouldPropagate);
+  colormatrix, kCVAttachmentMode_ShouldPropagate);
+}
 else {
 CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
 if (src->colorspace != AVCOL_SPC_UNSPECIFIED)
@@ -583,9 +591,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 }
 
 colorpri = 
av_map_videotoolbox_color_primaries_from_av(src->color_primaries);
-if (colorpri)
+if (colorpri) {
+CFDictionarySetValue(attachments, kCVImageBufferColorPrimariesKey, 
colorpri);
 CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey,
-colorpri, kCVAttachmentMode_ShouldPropagate);
+  colorpri, kCVAttachmentMode_ShouldPropagate);
+}
 else {
 CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey);
 if (src->color_primaries != AVCOL_SPC_UNSPECIFIED)
@@ -595,9 +605,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 }
 
 colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
-if (colortrc)
+if (colortrc) {
+CFDictionarySetValue(attachments, kCVImageBufferTransferFunctionKey, 
colortrc);
 CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
-colorpri, kCVAttachmentMode_ShouldPropagate);
+  colorpri, kCVAttachmentMode_ShouldPropagate);
+}
 else {
 CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
 if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
@@ -622,17 +634,12 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 #if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
 (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
 if (__builtin_available(macOS 10.8, iOS 10, *)) {
-CFDictionaryRef attachments =
-vt_cv_buffer_copy_attachments(pixbuf, 
kCVAttachmentMode_ShouldPropagate);
-
-if (attachments) {
-colorspace =
-CVImageBufferCreateColorSpaceFromAttachments(attachments);
-CFRelease(attachments);
-}
+colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments);
 }
 #endif
 
+CFRelease(attachments);
+
 // Done outside the above preprocessor code and if's so that
 // in any case a wrong kCVImageBufferCGColorSpaceKey is removed
 // if the above code is not used or fails.
-- 
2.39.3 (Apple Git-146)

___
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_videotoolbox: Correctly set trc

2024-08-01 Thread gnattu via ffmpeg-devel
The color trc key was assigned a color primaries value which causes
the resulting colorspace is always SDR.

Fixes #10884.

Signed-off-by: Gnattu OC 
---
 libavutil/hwcontext_videotoolbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index 1794459943..80eaab64f0 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -597,7 +597,7 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
 if (colortrc)
 CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
-colorpri, kCVAttachmentMode_ShouldPropagate);
+colortrc, kCVAttachmentMode_ShouldPropagate);
 else {
 CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
 if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
-- 
2.39.3 (Apple Git-146)

___
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] avcodec/videotoolboxenc: always release supported_props

2024-08-09 Thread gnattu via ffmpeg-devel
In vtenc_populate_extradata, supported_props should always be released
to avoid memory leak.

Regression from cd2f8a22e94700c68b1de7968df11e8bebfd315b

Signed-off-by: gnattu 
---
 libavcodec/videotoolboxenc.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 78ef474d7ae..6cc45db4a96 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -2787,9 +2787,16 @@ pe_cleanup:
 
 if (status) {
 vtenc_reset(vtctx);
-} else if (vtctx->session) {
-CFRelease(vtctx->session);
-vtctx->session = NULL;
+} else {
+if (vtctx->session) {
+CFRelease(vtctx->session);
+vtctx->session = NULL;
+}
+
+if (vtctx->supported_props) {
+CFRelease(vtctx->supported_props);
+vtctx->supported_props = NULL;
+}
 }
 
 vtctx->frame_ct_out = 0;
-- 
2.39.3 (Apple Git-146)

___
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_videotoolbox: silence warning for RGB

2024-08-09 Thread gnattu via ffmpeg-devel
Hardware frames with RGB colorspace will not have a YCbCrMatrixKey.
Currently, it will spam the console with warning if rgb frame is
uploaded.

Signed-off-by: Gnattu OC 
---
 libavutil/hwcontext_videotoolbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_videotoolbox.c 
b/libavutil/hwcontext_videotoolbox.c
index 80eaab64f08..122a61d5e78 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -576,7 +576,7 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
 colormatrix, kCVAttachmentMode_ShouldPropagate);
 else {
 CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
-if (src->colorspace != AVCOL_SPC_UNSPECIFIED)
+if (src->colorspace != AVCOL_SPC_UNSPECIFIED && src->colorspace != 
AVCOL_SPC_RGB)
 av_log(log_ctx, AV_LOG_WARNING,
 "Color space %s is not supported.\n",
 av_color_space_name(src->colorspace));
-- 
2.39.3 (Apple Git-146)

___
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] avfilter: inherit input color range for videotoolbox filters

2024-08-15 Thread gnattu via ffmpeg-devel
The color range should be set to match the input when creating
the VideoToolbox context. Otherwise, the new context will default
to limited range, creates inconsistencies with full range inputs.

Signed-off-by: Gnattu OC 
---
 libavfilter/vf_scale_vt.c   | 1 +
 libavfilter/vf_transpose_vt.c   | 1 +
 libavfilter/vf_yadif_videotoolbox.m | 6 +-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_scale_vt.c b/libavfilter/vf_scale_vt.c
index 7481af17471..1155233555f 100644
--- a/libavfilter/vf_scale_vt.c
+++ b/libavfilter/vf_scale_vt.c
@@ -209,6 +209,7 @@ static int scale_vt_config_output(AVFilterLink *outlink)
 hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
 hw_frame_ctx_out->width = outlink->w;
 hw_frame_ctx_out->height = outlink->h;
+((AVVTFramesContext *)hw_frame_ctx_out->hwctx)->color_range = 
((AVVTFramesContext *)hw_frame_ctx_in->hwctx)->color_range;
 
 err = ff_filter_init_hw_frames(avctx, outlink, 1);
 if (err < 0)
diff --git a/libavfilter/vf_transpose_vt.c b/libavfilter/vf_transpose_vt.c
index 72bab3d53b3..385a188ff77 100644
--- a/libavfilter/vf_transpose_vt.c
+++ b/libavfilter/vf_transpose_vt.c
@@ -124,6 +124,7 @@ static int transpose_vt_recreate_hw_ctx(AVFilterLink 
*outlink)
 hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
 hw_frame_ctx_out->width = outlink->w;
 hw_frame_ctx_out->height = outlink->h;
+((AVVTFramesContext *)hw_frame_ctx_out->hwctx)->color_range = 
((AVVTFramesContext *)hw_frame_ctx_in->hwctx)->color_range;
 
 err = ff_filter_init_hw_frames(avctx, outlink, 1);
 if (err < 0)
diff --git a/libavfilter/vf_yadif_videotoolbox.m 
b/libavfilter/vf_yadif_videotoolbox.m
index f77e7e86b5a..27fdadf1609 100644
--- a/libavfilter/vf_yadif_videotoolbox.m
+++ b/libavfilter/vf_yadif_videotoolbox.m
@@ -25,6 +25,7 @@
 #include "yadif.h"
 #include "libavutil/avassert.h"
 #include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_videotoolbox.h"
 #include "libavutil/objc.h"
 
 #include 
@@ -324,7 +325,8 @@ static int config_input(AVFilterLink *inlink)
 static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), 
ios(8.0))
 {
 FilterLink *l = ff_filter_link(link);
-AVHWFramesContext *output_frames;
+FilterLink *il = ff_filter_link(link->src->inputs[0]);
+AVHWFramesContext *output_frames, *input_frames;
 AVFilterContext *ctx = link->src;
 YADIFVTContext *s = ctx->priv;
 YADIFContext *y = &s->yadif;
@@ -346,12 +348,14 @@ static int do_config_output(AVFilterLink *link) 
API_AVAILABLE(macos(10.11), ios(
 goto exit;
 }
 
+input_frames = (AVHWFramesContext*)il->hw_frames_ctx->data;
 output_frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
 
 output_frames->format= AV_PIX_FMT_VIDEOTOOLBOX;
 output_frames->sw_format = s->input_frames->sw_format;
 output_frames->width = ctx->inputs[0]->w;
 output_frames->height= ctx->inputs[0]->h;
+((AVVTFramesContext *)output_frames->hwctx)->color_range = 
((AVVTFramesContext *)input_frames->hwctx)->color_range;
 
 ret = ff_filter_init_hw_frames(ctx, link, 10);
 if (ret < 0)
-- 
2.39.3 (Apple Git-146)

___
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] avcodec/bsf/dovi_rpu: remove EL when stripping dovi metadata

2024-10-15 Thread gnattu via ffmpeg-devel
When RPU is removed EL should also be removed. This only applies to
HEVC as AV1 based Profile 10 does not support EL at all.

Signed-off-by: Gnattu OC 
---
 libavcodec/bsf/dovi_rpu.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bsf/dovi_rpu.c b/libavcodec/bsf/dovi_rpu.c
index ae04d16360f..b4f80588e99 100644
--- a/libavcodec/bsf/dovi_rpu.c
+++ b/libavcodec/bsf/dovi_rpu.c
@@ -84,7 +84,8 @@ static int dovi_rpu_update_fragment_hevc(AVBSFContext *bsf, 
AVPacket *pkt,
 uint8_t *rpu = NULL;
 int rpu_size, ret;
 
-if (!nal || nal->type != HEVC_NAL_UNSPEC62)
+// HEVC_NAL_UNSPEC62 is Dolby Vision PRU and HEVC_NAL_UNSPEC63 is Dolby 
Vision EL
+if (!nal || (nal->type != HEVC_NAL_UNSPEC62 && nal->type != 
HEVC_NAL_UNSPEC63))
 return 0;
 
 if (s->strip) {
@@ -92,6 +93,10 @@ static int dovi_rpu_update_fragment_hevc(AVBSFContext *bsf, 
AVPacket *pkt,
 return 0;
 }
 
+if (nal->type == HEVC_NAL_UNSPEC63) {
+return 0;
+}
+
 ret = update_rpu(bsf, pkt, 0, nal->data + 2, nal->data_size - 2, &rpu, 
&rpu_size);
 if (ret < 0)
 return ret;
-- 
2.39.5 (Apple Git-154)

___
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] avutil/hwcontext_videotoolbox: Set proper CVBuffer colorspace

2024-05-20 Thread Gnattu OC via ffmpeg-devel



> On May 20, 2024, at 09:12, Marvin Scholz  wrote:
> 
> Fix #10884
> ---
> libavutil/hwcontext_videotoolbox.c | 54 +-
> 1 file changed, 38 insertions(+), 16 deletions(-)
> 
> diff --git a/libavutil/hwcontext_videotoolbox.c 
> b/libavutil/hwcontext_videotoolbox.c
> index 9f82b104c3..4a35bfc7ff 100644
> --- a/libavutil/hwcontext_videotoolbox.c
> +++ b/libavutil/hwcontext_videotoolbox.c
> @@ -530,6 +530,8 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum 
> AVColorTransferCharacteri
> static int vt_pixbuf_set_colorspace(void *log_ctx,
> CVPixelBufferRef pixbuf, const AVFrame 
> *src)
> {
> +CGColorSpaceRef colorspace = NULL;
> +CFMutableDictionaryRef attachments = NULL;
> CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
> Float32 gamma = 0;
> 
> @@ -550,37 +552,57 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
> else if (src->color_trc == AVCOL_TRC_GAMMA28)
> gamma = 2.8;
> 
> +attachments = CFDictionaryCreateMutable(NULL, 0,
> + 
> &kCFTypeDictionaryKeyCallBacks,
> + 
> &kCFTypeDictionaryValueCallBacks);
> +if (!attachments)
> +return AVERROR(ENOMEM);
> +
> if (colormatrix) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferYCbCrMatrixKey,
> -colormatrix,
> -kCVAttachmentMode_ShouldPropagate);
> +colormatrix);
> }
> if (colorpri) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferColorPrimariesKey,
> -colorpri,
> -kCVAttachmentMode_ShouldPropagate);
> +colorpri);
> }
> if (colortrc) {
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferTransferFunctionKey,
> -colortrc,
> -kCVAttachmentMode_ShouldPropagate);
> +colortrc);
> }
> if (gamma != 0) {
> CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, 
> &gamma);
> -CVBufferSetAttachment(
> -pixbuf,
> +CFDictionarySetValue(
> +attachments,
> kCVImageBufferGammaLevelKey,
> -gamma_level,
> -kCVAttachmentMode_ShouldPropagate);
> +gamma_level);
> CFRelease(gamma_level);
> }
> 
> +if (__builtin_available(macOS 10.8, iOS 10, *))
> +colorspace = 
> CVImageBufferCreateColorSpaceFromAttachments(attachments);
> +
> +if (colorspace) {
> +CFDictionarySetValue(
> +attachments,
> +kCVImageBufferCGColorSpaceKey,
> +colorspace);
> +CFRelease(colorspace);
> +} else
> +av_log(log_ctx, AV_LOG_WARNING, "Unable to set proper colorspace for 
> the CVImageBuffer.\n");

This will spam the console on SDR video inputs because they have nothing to be 
set as the attachment and the colorspace creation will always fail and return 
nil.

> +
> +CVBufferSetAttachments(
> +pixbuf,
> +attachments,
> +kCVAttachmentMode_ShouldPropagate);
> +CFRelease(attachments);
> +
> return 0;
> }
> 
> 
> base-commit: 463c573e6b6489c588bee90124d5cf92db8ccaaa
> -- 
> 2.39.3 (Apple Git-145)
> ___
> 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] hwcontext_videotoolbox: add vt_device_derive

2024-02-22 Thread Gnattu OC via ffmpeg-devel
Actually, if you examine the `hwcontext_videotoolbox.c` file, you will find 
that the current function for `vt_device_create` is essentially a no-op: it 
only returns an error if a user attempts to select a device, otherwise it just 
returns. This is generally how VideoToolbox works. If the `create_device` 
function is already a no-op, then the derive operation will certainly also be a 
no-op. All other hardware filters can utilize the derive API, and there are use 
cases that depend on this API. Thus, it seems inappropriate to me that 
VideoToolbox users cannot use the derive API just because VideoToolbox does not 
require any device creation.

> A libavfilter API user will set the correct hw_device_ctx on each filter and 
> your use-case will work properly

Can't this just be the modification of the `hwupload` filter? Instead of 
derive, the user just set the which initialized hardware to use, as 
`-init_hw_device` can already be called multiple times and creating alias for 
each hardware.

> On Feb 23, 2024, at 03:50, Mark Thompson  wrote:
> 
> On 22/02/2024 19:39, ChenLiucheng via ffmpeg-devel wrote:
>>> On Feb 23, 2024, at 03:28, Mark Thompson  wrote:
>>> 
>>> On 22/02/2024 18:46, gnattu via ffmpeg-devel wrote:
>>>> There is no device context to be setup, nor devices to be
>>>> selected with VideoToolbox. Just a simple return would allow
>>>> us to use derived device in filters like
>>>> `hwupload=derive_device=videotoolbox`
>>>> Signed-off-by: Gnattu OC 
>>>> ---
>>>>  libavutil/hwcontext_videotoolbox.c | 9 +
>>>>  1 file changed, 9 insertions(+)
>>>> diff --git a/libavutil/hwcontext_videotoolbox.c 
>>>> b/libavutil/hwcontext_videotoolbox.c
>>>> index fe469dc161..d13199eca7 100644
>>>> --- a/libavutil/hwcontext_videotoolbox.c
>>>> +++ b/libavutil/hwcontext_videotoolbox.c
>>>> @@ -759,6 +759,14 @@ static int vt_device_create(AVHWDeviceContext *ctx, 
>>>> const char *device,
>>>>  return 0;
>>>>  }
>>>>  +static int vt_device_derive(AVHWDeviceContext *device_ctx,
>>>> +AVHWDeviceContext *src_ctx, AVDictionary 
>>>> *opts,
>>>> +int flags)
>>>> +{
>>>> +// There is no context to be setup with VT, just return.
>>>> +return 0;
>>>> +}
>>>> +
>>>>  const HWContextType ff_hwcontext_type_videotoolbox = {
>>>>  .type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
>>>>  .name = "videotoolbox",
>>>> @@ -766,6 +774,7 @@ const HWContextType ff_hwcontext_type_videotoolbox = {
>>>>  .frames_priv_size = sizeof(VTFramesContext),
>>>>.device_create= vt_device_create,
>>>> +.device_derive= vt_device_derive,
>>>>  .frames_hwctx_size= sizeof(AVVTFramesContext),
>>>>  .frames_init  = vt_frames_init,
>>>>  .frames_get_buffer= vt_get_buffer,
>>> 
>>> This derivation behaviour doesn't make any sense inside libavutil.  
>>> Features which are only for the ffmpeg utility should be implemented inside 
>>> the ffmpeg utility.
>>> 
>>> (Also, try -init_hw_device.)
>>> 
> > Well this does make sense.
> >
> > If only one type of hardware device is in use, then `-init_hw_device` will 
> > suffice. However, if we use hardware filters with different device types, 
> > such as OpenCL, and we want to switch to a VideoToolbox filter later in the 
> > chain, we will have a issue. Since there is no `hwmap` between OpenCL and 
> > VideoToolbox, we need to perform a `hwdownload` followed by a `hwupload`. 
> > If the `derive_device` option cannot be used with `hwupload` due to 
> > `device_derive` not being implemented, the filter will struggle to find the 
> > correct device for uploading. It may attempt to upload to the OpenCL device 
> > without `device_derive` set if it comes after an OpenCL filter.
> >
> 
> Yes, it is unfortunate that the ffmpeg utility is missing this feature.
> 
> A libavfilter API user will set the correct hw_device_ctx on each filter and 
> your use-case will work properly, but the ffmpeg utility does not fully 
> expose the functionality of libavfilter to be able to do this.
> 
> This is mostly for syntax reasons; implementation would be straightforward.  
> If you can think of a good way to represent this in options to the ffmpeg 
> utility (which doesn't become too horrible with escaping) then I would very 
> much welcome suggestions.
> 
> Thanks,
> 
> - 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".


Re: [FFmpeg-devel] [PATCH v3] avfilter: add vf_overlay_videotoolbox

2024-02-23 Thread Gnattu OC via ffmpeg-devel
A ping for this.

> On Feb 21, 2024, at 09:53, gnattu  wrote:
> 
> Overlay filter for VideoToolbox hwframes. Unlike most hardware
> overlay filters, this filter does not require the two inputs to
> have the same pixel format; instead, it will perform format
> conversion automatically with hardware accelerated methods.
> 
> Signed-off-by: Gnattu OC 
> ---
> Changelog |   1 +
> configure |   1 +
> doc/filters.texi  |  52 ++
> libavfilter/Makefile  |   3 +
> libavfilter/allfilters.c  |   1 +
> libavfilter/metal/utils.h |   1 -
> libavfilter/metal/utils.m |   7 +-
> .../metal/vf_overlay_videotoolbox.metal   |  58 ++
> libavfilter/vf_overlay_videotoolbox.m | 551 ++
> 9 files changed, 672 insertions(+), 3 deletions(-)
> create mode 100644 libavfilter/metal/vf_overlay_videotoolbox.metal
> create mode 100644 libavfilter/vf_overlay_videotoolbox.m
> 
> diff --git a/Changelog b/Changelog
> index 610ee61dd6..3ecfdab81b 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -27,6 +27,7 @@ version :
> - a C11-compliant compiler is now required; note that this requirement
>   will be bumped to C17 in the near future, so consider updating your
>   build environment if it lacks C17 support
> +- VideoToolbox overlay filter
> 
> version 6.1:
> - libaribcaption decoder
> diff --git a/configure b/configure
> index 23066efa32..a7c349d126 100755
> --- a/configure
> +++ b/configure
> @@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
> overlay_qsv_filter_select="qsvvpp"
> overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
> overlay_vulkan_filter_deps="vulkan spirv_compiler"
> +overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
> owdenoise_filter_deps="gpl"
> pad_opencl_filter_deps="opencl"
> pan_filter_deps="swresample"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index e0436a5755..bfb77562cb 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -19033,6 +19033,58 @@ See @ref{framesync}.
> 
> This filter also supports the @ref{framesync} options.
> 
> +@section overlay_videotoolbox
> +
> +Overlay one video on top of another.
> +
> +This is the VideoToolbox variant of the @ref{overlay} filter.
> +It takes two inputs and has one output. The first input is the "main" video 
> on which the second input is overlaid.
> +It only accepts VideoToolbox frames. The underlying input pixel formats do 
> not have to match.
> +Different input pixel formats and color spaces will be automatically 
> converted using hardware accelerated methods.
> +The final output will have the same pixel format and color space as the 
> "main" input.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +
> +@item x
> +Set the x coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item y
> +Set the y coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item eof_action
> +See @ref{framesync}.
> +
> +@item shortest
> +See @ref{framesync}.
> +
> +@item repeatlast
> +See @ref{framesync}.
> +
> +@end table
> +
> +@subsection Examples
> +
> +@itemize
> +@item
> +Overlay an image LOGO at the top-left corner of the INPUT video.
> +The INPUT video is in nv12 format and the LOGO image is in rgba format.
> +@example
> +-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
> -filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
> [a][b]overlay_videotoolbox" OUTPUT
> +@end example
> +@item
> +Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
> +The INPUT video is in p010 format and the LOGO image is in nv12 format.
> +The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
> +@example
> +-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
> hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
> [1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
> +@end example
> +
> +@end itemize
> +
> @section owdenoise
> 
> Apply Overcomplete Wavelet denoiser.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index f6c1d641d6..ea1389ab57 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -413,6 +413,9 @@ OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += 
> vf_ov

Re: [FFmpeg-devel] [PATCH] hwcontext_videotoolbox: add vt_device_derive

2024-02-23 Thread Gnattu OC via ffmpeg-devel
I’ve tested and confirmed to work, and `reverse=1` also works for chaining to 
other videotoolbox filters. 

> On Feb 23, 2024, at 22:25, Zhao Zhili  wrote:
> 
> ___
> 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 v4] avfilter: add vf_overlay_videotoolbox

2024-03-05 Thread Gnattu OC via ffmpeg-devel
A ping for this as it is already a week.

> On Feb 28, 2024, at 00:35, gnattu via ffmpeg-devel  
> wrote:
> 
> Overlay filter for VideoToolbox hwframes. Unlike most hardware
> overlay filters, this filter does not require the two inputs to
> have the same pixel format; instead, it will perform format
> conversion automatically with hardware accelerated methods.
> 
> Signed-off-by: Gnattu OC 
> ---
> Changes from v3:
> 
> - Fixes an issue that 8bit depth BGRA overlay frames are not correctly 
> converted to 16bit
> - Added a constraint to input pixel formats as VideoToolbox cannot convert 
> all of its hardwareframes
> 
> Changelog |   1 +
> configure |   1 +
> doc/filters.texi  |  52 ++
> libavfilter/Makefile  |   3 +
> libavfilter/allfilters.c  |   1 +
> libavfilter/metal/utils.m |   7 +-
> .../metal/vf_overlay_videotoolbox.metal   |  58 ++
> libavfilter/vf_overlay_videotoolbox.m | 609 ++
> 8 files changed, 730 insertions(+), 2 deletions(-)
> create mode 100644 libavfilter/metal/vf_overlay_videotoolbox.metal
> create mode 100644 libavfilter/vf_overlay_videotoolbox.m
> 
> diff --git a/Changelog b/Changelog
> index 610ee61dd6..3ecfdab81b 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -27,6 +27,7 @@ version :
> - a C11-compliant compiler is now required; note that this requirement
>   will be bumped to C17 in the near future, so consider updating your
>   build environment if it lacks C17 support
> +- VideoToolbox overlay filter
> 
> version 6.1:
> - libaribcaption decoder
> diff --git a/configure b/configure
> index 23066efa32..a7c349d126 100755
> --- a/configure
> +++ b/configure
> @@ -3807,6 +3807,7 @@ overlay_qsv_filter_deps="libmfx"
> overlay_qsv_filter_select="qsvvpp"
> overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
> overlay_vulkan_filter_deps="vulkan spirv_compiler"
> +overlay_videotoolbox_filter_deps="metal corevideo coreimage videotoolbox"
> owdenoise_filter_deps="gpl"
> pad_opencl_filter_deps="opencl"
> pan_filter_deps="swresample"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index e0436a5755..bfb77562cb 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -19033,6 +19033,58 @@ See @ref{framesync}.
> 
> This filter also supports the @ref{framesync} options.
> 
> +@section overlay_videotoolbox
> +
> +Overlay one video on top of another.
> +
> +This is the VideoToolbox variant of the @ref{overlay} filter.
> +It takes two inputs and has one output. The first input is the "main" video 
> on which the second input is overlaid.
> +It only accepts VideoToolbox frames. The underlying input pixel formats do 
> not have to match.
> +Different input pixel formats and color spaces will be automatically 
> converted using hardware accelerated methods.
> +The final output will have the same pixel format and color space as the 
> "main" input.
> +
> +The filter accepts the following options:
> +
> +@table @option
> +
> +@item x
> +Set the x coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item y
> +Set the y coordinate of the overlaid video on the main video.
> +Default value is @code{0}.
> +
> +@item eof_action
> +See @ref{framesync}.
> +
> +@item shortest
> +See @ref{framesync}.
> +
> +@item repeatlast
> +See @ref{framesync}.
> +
> +@end table
> +
> +@subsection Examples
> +
> +@itemize
> +@item
> +Overlay an image LOGO at the top-left corner of the INPUT video.
> +The INPUT video is in nv12 format and the LOGO image is in rgba format.
> +@example
> +-hwaccel videotoolbox -i INPUT -i LOGO -codec:v:0 h264_videotoolbox 
> -filter_complex "[0:v]format=nv12,hwupload[a], [1:v]format=rgba,hwupload[b], 
> [a][b]overlay_videotoolbox" OUTPUT
> +@end example
> +@item
> +Overlay an SDR video OVERLAY at the top-left corner of the HDR video MAIN.
> +The INPUT video is in p010 format and the LOGO image is in nv12 format.
> +The OUTPUT video will also be an HDR video with OVERLAY mapped to HDR.
> +@example
> +-hwaccel videotoolbox -i MAIN -i OVERLAY -codec:v:0 hevc_videotoolbox -tag:v 
> hvc1 -filter_complex "[0:v]format=p010,hwupload[a], 
> [1:v]format=nv12,hwupload[b], [a][b]overlay_videotoolbox" OUTPUT
> +@end example
> +
> +@end itemize
> +
> @section owdenoise
> 
> Apply Overcomplete Wavelet denoiser.
> diff --git a/libavfilter/Makefile b/libavf

Re: [FFmpeg-devel] duplicate symbol '_dec_init' in: fftools/ffmpeg_dec.o

2024-03-16 Thread Gnattu OC via ffmpeg-devel
If you are using Xcode >= 15 then you will need to add `-Wl,-ld_classic` to 
LDFLAGS.  During configure you will also need to set 
`--host-ldflags='-Wl,-ld_classic’`.

> On Mar 16, 2024, at 09:04, Helmut K. C. Tessarek  wrote:
> 
> Hello,
> 
> It's me again - the dude who compiles ffmpeg for macOS... ;-)
> 
> I haven't updated the referenced libbluray, but only compiled ffmpeg the way 
> I always do. The last time was about 3 days ago and all was good.
> 
> This is the git hash of ffmpeg I tried to compile: b47abd5737
> 
> duplicate symbol '_dec_init' in:
>fftools/ffmpeg_dec.o
>/Users/Shared/ffmpeg/sw/lib/libbluray.a(libbluray_la-dec.o)
> ld: 1 duplicate symbol for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see 
> invocation)
> 
> The only code that changed was ffmpeg and libx265, thus I suspect it was a 
> change to ffmpeg. I can't really do a git bisect, because this error only 
> happens after ffmpeg is compiled at the linker stage, so that would take me 
> forever
> 
> However, the dev who did a change related to this would probably know right 
> away.
> 
> Cheers,
>  K. C.
> 
> 
> -- 
> regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944
> Key fingerprint = 8A55 70C1 BD85 D34E ADBC 386C 1723 80A0 11EF 4944
> 
> /*
>   Thou shalt not follow the NULL pointer for chaos and madness
>   await thee at its end.
> */
> ___
> 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] duplicate symbol '_dec_init' in: fftools/ffmpeg_dec.o

2024-03-17 Thread Gnattu OC via ffmpeg-devel
Can you try to change the `BD_PRIVATE` to 
`__attribute__((visibility("hidden")))` in the line defines `dec_init` 
src/libbluray/disc/dec.h then recompile libbluray to see if it fixes the 
linking issue?

> On Mar 17, 2024, at 05:09, Helmut K. C. Tessarek  wrote:
> 
> Hi,
> 
> On 2024-03-16 10:26, Christopher Degawa wrote:
>> Seems the conflict comes from
>> https://code.videolan.org/videolan/libbluray/-/blob/master/src/libbluray/disc/dec.c?ref_type=heads#L287
>>  and
>> https://github.com/FFmpeg/FFmpeg/commit/c4de5778bceab3c15f1239f1f16816749a7fd3b6
>> Perhaps you could also try asking libbluray if they could use an internal
>> prefix. Otherwise you might need to do a rename of that function on
>> ffmpeg's side.
> 
> Hmm, this commit in ffmpeg broke the possibility to link ffmpeg with 
> libbluray. Just to make this perfectly clear, before that commit it worked 
> without issues.
> 
> This means that nobody is able to use libbluray and ffmpeg from this point 
> forward. I am sorry, but this commit should be reverted.
> 
> The commit message reads: Rename dec_open to dec_init(), as it is more 
> descriptive of its new purpose.
> 
> Who cares about how descriptive it is as long as it works. Now it doesn't. 
> This was not a change to implement a feature or fix a bug, but a simple 
> refactor, because somebody didn't like the name.
> 
> In reality I agree with you that it might be better for libbluray to use a 
> prefix/namespace or whatever.  But until then, ffmpeg should still be able to 
> be linked with libbluray.
> 
> Is my standpoint unreasonable? If so, why?
> 
> Cheers,
>  K. C.
> 
> -- 
> regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944
> Key fingerprint = 8A55 70C1 BD85 D34E ADBC 386C 1723 80A0 11EF 4944
> 
> /*
>   Thou shalt not follow the NULL pointer for chaos and madness
>   await thee at its end.
> */
> ___
> 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] videotoolbox increases min target to macOS 12

2024-07-08 Thread Gnattu OC via ffmpeg-devel


> On Jul 9, 2024, at 13:47, Helmut K. C. Tessarek  wrote:
> 
> I'm very sorry to bother the dev list with this, but this is the 2nd time in 
> less than a year that the min version of macOS was changed in videotoolbox.
> 
> 2023-09-22: macOS 10.13
> now: macOS 12
> 
> Will ffmpeg soon only compile on the current release of macOS (with 
> videtoolbox support)? While I understand that too old OS versions are not 
> necessarily the best idea, a lot of people still use older versions. 
> Especially when it comes to Intel based static binaries.
> 
> I just want to ask what the devs think of this situation.
> I'm not saying that this has to be fixed. (I just removed the videotoolbox 
> support from my binaries.)
> 
> I'd asked in a forum, but there is none, nor is there another way to ask the 
> devs a question. And it is a question to the devs:
> 
> Is it feasible that this code raises the minimum depolyment target that 
> often, while the rest of ffmpeg just works perfectly fine with lower 
> deployment targets?

Well the code introduced is to fix certain HDR related bugs and it does not 
"works perfectly” before, it was just broken.
> 
> Cheers,
>  K. C.
> 
> Here  is the error message when compiling ffmpeg for reference:
> 
> libavutil/hwcontext_videotoolbox.c:592:39: error: 'CVBufferCopyAttachments' 
> is only available on macOS 12.0 or newer 
> [-Werror,-Wunguarded-availability-new]
>CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, 
> kCVAttachmentMode_ShouldPropagate);

This should be fixed by this patch: 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_386ebee5491311084f93f9136a75c4090...@qq.com/

so that it should at least compile on older OS targets.
But the end result is that the colorspace is as wrong as before, an older 
version cannot receive the fix to set the correct colorspace.

For this use case I could see that using the (now deprecated) 
`CVBufferGetAttachments` instead on older OS, but I cannot really test that 
because I don’t have device running that old version.
>  ^~~
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreVideo.framework/Headers/CVBuffer.h:160:59:
>  note: 'CVBufferCopyAttachments' has been marked as being introduced in macOS 
> 12.0 here, but the deployment target is macOS 10.13.0
> CV_EXPORT CFDictionaryRef CF_RETURNS_RETAINED CV_NULLABLE 
> CVBufferCopyAttachments( CVBufferRef CV_NONNULL buffer, CVAttachmentMode 
> attachmentMode ) API_AVAILABLE(macos(12.0), ios(15.0), tvos(15.0), 
> watchos(8.0));
>  ^
> libavutil/hwcontext_videotoolbox.c:592:39: note: enclose 
> 'CVBufferCopyAttachments' in a __builtin_available check to silence this 
> warning
>CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, 
> kCVAttachmentMode_ShouldPropagate);
>  ^~~
> 1 error generated.
> 
> 
> -- 
> regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944
> Key fingerprint = 8A55 70C1 BD85 D34E ADBC 386C 1723 80A0 11EF 4944
> 
> /*
>   Thou shalt not follow the NULL pointer for chaos and madness
>   await thee at its end.
> */
> ___
> 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] avutil/hwcontext_videotoolbox: Fix build with older SDKs

2024-07-21 Thread Gnattu OC via ffmpeg-devel



> On Jul 22, 2024, at 06:04, Sean McGovern  wrote:
> 
> Hi Marvin,
> 
> 
> On Tue, Jul 9, 2024, 10:47 Marvin Scholz  wrote:
> 
>> I've accidentally used API not available on the checked version.
>> Additionally check for the SDK to be new enough to even have the
>> CVImageBufferCreateColorSpaceFromAttachments API to not fail
>> the build.
>> ---
>> libavutil/hwcontext_videotoolbox.c | 15 ++-
>> 1 file changed, 14 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavutil/hwcontext_videotoolbox.c
>> b/libavutil/hwcontext_videotoolbox.c
>> index 953155ce32..ab7556936d 100644
>> --- a/libavutil/hwcontext_videotoolbox.c
>> +++ b/libavutil/hwcontext_videotoolbox.c
>> @@ -588,13 +588,26 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>> } else
>> CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
>> 
>> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
>> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
>> if (__builtin_available(macOS 10.8, iOS 10, *)) {
>> -CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf,
>> kCVAttachmentMode_ShouldPropagate);
>> +CFDictionaryRef attachments = NULL;
>> +if (__builtin_available(macOS 12.0, iOS 15.0, *))
>> +attachments = CVBufferCopyAttachments(pixbuf,
>> kCVAttachmentMode_ShouldPropagate);
>> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 12) || \
>> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 15)
>> +else {
>> +CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf,
>> kCVAttachmentMode_ShouldPropagate);
>> +if (tmp)
>> +attachments = CFDictionaryCreateCopy(NULL, tmp);
>> +}
>> +#endif
>> if (attachments) {
>> colorspace =
>> CVImageBufferCreateColorSpaceFromAttachments(attachments);
>> CFRelease(attachments);
>> }
>> }
>> +#endif
>> 
>> if (colorspace) {
>> CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
>> 
>> base-commit: 9fb8d13d56f20728141fd7070d8a325720727d57
>> --
>> 2.39.3 (Apple Git-146)
>> ___
>> 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".
>> 
> 
> Should this have fixed the Apple M1 FATE node [1]? It seems to be still
> failing.
> 
> -- Sean McGovern
> 
> [1] https://fate.ffmpeg.org/history.cgi?slot=aarch64-osx-clang-1200.0.32.29

I sent another patch that does the availability check at configure time which 
should fix the fate CI:
https://ffmpeg.org//pipermail/ffmpeg-devel/2024-July/331496.html

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

___
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] avutil/hwcontext_videotoolbox: Fix build with older SDKs

2024-07-21 Thread Gnattu OC via ffmpeg-devel



> On Jul 22, 2024, at 06:45, Gnattu OC via ffmpeg-devel 
>  wrote:
> 
> 
> 
>> On Jul 22, 2024, at 06:04, Sean McGovern  wrote:
>> 
>> Hi Marvin,
>> 
>> 
>> On Tue, Jul 9, 2024, 10:47 Marvin Scholz  wrote:
>> 
>>> I've accidentally used API not available on the checked version.
>>> Additionally check for the SDK to be new enough to even have the
>>> CVImageBufferCreateColorSpaceFromAttachments API to not fail
>>> the build.
>>> ---
>>> libavutil/hwcontext_videotoolbox.c | 15 ++-
>>> 1 file changed, 14 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/libavutil/hwcontext_videotoolbox.c
>>> b/libavutil/hwcontext_videotoolbox.c
>>> index 953155ce32..ab7556936d 100644
>>> --- a/libavutil/hwcontext_videotoolbox.c
>>> +++ b/libavutil/hwcontext_videotoolbox.c
>>> @@ -588,13 +588,26 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>>>} else
>>>CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
>>> 
>>> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
>>> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
>>>if (__builtin_available(macOS 10.8, iOS 10, *)) {
>>> -CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf,
>>> kCVAttachmentMode_ShouldPropagate);
>>> +CFDictionaryRef attachments = NULL;
>>> +if (__builtin_available(macOS 12.0, iOS 15.0, *))
>>> +attachments = CVBufferCopyAttachments(pixbuf,
>>> kCVAttachmentMode_ShouldPropagate);
>>> +#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED <= 12) || \
>>> +(TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED <= 15)
>>> +else {
>>> +CFDictionaryRef tmp = CVBufferGetAttachments(pixbuf,
>>> kCVAttachmentMode_ShouldPropagate);
>>> +if (tmp)
>>> +attachments = CFDictionaryCreateCopy(NULL, tmp);
>>> +}
>>> +#endif
>>>if (attachments) {
>>>colorspace =
>>> CVImageBufferCreateColorSpaceFromAttachments(attachments);
>>>CFRelease(attachments);
>>>}
>>>}
>>> +#endif
>>> 
>>>if (colorspace) {
>>>CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
>>> 
>>> base-commit: 9fb8d13d56f20728141fd7070d8a325720727d57
>>> --
>>> 2.39.3 (Apple Git-146)
>>> ___
>>> 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".
>>> 
>> 
>> Should this have fixed the Apple M1 FATE node [1]? It seems to be still
>> failing.
>> 
>> -- Sean McGovern
>> 
>> [1] https://fate.ffmpeg.org/history.cgi?slot=aarch64-osx-clang-1200.0.32.29
> 
> I sent another patch that does the availability check at configure time which 
> should fix the fate CI:
> https://ffmpeg.org//pipermail/ffmpeg-devel/2024-July/331496.html
> 
Sorry, should be this one: 
https://ffmpeg.org//pipermail/ffmpeg-devel/2024-July/331499.html
>> 
>>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org <mailto:ffmpeg-devel-requ...@ffmpeg.org> 
>> with subject "unsubscribe".
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org <mailto: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] avutil/hwcontext_videotoolbox: Allocate attachments dictionary

2024-08-01 Thread Gnattu OC via ffmpeg-devel


Replaced by: https://ffmpeg.org//pipermail/ffmpeg-devel/2024-August/331962.html

> On Aug 2, 2024, at 06:47, epira...@gmail.com wrote:
> 
> 
> 
> On 2 Aug 2024, at 0:25, gnattu via ffmpeg-devel wrote:
> 
>> From: Gnattu OC 
>> 
>> Allocate a dedicated attachments dictionary instead of trying to get
>> one from the pixel buffer. The attachments got from the pixel buffer
>> confuses the CVImageBufferCreateColorSpaceFromAttachments method and
>> will make it to output a wrong colorspace that causes problem like
>> #10884.
> 
> Thanks for the patch. Looks fine in principle given this was essentially
> how I did it before.
> 
> Did you check if maybe removing the kCVImageBufferCGColorSpaceKey by doing
> CVBufferRemoveAttachment(pixbuf, kCVImageBufferCGColorSpaceKey); before
> calling CVImageBufferCreateColorSpaceFromAttachments() is enough to make
> it work with the attachments obtained from the pixel buffer?
> 
>> 
>> Signed-off-by: gnattu 
>> ---
>> libavutil/hwcontext_videotoolbox.c | 35 ++
>> 1 file changed, 21 insertions(+), 14 deletions(-)
>> 
>> diff --git a/libavutil/hwcontext_videotoolbox.c 
>> b/libavutil/hwcontext_videotoolbox.c
>> index 1794459943..dda6ada1af 100644
>> --- a/libavutil/hwcontext_videotoolbox.c
>> +++ b/libavutil/hwcontext_videotoolbox.c
>> @@ -569,11 +569,19 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>> CGColorSpaceRef colorspace = NULL;
>> CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
>> Float32 gamma = 0;
>> +CFMutableDictionaryRef attachments = NULL;
>> +attachments = CFDictionaryCreateMutable(NULL, 0,
>> +&kCFTypeDictionaryKeyCallBacks,
>> +
>> &kCFTypeDictionaryValueCallBacks);
>> +if (!attachments)
>> +return AVERROR(ENOMEM);
>> 
>> colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace);
>> -if (colormatrix)
>> +if (colormatrix) {
>> +CFDictionarySetValue(attachments, kCVImageBufferYCbCrMatrixKey, 
>> colormatrix);
>> CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey,
>> -colormatrix, kCVAttachmentMode_ShouldPropagate);
>> +  colormatrix, 
>> kCVAttachmentMode_ShouldPropagate);
>> +}
>> else {
>> CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
>> if (src->colorspace != AVCOL_SPC_UNSPECIFIED)
>> @@ -583,9 +591,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>> }
>> 
>> colorpri = 
>> av_map_videotoolbox_color_primaries_from_av(src->color_primaries);
>> -if (colorpri)
>> +if (colorpri) {
>> +CFDictionarySetValue(attachments, kCVImageBufferColorPrimariesKey, 
>> colorpri);
>> CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey,
>> -colorpri, kCVAttachmentMode_ShouldPropagate);
>> +  colorpri, kCVAttachmentMode_ShouldPropagate);
>> +}
>> else {
>> CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey);
>> if (src->color_primaries != AVCOL_SPC_UNSPECIFIED)
>> @@ -595,9 +605,11 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>> }
>> 
>> colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
>> -if (colortrc)
>> +if (colortrc) {
>> +CFDictionarySetValue(attachments, 
>> kCVImageBufferTransferFunctionKey, colortrc);
>> CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
>> -colorpri, kCVAttachmentMode_ShouldPropagate);
>> +  colorpri, kCVAttachmentMode_ShouldPropagate);
>> +}
>> else {
>> CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
>> if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
>> @@ -622,17 +634,12 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
>> #if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100800) || \
>> (TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 10)
>> if (__builtin_available(macOS 10.8, iOS 10, *)) {
>> -CFDictionaryRef attachments =
>> -vt_cv_buffer_copy_attachments(pixbuf, 
>> kCVAttachmentMode_ShouldPropagate);
>> -
>> -if (attachments) {
>> -colorspace =
>> -CVImageBufferCreateColorSpaceFromAttachmen

Re: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: always release supported_props

2024-08-15 Thread Gnattu OC via ffmpeg-devel


> On Aug 15, 2024, at 19:59, Zhao Zhili  wrote:
> 
> 
> 
>> On Aug 10, 2024, at 14:06, gnattu via ffmpeg-devel  
>> wrote:
>> 
>> In vtenc_populate_extradata, supported_props should always be released
>> to avoid memory leak.
>> 
>> Regression from cd2f8a22e94700c68b1de7968df11e8bebfd315b
>> 
>> Signed-off-by: gnattu 
>> ---
>> libavcodec/videotoolboxenc.c | 13 ++---
>> 1 file changed, 10 insertions(+), 3 deletions(-)
>> 
>> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> index 78ef474d7ae..6cc45db4a96 100644
>> --- a/libavcodec/videotoolboxenc.c
>> +++ b/libavcodec/videotoolboxenc.c
>> @@ -2787,9 +2787,16 @@ pe_cleanup:
>> 
>>if (status) {
>>vtenc_reset(vtctx);
>> -} else if (vtctx->session) {
>> -CFRelease(vtctx->session);
>> -vtctx->session = NULL;
>> +} else {
>> +if (vtctx->session) {
>> +CFRelease(vtctx->session);
>> +vtctx->session = NULL;
>> +}
>> +
>> +if (vtctx->supported_props) {
>> +CFRelease(vtctx->supported_props);
>> +vtctx->supported_props = NULL;
>> +}
>>}
> 
> Could you elaborate on how supported_props is leaked? Isn’t it cleaned by
> vtenc_close -> vtenc_reset?

In the function `vtenc_populate_extradata`, a call is made to 
`vtenc_create_encoder` to create a `VTCompressionSession`. During this process, 
a `supported_props` dictionary is created. However, if the status is 0, only 
the compression session is released, while `supported_props` remains allocated. 

Later, in `vtenc_configure_encoder`, `vtenc_create_encoder` is called again 
after `vtenc_populate_extradata` returns. This call replaces the reference to 
`supported_props` with a new dictionary, causing the reference to the old one 
(created in `vtenc_populate_extradata`) to be lost. As a result, when 
`vtenc_close -> vtenc_reset` is called, it will only release the most recent 
`supported_props`, leading to a memory leak as all previous allocations are not 
properly released.

> 
>> 
>>vtctx->frame_ct_out = 0;
>> -- 
>> 2.39.3 (Apple Git-146)
>> 
>> ___
>> 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 <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org <mailto: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] libavdevice: fix compilation for Mac OS X 10.7-10.12, iOS < 11

2024-08-20 Thread Gnattu OC via ffmpeg-devel


> On Aug 21, 2024, at 07:17, epira...@gmail.com wrote:
> 
> 
> 
> On 21 Aug 2024, at 0:43, Erik Bråthen Solem wrote:
> 
>> avfoundation.m uses constants prefixed with AVMediaType on Mac OS X > 10.6.
>> In 10.7 through 10.12 their type was NSString*, but starting with 10.13 a
>> new AVMediaType struct type was introduced. In avfoundation.m, the function
>> getDevicesWithMediaType takes this struct as parameter, which breaks support
>> for Mac OS X 10.7 through 10.12. By typedef-ing AVMediaType to NSString* for
>> these versions, the code compiles. Prior to 10.15 the value is passed to a
>> function that takes AVMediaType on 10.13+ and NSString* on <= 10.12. The
>> same API change was introduced in iOS starting with iOS 11.
>> 
> 
> Hi, thanks for the patch. Conceptually looks fine to me.
> 
> See my remark below:
> 
>> Signed-off-by: Erik Bråthen Solem 
>> ---
>> libavdevice/avfoundation.m | 4 
>> 1 file changed, 4 insertions(+)
>> 
>> diff --git a/libavdevice/avfoundation.m b/libavdevice/avfoundation.m
>> index c5a09c6563..779bc767d6 100644
>> --- a/libavdevice/avfoundation.m
>> +++ b/libavdevice/avfoundation.m
>> @@ -763,6 +763,10 @@ static int get_audio_config(AVFormatContext *s)
>>return 0;
>> }
>> 
>> +#if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < 11) || 
>> (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300))
>> +typedef NSString* AVMediaType;
>> +#endif
> 
> I do not think this is the proper guard here? You want to check *_MAX_ALLOWED 
> if you want to check the SDK version,
> which is what controls these change (as the SDK changed) not the minimum 
> version you target when compiling.

This depends on use case though. For example, compiling on high version SDK, 
but targeting low version SDK and selectively
load high version symbols during the runtime should not use *_MAX_ALLOWED 
because that will disable higher version symbols
at build time which prevents the usage of the runtime version check.

> 
>> +
>> static NSArray* getDevicesWithMediaType(AVMediaType mediaType) {
>> #if ((TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 10) || 
>> (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500))
>>NSMutableArray *deviceTypes = nil;
>> -- 
>> 2.46.0
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org 
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org  with 
> subject "unsubscribe".

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