[FFmpeg-devel] [PATCH WIP 4/5] avcodec/hevc/sei: Add support for alpha channel information

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/hevc/sei.c | 30 ++
 libavcodec/hevc/sei.h | 14 ++
 2 files changed, 44 insertions(+)

diff --git a/libavcodec/hevc/sei.c b/libavcodec/hevc/sei.c
index e11a33773c..56983fe96e 100644
--- a/libavcodec/hevc/sei.c
+++ b/libavcodec/hevc/sei.c
@@ -150,6 +150,34 @@ static int decode_nal_sei_timecode(HEVCSEITimeCode *s, 
GetBitContext *gb)
 return 0;
 }
 
+static int decode_nal_sei_alpha_info(HEVCSEIAlphaChannelInfo *s, GetBitContext 
*gb)
+{
+int length;
+
+s->has_alpha_channel_info = true;
+
+s->alpha_channel_cancel_flag = get_bits1(gb);
+if (!s->alpha_channel_cancel_flag) {
+s->alpha_channel_use_idc = 2;
+s->alpha_channel_incr_flag = 0;
+s->alpha_channel_clip_flag = 0;
+
+return 0;
+}
+
+s->alpha_channel_use_idc = get_bits(gb, 3);
+s->alpha_channel_bit_depth_minus8 = get_bits(gb, 3);
+length = s->alpha_channel_bit_depth_minus8 + 9;
+s->alpha_transparent_value = get_bits(gb, length);
+s->alpha_opaque_value = get_bits(gb, length);
+s->alpha_channel_incr_flag = get_bits1(gb);
+s->alpha_channel_clip_flag = get_bits1(gb);
+if (s->alpha_channel_clip_flag)
+s->alpha_channel_clip_type_flag = get_bits1(gb);
+
+return 0;
+}
+
 static int decode_nal_sei_3d_reference_displays_info(HEVCSEITDRDI *s, 
GetBitContext *gb)
 {
 s->prec_ref_display_width = get_ue_golomb(gb);
@@ -216,6 +244,8 @@ static int decode_nal_sei_prefix(GetBitContext *gb, 
GetByteContext *gbyte,
 return decode_nal_sei_active_parameter_sets(s, gb, logctx);
 case SEI_TYPE_TIME_CODE:
 return decode_nal_sei_timecode(&s->timecode, gb);
+case SEI_TYPE_ALPHA_CHANNEL_INFO:
+return decode_nal_sei_alpha_info(&s->alpha, gb);
 case SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO:
 return decode_nal_sei_3d_reference_displays_info(&s->tdrdi, gb);
 default: {
diff --git a/libavcodec/hevc/sei.h b/libavcodec/hevc/sei.h
index ee640003bc..54122c27df 100644
--- a/libavcodec/hevc/sei.h
+++ b/libavcodec/hevc/sei.h
@@ -21,6 +21,7 @@
 #ifndef AVCODEC_HEVC_SEI_H
 #define AVCODEC_HEVC_SEI_H
 
+#include 
 #include 
 
 #include "libavutil/buffer.h"
@@ -95,6 +96,18 @@ typedef struct HEVCSEITDRDI {
 uint8_t three_dimensional_reference_displays_extension_flag;
 } HEVCSEITDRDI;
 
+typedef struct HEVCSEIAlphaChannelInfo {
+bool has_alpha_channel_info;
+uint8_t  alpha_channel_cancel_flag;
+uint8_t  alpha_channel_use_idc;
+uint8_t  alpha_channel_bit_depth_minus8;
+uint16_t alpha_transparent_value;
+uint16_t alpha_opaque_value;
+uint8_t  alpha_channel_incr_flag;
+uint8_t  alpha_channel_clip_flag;
+uint8_t  alpha_channel_clip_type_flag;
+} HEVCSEIAlphaChannelInfo;
+
 typedef struct HEVCSEI {
 H2645SEI common;
 HEVCSEIPictureHash picture_hash;
@@ -102,6 +115,7 @@ typedef struct HEVCSEI {
 int active_seq_parameter_set_id;
 HEVCSEITimeCode timecode;
 HEVCSEITDRDI tdrdi;
+HEVCSEIAlphaChannelInfo alpha;
 } HEVCSEI;
 
 struct HEVCParamSets;
-- 
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] [PATCH WIP 2/5] avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

Remove a for loop and make it easy to extend to support other types
of scalability.
---
 libavcodec/hevc/hevc.h | 10 +-
 libavcodec/hevc/ps.c   | 25 +++--
 libavcodec/hevc/ps.h   |  2 ++
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index eae28b3b04..b2229fda40 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -163,11 +163,11 @@ enum {
 };
 
 enum HEVCScalabilityMask {
-HEVC_SCALABILITY_DEPTH  = 0,
-HEVC_SCALABILITY_MULTIVIEW  = 1,
-HEVC_SCALABILITY_SPATIAL= 2,
-HEVC_SCALABILITY_AUXILIARY  = 3,
-HEVC_SCALABILITY_MASK_MAX   = 15,
+HEVC_SCALABILITY_DEPTH  = 1 << (15 - 0),
+HEVC_SCALABILITY_MULTIVIEW  = 1 << (15 - 1),
+HEVC_SCALABILITY_SPATIAL= 1 << (15 - 2),
+HEVC_SCALABILITY_AUXILIARY  = 1 << (15 - 3),
+HEVC_SCALABILITY_MASK_MAX   = 0x,
 };
 
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index bd8a796c2d..5b1bcd9b7c 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -524,17 +524,22 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 return AVERROR_INVALIDDATA;
 
 splitting_flag = get_bits1(gb);
-num_scalability_types = 0;
-for (int i = 0; i <= HEVC_SCALABILITY_MASK_MAX; i++) {
-int scalability_mask_flag = get_bits1(gb);
-if (scalability_mask_flag && (i != HEVC_SCALABILITY_MULTIVIEW)) {
-av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n", 
i);
-return AVERROR_PATCHWELCOME;
-}
-num_scalability_types += scalability_mask_flag;
-}
-if (num_scalability_types != 1)
+vps->scalability_mask_flag = get_bits(gb, 16);
+num_scalability_types = av_popcount(vps->scalability_mask_flag);
+if (!num_scalability_types) {
+av_log(avctx, AV_LOG_ERROR, "Missing scalability mask\n");
 return AVERROR_INVALIDDATA;
+} else if (num_scalability_types > 1) {
+av_log(avctx, AV_LOG_ERROR, "Scalability number %d not supported\n",
+   num_scalability_types);
+return AVERROR_PATCHWELCOME;
+}
+
+if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
+   15 - ff_ctz(vps->scalability_mask_flag));
+return AVERROR_PATCHWELCOME;
+}
 
 if (!splitting_flag)
 dimension_id_len = get_bits(gb, 3) + 1;
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 6f5b1f8755..d3465e3d27 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -205,6 +205,8 @@ typedef struct HEVCVPS {
  */
 int nb_layers;
 
+uint16_t scalability_mask_flag;
+
 // LayerIdxInVps[nuh_layer_id], i.e. a mapping of nuh_layer_id to VPS layer
 // indices. Valid values are between 0 and HEVC_VPS_MAX_LAYERS. Entries for
 // unmapped values of nuh_layer_id are set to -1.
-- 
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] [PATCH WIP 5/5] avcodec/hevc: Add alpha layer support

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

---
 libavcodec/hevc/hevcdec.c | 75 ++-
 libavcodec/hevc/hevcdec.h |  2 ++
 libavcodec/hevc/refs.c| 10 +-
 3 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index be35a9de82..782c9382bc 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -458,6 +458,26 @@ static int export_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+int ff_hevc_is_alpha_video(const HEVCContext *s) {
+const HEVCVPS *vps;
+int ret = 0;
+
+if (!s->vps)
+return 0;
+
+vps = s->vps;
+if (vps->nb_layers != 2 || !vps->layer_id_in_nuh[1])
+return 0;
+
+ret = (s->vps->scalability_mask_flag & HEVC_SCALABILITY_AUXILIARY) &&
+  s->sei.alpha.has_alpha_channel_info;
+
+av_log(s->avctx, AV_LOG_DEBUG, "Multi layer video, %s alpha video\n",
+   ret ? "is" : "not");
+
+return ret;
+}
+
 static int setup_multilayer(HEVCContext *s, const HEVCVPS *vps)
 {
 unsigned layers_active_output = 0, highest_layer;
@@ -465,6 +485,18 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 s->layers_active_output = 1;
 s->layers_active_decode = 1;
 
+if (ff_hevc_is_alpha_video(s)) {
+const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(s->avctx->pix_fmt);
+
+if (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA))
+return 0;
+
+s->layers_active_decode = (1 << vps->nb_layers) - 1;
+s->layers_active_output = 1;
+
+return 0;
+}
+
 // nothing requested - decode base layer only
 if (!s->nb_view_ids)
 return 0;
@@ -522,6 +554,34 @@ static int setup_multilayer(HEVCContext *s, const HEVCVPS 
*vps)
 return 0;
 }
 
+static enum AVPixelFormat map_to_alpha_format(HEVCContext *s,
+  enum AVPixelFormat pix_fmt)
+{
+switch (pix_fmt) {
+case AV_PIX_FMT_YUV420P:
+case AV_PIX_FMT_YUVJ420P:
+return AV_PIX_FMT_YUVA420P;
+case AV_PIX_FMT_YUV420P10:
+return AV_PIX_FMT_YUVA420P10;
+case AV_PIX_FMT_YUV444P:
+return AV_PIX_FMT_YUVA444P;
+case AV_PIX_FMT_YUV422P:
+return AV_PIX_FMT_YUVA422P;
+case AV_PIX_FMT_YUV422P10LE:
+return AV_PIX_FMT_YUVA422P10LE;
+case AV_PIX_FMT_YUV444P10:
+return AV_PIX_FMT_YUVA444P10;
+case AV_PIX_FMT_YUV444P12:
+return AV_PIX_FMT_YUVA444P12;
+case AV_PIX_FMT_YUV422P12:
+return AV_PIX_FMT_YUVA422P12;
+default:
+av_log(s->avctx, AV_LOG_WARNING, "No alpha pixel format map for %s\n",
+   av_get_pix_fmt_name(pix_fmt));
+return AV_PIX_FMT_NONE;
+}
+}
+
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 {
 #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + \
@@ -532,9 +592,13 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
  CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
  CONFIG_HEVC_VDPAU_HWACCEL + \
  CONFIG_HEVC_VULKAN_HWACCEL)
-enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
+enum AVPixelFormat pix_fmts[HWACCEL_MAX + 3], *fmt = pix_fmts;
+enum AVPixelFormat alpha_fmt = AV_PIX_FMT_NONE;
 int ret;
 
+if (ff_hevc_is_alpha_video(s))
+alpha_fmt = map_to_alpha_format(s, sps->pix_fmt);
+
 switch (sps->pix_fmt) {
 case AV_PIX_FMT_YUV420P:
 case AV_PIX_FMT_YUVJ420P:
@@ -650,6 +714,8 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
 break;
 }
 
+if (alpha_fmt != AV_PIX_FMT_NONE)
+*fmt++ = alpha_fmt;
 *fmt++ = sps->pix_fmt;
 *fmt = AV_PIX_FMT_NONE;
 
@@ -3182,6 +3248,12 @@ static int hevc_frame_start(HEVCContext *s, 
HEVCLayerContext *l,
 !sps->vui.common.video_signal_type_present_flag)
 pix_fmt = sps_base->pix_fmt;
 
+// Ignore range mismatch between base layer and alpha layer
+if (ff_hevc_is_alpha_video(s) &&
+sps_base->pix_fmt == AV_PIX_FMT_YUV420P &&
+pix_fmt == AV_PIX_FMT_YUVJ420P)
+pix_fmt = sps_base->pix_fmt;
+
 if (pix_fmt != sps_base->pix_fmt ||
 sps->width  != sps_base->width   ||
 sps->height != sps_base->height) {
@@ -4004,6 +4076,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 s->sei.common.display_orientation  = s0->sei.common.display_orientation;
 s->sei.common.alternative_transfer = s0->sei.common.alternative_transfer;
 s->sei.tdrdi   = s0->sei.tdrdi;
+s->sei.alpha   = s0->sei.alpha;
 
 return 0;
 }
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 473709b4e8..f8ed156a1c 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -714,6 +714,8 @@ void ff_hevc_hls_residual_coding(HEVCLoc

[FFmpeg-devel] [PATCH WIP 3/5] avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

Only implementing what's needed for HEVC with alpha.
---
 libavcodec/hevc/ps.c | 64 +---
 libavcodec/hevc/ps.h |  1 +
 2 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 5b1bcd9b7c..59df750b91 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -460,14 +460,14 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
   uint64_t layer1_id_included)
 {
 PTL ptl_dummy;
-uint8_t max_sub_layers[HEVC_MAX_LAYERS];
+uint8_t max_sub_layers[HEVC_MAX_LAYERS] = {1, 1};
 
 int splitting_flag, dimension_id_len, view_id_len, num_add_olss, 
num_scalability_types,
 default_output_layer_idc, direct_dep_type_len, direct_dep_type,
 sub_layers_max_present, sub_layer_flag_info_present_flag, nb_ptl;
 unsigned non_vui_extension_length;
 
-if (vps->vps_max_layers == 1 || vps->vps_num_layer_sets == 1) {
+if (vps->vps_max_layers == 1) {
 av_log(avctx, AV_LOG_VERBOSE, "Ignoring VPS extensions with a single 
layer\n");
 return 0;
 }
@@ -535,7 +535,8 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext 
*avctx, HEVCVPS *vps
 return AVERROR_PATCHWELCOME;
 }
 
-if (!(vps->scalability_mask_flag & HEVC_SCALABILITY_MULTIVIEW)) {
+if (!(vps->scalability_mask_flag &
+  (HEVC_SCALABILITY_MULTIVIEW | HEVC_SCALABILITY_AUXILIARY))) {
 av_log(avctx, AV_LOG_ERROR, "Scalability type %d not supported\n",
15 - ff_ctz(vps->scalability_mask_flag));
 return AVERROR_PATCHWELCOME;
@@ -571,16 +572,25 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 for (int i = 0; i < 2 /* NumViews */; i++)
 vps->view_id[i] = get_bits(gb, view_id_len);
 
-if (!get_bits1(gb) /* direct_dependency_flag */) {
-av_log(avctx, AV_LOG_WARNING, "Independent output layers not 
supported\n");
-return AVERROR_PATCHWELCOME;
+/* direct_dependency_flag */
+vps->num_direct_ref_layers[1] = get_bits1(gb);
+if (!vps->num_direct_ref_layers[1]) {
+vps->num_add_layer_sets = get_ue_golomb(gb);
+for (int i = 0; i < vps->num_add_layer_sets; i++) {
+/* highest_layer_idx_plus1 */
+skip_bits1(gb);
+}
 }
-vps->num_direct_ref_layers[1] = 1;
+vps->num_output_layer_sets = vps->vps_num_layer_sets + 
vps->num_add_layer_sets;
+if (vps->num_output_layer_sets != 2)
+return AVERROR_INVALIDDATA;
 
 sub_layers_max_present = get_bits1(gb); // 
vps_sub_layers_max_minus1_present_flag
-for (int i = 0; i < vps->vps_max_layers; i++)
-max_sub_layers[i] = sub_layers_max_present ? get_bits(gb, 3) + 1 :
- vps->vps_max_sub_layers;
+if (sub_layers_max_present) {
+for (int i = 0; i < vps->vps_max_layers; i++)
+max_sub_layers[i] = sub_layers_max_present ? get_bits(gb, 3) + 1 :
+ 
vps->vps_max_sub_layers;
+}
 
 if (get_bits1(gb) /* max_tid_ref_present_flag */)
 skip_bits(gb, 3); // max_tid_il_ref_pics_plus1
@@ -613,18 +623,24 @@ static int decode_vps_ext(GetBitContext *gb, 
AVCodecContext *avctx, HEVCVPS *vps
 }
 
 /* Consequence of established layer dependencies */
-if (layer1_id_included != ((1 << vps->layer_id_in_nuh[0]) |
+if (layer1_id_included &&
+layer1_id_included != ((1 << vps->layer_id_in_nuh[0]) |
(1 << vps->layer_id_in_nuh[1]))) {
-av_log(avctx, AV_LOG_ERROR, "Dependent layer not included in layer 
ID?\n");
-return AVERROR_PATCHWELCOME;
+av_log(avctx, AV_LOG_ERROR,
+   "Dependent layer not included in layer ID?\n");
+return AVERROR_PATCHWELCOME;
 }
+if (!layer1_id_included)
+vps->ols[1] = 2;
+else
+vps->ols[1] = 3;
 
-vps->num_output_layer_sets = 2;
-vps->ols[1] = 3;
+if (vps->vps_num_layer_sets == 1 || default_output_layer_idc == 2)
+skip_bits1(gb);
 
 for (int j = 0; j < av_popcount64(vps->ols[1]); j++) {
 int ptl_idx = get_bits(gb, av_ceil_log2(nb_ptl));
-if (ptl_idx < 1 || ptl_idx >= nb_ptl) {
+if (ptl_idx >= nb_ptl) {
 av_log(avctx, AV_LOG_ERROR, "Invalid PTL index: %d\n", ptl_idx);
 return AVERROR_INVALIDDATA;
 }
@@ -667,6 +683,8 @@ static int decode_vps_ext(GetBitContext *gb, AVCodecContext 
*avctx, HEVCVPS *vps
 
 vps->max_one_active_ref_layer = get_bits1(gb);
 vps->poc_lsb_aligned  = get_bits1(gb);
+if (!vps->num_direct_ref_layers[1])
+vps->poc_lsb_not_present = get_bits1(gb) << 1;
 
 sub_layer_flag_info_present_flag = get_bits1(gb);
 for (int j = 0; j < FFMAX(max_sub_layers[0], max_sub_layers[1]); j++) {
@@ -688,12 +706,1

[FFmpeg-devel] [PATCH WIP 1/5] avcodec/hevc: Move ScalabilityMask to hevc header file

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

So it can be used in hevc decoder.
---
 libavcodec/hevc/hevc.h | 7 +++
 libavcodec/hevc/ps.c   | 8 
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevc.h b/libavcodec/hevc/hevc.h
index 8bd59142db..eae28b3b04 100644
--- a/libavcodec/hevc/hevc.h
+++ b/libavcodec/hevc/hevc.h
@@ -162,5 +162,12 @@ enum {
 HEVC_MAX_PALETTE_PREDICTOR_SIZE = 128,
 };
 
+enum HEVCScalabilityMask {
+HEVC_SCALABILITY_DEPTH  = 0,
+HEVC_SCALABILITY_MULTIVIEW  = 1,
+HEVC_SCALABILITY_SPATIAL= 2,
+HEVC_SCALABILITY_AUXILIARY  = 3,
+HEVC_SCALABILITY_MASK_MAX   = 15,
+};
 
 #endif /* AVCODEC_HEVC_HEVC_H */
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index a1d352eec5..bd8a796c2d 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -450,14 +450,6 @@ static void hevc_vps_free(FFRefStructOpaque opaque, void 
*obj)
 av_freep(&vps->data);
 }
 
-enum ScalabilityMask {
-HEVC_SCALABILITY_DEPTH  = 0,
-HEVC_SCALABILITY_MULTIVIEW  = 1,
-HEVC_SCALABILITY_SPATIAL= 2,
-HEVC_SCALABILITY_AUXILIARY  = 3,
-HEVC_SCALABILITY_MASK_MAX   = 15,
-};
-
 enum DependencyType {
 HEVC_DEP_TYPE_SAMPLE = 0,
 HEVC_DEP_TYPE_MV = 1,
-- 
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] [PATCH WIP 0/5] avcodec/hevc: Add alpha video decoding support

2024-12-10 Thread Zhao Zhili
From: Zhao Zhili 

What works:

1. Create a sample with macOS videotoolbox
ffmpeg -i base.mp4 -i alpha.mp4 \
-c:v hevc_videotoolbox -alpha_quality 0.5 -b:v 2M \
 -filter_complex 
'[0:v]scale,format=bgra[v0];[1:v]scale=640x480,format=gray[v1];[v0][v1]alphamerge[v2]'
 \
-map '[v2]' -y hevc-alpha.ts

Then you can remux it to mp4 if you prefer.

2. Decoding test

a. Check alpha plane
./ffmpeg -i hevc-alpha.ts -an -vf extractplanes=planes=a -f nut - |ffplay -

b. Check Y plane
./ffmpeg -i hevc-alpha.ts -an -vf extractplanes=planes=y -f nut - |ffplay -

What doesn't work:

1. Encoding with videotoolbox and output as mp4 directly, due to missing PS.
Can be fixed by

https://patchwork.ffmpeg.org/project/ffmpeg/patch/20241210191641.676-1-t...@rothenpieler.org/

2. vps_extension is over-engineering and decode_vps_ext() is far from complete.
A complete implementation might take a week, and I don't have enough spare time.
I would greatly appreciate it if someone could help implement it.

Branch on github:

https://github.com/quink-black/FFmpeg/tree/hevc-alpha-3

Zhao Zhili (5):
  avcodec/hevc: Move ScalabilityMask to hevc header file
  avcodec/hevc: Rewrite scalability_mask_flag parse in decode_vps_ext
  avcodec/hevc/ps: Add basic HEVC_SCALABILITY_AUXILIARY support
  avcodec/hevc/sei: Add support for alpha channel information
  avcodec/hevc: Add alpha layer support

 libavcodec/hevc/hevc.h|  7 +++
 libavcodec/hevc/hevcdec.c | 75 ++-
 libavcodec/hevc/hevcdec.h |  2 +
 libavcodec/hevc/ps.c  | 95 +++
 libavcodec/hevc/ps.h  |  3 ++
 libavcodec/hevc/refs.c| 10 -
 libavcodec/hevc/sei.c | 30 +
 libavcodec/hevc/sei.h | 14 ++
 8 files changed, 195 insertions(+), 41 deletions(-)

-- 
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] [PATCH 1/5] avutil/channel_layout: add a 9.1.6 layout

2024-12-10 Thread James Almer
Signed-off-by: James Almer 
---
 doc/utils.texi| 2 ++
 libavutil/channel_layout.c| 1 +
 libavutil/channel_layout.h| 2 ++
 tests/ref/fate/channel_layout | 1 +
 4 files changed, 6 insertions(+)

diff --git a/doc/utils.texi b/doc/utils.texi
index eb5ccc8355..9c50dac949 100644
--- a/doc/utils.texi
+++ b/doc/utils.texi
@@ -731,6 +731,8 @@ FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBL+TBR
 FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBC+LFE2
 @item 9.1.4
 FL+FR+FC+LFE+BL+BR+FLC+FRC+SL+SR+TFL+TFR+TBL+TBR
+@item 9.1.6
+FL+FR+FC+LFE+BL+BR+FLC+FRC+SL+SR+TFL+TFR+TBL+TBR+TSL+TSR
 @item hexadecagonal
 FL+FR+FC+BL+BR+BC+SL+SR+WL+WR+TBL+TBR+TBC+TFC+TFL+TFR
 @item binaural
diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index dd97e167c7..dcf102d57a 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -221,6 +221,7 @@ static const struct channel_layout_name 
channel_layout_map[] = {
 { "7.1.4",  AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK  },
 { "7.2.3",  AV_CHANNEL_LAYOUT_7POINT2POINT3   },
 { "9.1.4",  AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK  },
+{ "9.1.6",  AV_CHANNEL_LAYOUT_9POINT1POINT6   },
 { "hexadecagonal",  AV_CHANNEL_LAYOUT_HEXADECAGONAL   },
 { "binaural",   AV_CHANNEL_LAYOUT_BINAURAL},
 { "downmix",AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, },
diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index 23fbc90606..4e0be7bed2 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -248,6 +248,7 @@ enum AVChannelOrder {
 #define AV_CH_LAYOUT_7POINT1POINT4_BACK 
(AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)
 #define AV_CH_LAYOUT_7POINT2POINT3 
(AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_CENTER|AV_CH_LOW_FREQUENCY_2)
 #define AV_CH_LAYOUT_9POINT1POINT4_BACK 
(AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_LAYOUT_9POINT1POINT6 
(AV_CH_LAYOUT_9POINT1POINT4_BACK|AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT)
 #define AV_CH_LAYOUT_HEXADECAGONAL 
(AV_CH_LAYOUT_OCTAGONAL|AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)
 #define AV_CH_LAYOUT_BINAURAL  
(AV_CH_BINAURAL_LEFT|AV_CH_BINAURAL_RIGHT)
 #define AV_CH_LAYOUT_STEREO_DOWNMIX(AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
@@ -423,6 +424,7 @@ typedef struct AVChannelLayout {
 #define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(12, 
AV_CH_LAYOUT_7POINT1POINT4_BACK)
 #define AV_CHANNEL_LAYOUT_7POINT2POINT3 AV_CHANNEL_LAYOUT_MASK(12, 
AV_CH_LAYOUT_7POINT2POINT3)
 #define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(14, 
AV_CH_LAYOUT_9POINT1POINT4_BACK)
+#define AV_CHANNEL_LAYOUT_9POINT1POINT6 AV_CHANNEL_LAYOUT_MASK(16, 
AV_CH_LAYOUT_9POINT1POINT6)
 #define AV_CHANNEL_LAYOUT_HEXADECAGONAL AV_CHANNEL_LAYOUT_MASK(16, 
AV_CH_LAYOUT_HEXADECAGONAL)
 #define AV_CHANNEL_LAYOUT_BINAURAL  AV_CHANNEL_LAYOUT_MASK(2,  
AV_CH_LAYOUT_BINAURAL)
 #define AV_CHANNEL_LAYOUT_STEREO_DOWNMIXAV_CHANNEL_LAYOUT_MASK(2,  
AV_CH_LAYOUT_STEREO_DOWNMIX)
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index 0e3d6914bc..206f8d51c7 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -33,6 +33,7 @@ cube   FL+FR+BL+BR+TFL+TFR+TBL+TBR
 7.1.4  FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBL+TBR
 7.2.3  FL+FR+FC+LFE+BL+BR+SL+SR+TFL+TFR+TBC+LFE2
 9.1.4  FL+FR+FC+LFE+BL+BR+FLC+FRC+SL+SR+TFL+TFR+TBL+TBR
+9.1.6  FL+FR+FC+LFE+BL+BR+FLC+FRC+SL+SR+TFL+TFR+TBL+TBR+TSL+TSR
 hexadecagonal  FL+FR+FC+BL+BR+BC+SL+SR+TFL+TFC+TFR+TBL+TBC+TBR+WL+WR
 binaural   BIL+BIR
 downmixDL+DR
-- 
2.47.1

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

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


Re: [FFmpeg-devel] [PATCH v2] libavformat/mpegts: demux DVB VBI data

2024-12-10 Thread Scott Theisen

On 12/8/24 17:04, Marton Balint wrote:

On Sun, 8 Dec 2024, Scott Theisen wrote:

On 12/3/24 17:23, Marton Balint wrote:

  On Tue, 3 Dec 2024, Marton Balint wrote:

  On Sat, 30 Nov 2024, Scott Theisen wrote:
  DVB VBI data is defined in ETSI EN 301 775 and can include EBU 
teletext

  data
  as defined in ETSI EN 300 472.

  ETSI EN 300 468 defines teletext_descriptor, 
VBI_data_descriptor, and

  VBI_teletext_descriptor, which has the same definition as, but
 different
  use
  from, teletext_descriptor.
  ---
  libavcodec/codec_desc.c | 6 ++
  libavcodec/codec_id.h   | 1 +
  libavformat/mpegts.c    | 3 +++
  libavformat/mpegts.h    | 2 ++
  4 files changed, 12 insertions(+)


 You should split this to two patches.


OK, I'll do that.



 Patch 1 should add the codec ID the codec_description and please also
 update the assertion check in libavcodec/version.c.

 Patch 2 should add the support for demuxing in mpegts. I'd rather 
put the

 VBI descriptors after the teletext descriptor in the list, so in case
 multiple descriptors are present the detected codec should be 
teletext.


 On second thought the order does not help, because the codec will be
 determined by the first descriptor...

 Maybe when parsing the teletext descriptor it should override VBI 
codec to

 teletext, e.g.:

 case TELETEXT_DESCRIPTOR:
  if (codec_id == DVB_VBI)
 codec_id = DVB_TELETEXT
  // fall-through
 case VBI_TELETEXT_DESCRIPTOR:
  


I'm not sure it makes sense to change it from DVB_VBI to 
DVB_TELETEXT, since the VBI format is backwards compatible with the 
teletext format.  Although, the TELETEXT_DESCRIPTOR is for EBU 
teletext data only streams, but then there shouldn't be either VBI 
descriptor to set the codec_id to DVB_VBI.


I'm not strongly opposed, I'm just not sure it is really necessary.


The reason I prefer it that way so streams which were detected earlier 
as teletext won't be suddenly detected as VBI because both descriptors 
are present and VBI is the first. I think using both descriptors is 
not unlikely, since the essence is compatible, here is an example I 
stumbled upon by accident:


https://www.dvbcontrol.com/wp-content/uploads/DVBAnalyzer/DVBAnalyzer_View_0.jpg 



ETSI EN 300 468 is not very clear on how the descriptors are supposed to 
be used, but I think it goes like this:


"The VBI_data_descriptor (see table 106) shall be used in the PSI PMT of 
a stream which carries VBI data as defined in ETSI EN 301 775."


However, a stream as defined by ETSI EN 300 472 (teletext) is also a 
stream as defined by ETSI EN 301 775 (VBI data), so a stream that is 
just EBU teletext shall have a teletext_descriptor and a 
VBI_data_descriptor.


I think a VBI_teletext_descriptor would be used instead of a 
teletext_descriptor when there are other types of VBI data in addition 
to the EBU teletext data, but it is not clear if they are supposed to be 
mutually exclusive.






If you do want it, I'm not sure the if is necessary, just set 
codec_id unconditionally.  However, it might be better to just call 
mpegts_find_stream_type() instead so FFStream::need_context_update is 
set.


Yes, good point calling mpegts_find_stream_type() instead.



Regardless, I'm wondering if instead VBI_TELETEXT_DESCRIPTOR should 
not be added to DESC_types since ETSI EN 300 468 says this about 
VBI_teletext_descriptor:

"
The only exception is that the VBI_teletext_descriptor is not to be 
used to associate stream_type 0x06 with the VBI standard nor the EBU 
teletext standard. Decoders can only use the languages in this 
descriptor to select magazines and subtitles.

"



Yeah, we could remove it from DESC_types if we want to strictly follow 
the standard. However, as far as understand, a VBI_teletext_descriptor 
should never appear alone, only accompanied by a VBI_data_descriptor. 
So the question is if there are non-compliant streams with 
VBI_teletext_descriptor only which we want to support? I don't really 
have a preference here, so do whichever you think best.


I don't see any harm in keeping it in DESC_types to support possible 
non-compliant streams.


All of this discussion has made me think that DVB_VBI shouldn't be a 
separate codec, but added to DVB_TELETEXT, changing the 
AVCodecDescriptor::long_name to "DVB teletext and VBI data", since the 
data format is the same.  The only downside I see is that a VBI data 
stream without any EBU teletext data would appear to be a subtitle 
stream even though it contains no subtitles.  However, that issue is 
also present with the v2 patch which says DVB_VBI is subtitles.


It would be nice, although not necessary, if the information in the 
VBI_data_descriptor was exposed somehow, but the teletext descriptors 
already use AVCodecParameters::extradata and I'm not sure if 
AVStream::metadata is supposed to be only text data, so I don't know 
where the entire VBI_data_descriptor could be copied to.


Regards,

Scott Theisen
__

Re: [FFmpeg-devel] [PATCH 5/7] avformat/mpegts: add s337m support

2024-12-10 Thread Scott Theisen

On 12/8/24 22:55, Michael Niedermayer wrote:

On Wed, Dec 04, 2024 at 03:14:07PM +0100, ffnicol...@sfr.fr wrote:

From: Nicolas Gaullier 

Move s302m decoder from avcodec to avformat.
Set AVSTREAM_PARSE_FULL for s337m support.

Signed-off-by: Nicolas Gaullier 
---
  libavformat/mpegts.c  | 138 +-
  tests/fate/acodec.mak |   3 +-
  2 files changed, 139 insertions(+), 2 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 177e610e53..fd649751fc 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -31,6 +31,7 @@
  #include "libavutil/opt.h"
  #include "libavutil/avassert.h"
  #include "libavutil/dovi_meta.h"
+#include "libavutil/reverse.h"
  #include "libavcodec/bytestream.h"
  #include "libavcodec/defs.h"
  #include "libavcodec/get_bits.h"

[...]

+static int s302m_demux(AVCodecParameters *par, AVPacket *pkt)
+{
+int ret = av_packet_make_writable(pkt);
+if (ret < 0)
+return ret;
+pkt->data += AES3_HEADER_LEN;
+av_shrink_packet(pkt, pkt->size - AES3_HEADER_LEN);
+
+if (par->bits_per_raw_sample == 24) {
+uint8_t *buf = pkt->data;
+uint8_t *buf_out = buf;
+for (; buf + 6 < pkt->data + pkt->size; buf+=7, buf_out+=6)
+AV_WL48(buf_out,
+((uint64_t)ff_reverse[buf[2]] << 16) |
+((uint64_t)ff_reverse[buf[1]] <<  8) |
+((uint64_t)ff_reverse[buf[0]])   |
+((uint64_t)ff_reverse[buf[6] & 0xf0] << 44) |
+((uint64_t)ff_reverse[buf[5]]<< 36) |
+((uint64_t)ff_reverse[buf[4]]<< 28) |
+((uint64_t)ff_reverse[buf[3] & 0x0f] << 20));
+av_shrink_packet(pkt, buf_out - pkt->data);

/usr/bin/ld: libavformat/libavformat.so: undefined reference to `ff_reverse'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:142: ffprobe_g] Error 1
make: *** Waiting for unfinished jobs
/usr/bin/ld: libavformat/libavformat.so: undefined reference to `ff_reverse'
/usr/bin/ld: libavformat/libavformat.so: undefined reference to `ff_reverse'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:142: ffplay_g] Error 1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:142: ffmpeg_g] Error 1

thx



ff_* symbols are not exported and are internal to each library. Some of 
the other libraries `#include "libavutil/reverse.c"` in a file.  Should 
ff_reverse be renamed avpriv_reverse so that is not necessary?


Regards,

Scott Theisen

___
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 05/16] swscale/utils: read dynamic HDR10+ metadata from AVFrame

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:04PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> Logic ported from libplacebo's AVFrame helpers. The basic idea is to use the
> provided MaxRGB/MaxSCL values to infer what the actual luminance would have
> been, which HDR10+ metadata does not provide directly. It's worth pointing out
> that this gives us an *upper* bound on the true maximum luminance, so any
> error in the estimation cannot result in clipping.
> ---
>  libswscale/utils.c | 50 ++
>  1 file changed, 50 insertions(+)

probably ok

thx

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

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 06/16] swscale/utils: add helper function to infer colorspace metadata

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:05PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> Logic is loosely on equivalent decisions in libplacebo. The basic idea is to 
> try
> and be a bit conservative by treating AVCOL_*_UNSPECIFIED as a no-op, unless 
> the
> other primaries set are non-standard / wide-gamut or HDR. This helps avoid
> unintended or unexpected colorspace conversions, while forcing it in cases 
> where
> we are almost certain it is needed. The major departure from libplacebo 
> semantics
> is that we no default to a 1000:1 contrast ration for SDR displays, instead 
> modelling
> them as idealized devices with an infinite contrast ratio.
> 
> In either case, setting SWS_STRICT overrides this behavior in favor of always
> requiring explicit colorspace metadata.
> ---
>  libswscale/utils.c | 66 ++
>  libswscale/utils.h |  3 +++
>  2 files changed, 69 insertions(+)

should be ok

thx

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

In fact, the RIAA has been known to suggest that students drop out
of college or go to community college in order to be able to afford
settlements. -- The RIAA


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 07/16] swscale/utils: fix XYZ primaries tagging

2024-12-10 Thread Michael Niedermayer
On Fri, Dec 06, 2024 at 03:32:06PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> Swscale currently handles XYZ by embedding a forced conversion to
> BT.709 RGB with a hardcoded matrix. This is not ideal, but to preserve the
> status quo and avoid any unexpected changes in behavior, this patch merely
> fixes the inferred primaries tag to match the reality.
> 
> In the future, I would like to handle XYZ properly, via direct conversion
> to the target colorspace (or possibly simply by using a more fitting
> RGB intermediate like SMPTE428), but for now just keep the status quo.
> ---
>  libswscale/utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

ok

thx

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

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 08/16] swscale: add ICC intent enum and option

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:07PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> This setting can be used to infuence the type of tone and gamut mapping used
> internally when color space conversions are required. As discussed at VDD'24,
> the default was set to relative colorimetric clipping, which is approximately
> associative, surjective and idempotent. As such, it roundtrips well, although
> it is strictly speaking not associative on out-of-gamut colors.
> ---
>  doc/APIchanges|  3 +++
>  doc/filters.texi  | 31 +++
>  libswscale/graph.c| 11 ++-
>  libswscale/options.c  |  6 ++
>  libswscale/swscale.h  | 13 +
>  libswscale/swscale_internal.h |  2 +-
>  libswscale/version.h  |  2 +-
>  libswscale/x86/output.asm |  2 +-
>  8 files changed, 62 insertions(+), 8 deletions(-)

LGTM

thx

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

The smallest minority on earth is the individual. Those who deny 
individual rights cannot claim to be defenders of minorities. - Ayn Rand


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 03/16] swscale/utils: set static/implied HDR metadata

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:02PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> Provide default values for the fields added in the previous commit.
> ---
>  libswscale/utils.c | 21 +
>  1 file changed, 21 insertions(+)
> 
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index 428cf1c7f5..182f92396a 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -2654,6 +2654,8 @@ int ff_range_add(RangeList *rl, unsigned int start, 
> unsigned int len)
>  SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field)
>  {
>  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
> +const AVColorPrimariesDesc *primaries;
> +
>  SwsFormat fmt = {
>  .width  = frame->width,
>  .height = frame->height,
> @@ -2710,6 +2712,25 @@ SwsFormat ff_fmt_from_frame(const AVFrame *frame, int 
> field)
>  fmt.interlaced = 1;
>  }
>  
> +/* Set luminance and gamut information */
> +fmt.color.min_luma = av_make_q(0, 1);
> +switch (fmt.color.trc) {
> +case AVCOL_TRC_SMPTE2084:
> +fmt.color.max_luma = av_make_q(1, 1); break;
> +case AVCOL_TRC_ARIB_STD_B67:
> +fmt.color.max_luma = av_make_q( 1000, 1); break; /* HLG reference 
> display */
> +default:
> +fmt.color.max_luma = av_make_q(  203, 1); break; /* SDR reference 
> brightness */
> +}
> +
> +primaries = av_csp_primaries_desc_from_id(fmt.color.prim);
> +if (primaries)
> +fmt.color.gamut = primaries->prim;
> +
> +/* PQ is always scaled down to absolute zero, so ignore mastering 
> metadata */
> +if (fmt.color.trc == AVCOL_TRC_SMPTE2084)
> +fmt.color.min_luma = av_make_q(0, 1);

This makes sense after subsequent patches, but here it sets
min_luma to 0 after it is set to 0, maybe this hunk should be in another patch
or something else

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 16/16] swscale: remove primaries/trc change warning

2024-12-10 Thread Michael Niedermayer
On Fri, Dec 06, 2024 at 03:32:15PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> This is now supported when using the new API.
> ---
>  libswscale/swscale.c | 11 ---
>  1 file changed, 11 deletions(-)

LGTM

thx

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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 01/16] swscale/utils: check for supported color transfers

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:00PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> We will use the av_csp_itu_eotf() functions to decode these internally, so
> check this function to see if it succeeds.
> ---
>  libswscale/utils.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)

should be ok, assuming reserved values are handled somewhere somehow,
and dont lead to hard failures

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] libavcodec/mpegaudio_parser.c: differentiate MPEG audio dual mono

2024-12-10 Thread Scott Theisen

On 12/10/24 19:16, James Almer wrote:

On 12/10/2024 9:06 PM, Scott Theisen wrote:

On 12/9/24 02:30, Anton Khirnov wrote:

Quoting James Almer (2024-11-30 14:41:20)

On 11/14/2024 1:37 AM, Scott Theisen wrote:
When attempting to upstream this MythTV change in September 2022, 
it was recommended to
use AV_CHANNEL_ORDER_CUSTOM with two AV_CHAN_FRONT_CENTER 
channels. See
https://patchwork.ffmpeg.org/project/ffmpeg/ 
patch/20220921192611.3241-1-scott.the@gmail.com/

---
   libavcodec/audiotoolboxdec.c    |  4 ++--
   libavcodec/mpegaudio_parser.c   | 12 +---
   libavcodec/mpegaudiodecheader.c |  4 +++-
   libavcodec/mpegaudiodecheader.h |  2 +-
   tests/ref/fate/pva-demux    |  2 +-
   5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/ 
audiotoolboxdec.c

index 0f7ce8e4eb..d279d7bbc4 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -346,10 +346,10 @@ static av_cold int 
ffat_create_decoder(AVCodecContext *avctx,

   avctx->codec_id == AV_CODEC_ID_MP2 ||
   avctx->codec_id == AV_CODEC_ID_MP3)) {
   enum AVCodecID codec_id;
-    int bit_rate;
+    int bit_rate, dual_mono;
   if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx- 
>sample_rate,

&in_format.mChannelsPerFrame, &avctx->frame_size,
- &bit_rate, &codec_id) < 0)
+ &bit_rate, &codec_id, 
&dual_mono) < 0)

   return AVERROR_INVALIDDATA;
   avctx->bit_rate = bit_rate;
   in_format.mSampleRate = avctx->sample_rate;
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/ 
mpegaudio_parser.c

index d54366f10a..d1a4ee6434 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -65,12 +65,12 @@ static int 
mpegaudio_parse(AVCodecParserContext *s1,

   }
   }else{
   while(i+    int ret, sr, channels, bit_rate, frame_size, 
dual_mono;

   enum AVCodecID codec_id = avctx->codec_id;
   state= (state<<8) + buf[i++];
-    ret = ff_mpa_decode_header(state, &sr, &channels, 
&frame_size, &bit_rate, &codec_id);
+    ret = ff_mpa_decode_header(state, &sr, &channels, 
&frame_size, &bit_rate, &codec_id, &dual_mono);

   if (ret < 4) {
   if (i > 4)
   s->header_count = -2;
@@ -85,7 +85,13 @@ static int mpegaudio_parse(AVCodecParserContext 
*s1,

   if (s->header_count > header_threshold) {
   avctx->sample_rate= sr;
av_channel_layout_uninit(&avctx->ch_layout);
- av_channel_layout_default(&avctx- >ch_layout, channels);
+    if (dual_mono) {
+ av_channel_layout_custom_init(&avctx- >ch_layout, 2);
+ avctx->ch_layout.u.map[0].id = AV_CHAN_FRONT_CENTER;
+ avctx->ch_layout.u.map[1].id = AV_CHAN_FRONT_CENTER;

Kind of sucks we have used FC to represent mono for so long that we
can't cleanly introduce a new channel that's strictly mono (with no
speaker location implied) and give it meaningful use.

AV_CHAN_UNKNOWN?



Using AV_CHAN_UNKNOWN would be fine with me.

However, would using AV_CHANNEL_ORDER_UNSPEC instead of 
AV_CHANNEL_ORDER_CUSTOM be better?


UNSPEC means the channels have no definition. We could allow the user 
to assume 1 channel is "mono", but definitely not 2 channels for dual 
mono.


The documentation for AV_CHANNEL_ORDER_UNSPEC says "Only the channel 
count is specified, without any further information about the channel 
order. ", not that the channels have no definition.  (I'm not sure what 
you mean by definition, though.)


Based on av_channel_layout_retype(), AV_CHANNEL_ORDER_CUSTOM with two 
AV_CHAN_UNKNOWN channels is equivalent to AV_CHANNEL_ORDER_UNSPEC with 
two channels.


Regards,

Scott Theisen

___
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] libavcodec/mpegaudio_parser.c: differentiate MPEG audio dual mono

2024-12-10 Thread James Almer

On 12/10/2024 9:06 PM, Scott Theisen wrote:

On 12/9/24 02:30, Anton Khirnov wrote:

Quoting James Almer (2024-11-30 14:41:20)

On 11/14/2024 1:37 AM, Scott Theisen wrote:
When attempting to upstream this MythTV change in September 2022, it 
was recommended to

use AV_CHANNEL_ORDER_CUSTOM with two AV_CHAN_FRONT_CENTER channels. See
https://patchwork.ffmpeg.org/project/ffmpeg/ 
patch/20220921192611.3241-1-scott.the@gmail.com/

---
   libavcodec/audiotoolboxdec.c    |  4 ++--
   libavcodec/mpegaudio_parser.c   | 12 +---
   libavcodec/mpegaudiodecheader.c |  4 +++-
   libavcodec/mpegaudiodecheader.h |  2 +-
   tests/ref/fate/pva-demux    |  2 +-
   5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/ 
audiotoolboxdec.c

index 0f7ce8e4eb..d279d7bbc4 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -346,10 +346,10 @@ static av_cold int 
ffat_create_decoder(AVCodecContext *avctx,

   avctx->codec_id == AV_CODEC_ID_MP2 ||
   avctx->codec_id == AV_CODEC_ID_MP3)) {
   enum AVCodecID codec_id;
-    int bit_rate;
+    int bit_rate, dual_mono;
   if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx- 
>sample_rate,
    &in_format.mChannelsPerFrame, 
&avctx->frame_size,

- &bit_rate, &codec_id) < 0)
+ &bit_rate, &codec_id, &dual_mono) 
< 0)

   return AVERROR_INVALIDDATA;
   avctx->bit_rate = bit_rate;
   in_format.mSampleRate = avctx->sample_rate;
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/ 
mpegaudio_parser.c

index d54366f10a..d1a4ee6434 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -65,12 +65,12 @@ static int mpegaudio_parse(AVCodecParserContext 
*s1,

   }
   }else{
   while(i+    int ret, sr, channels, bit_rate, frame_size, 
dual_mono;

   enum AVCodecID codec_id = avctx->codec_id;
   state= (state<<8) + buf[i++];
-    ret = ff_mpa_decode_header(state, &sr, &channels, 
&frame_size, &bit_rate, &codec_id);
+    ret = ff_mpa_decode_header(state, &sr, &channels, 
&frame_size, &bit_rate, &codec_id, &dual_mono);

   if (ret < 4) {
   if (i > 4)
   s->header_count = -2;
@@ -85,7 +85,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
   if (s->header_count > header_threshold) {
   avctx->sample_rate= sr;
   av_channel_layout_uninit(&avctx->ch_layout);
-    av_channel_layout_default(&avctx- 
>ch_layout, channels);

+    if (dual_mono) {
+    av_channel_layout_custom_init(&avctx- 
>ch_layout, 2);
+    avctx->ch_layout.u.map[0].id = 
AV_CHAN_FRONT_CENTER;
+    avctx->ch_layout.u.map[1].id = 
AV_CHAN_FRONT_CENTER;

Kind of sucks we have used FC to represent mono for so long that we
can't cleanly introduce a new channel that's strictly mono (with no
speaker location implied) and give it meaningful use.

AV_CHAN_UNKNOWN?



Using AV_CHAN_UNKNOWN would be fine with me.

However, would using AV_CHANNEL_ORDER_UNSPEC instead of 
AV_CHANNEL_ORDER_CUSTOM be better?


UNSPEC means the channels have no definition. We could allow the user to 
assume 1 channel is "mono", but definitely not 2 channels for dual mono.




OpenPGP_signature.asc
Description: OpenPGP digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 02/16] swscale/utils: add HDR metadata to SwsFormat

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:01PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> Only add the condensed values that we actually care about. Group them into
> a new struct to make it easier to discard or replace this metadata.
> 
> Define a special comparison function that does not choke on undefined/unknown
> metadata.

[...]

> diff --git a/libswscale/utils.h b/libswscale/utils.h
> index 4d204ef6cc..1263e3f8ed 100644
> --- a/libswscale/utils.h
> +++ b/libswscale/utils.h
> @@ -21,26 +21,55 @@
>  #ifndef SWSCALE_UTILS_H
>  #define SWSCALE_UTILS_H
>  
> +#include "libavutil/csp.h"
>  #include "libavutil/pixdesc.h"
>  
>  #include "swscale.h"
>  
> +/* Like av_cmp_q but considers 0/0 == 0/0 */
> +static inline int ff_q_equal(const AVRational a, const AVRational b)
> +{
> +return (a.den || b.den) ? !av_cmp_q(a, b) : a.den == b.den;
> +}

in which case is a.den == b.den untrue ?


[...]

thx


--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 04/16] swscale/utils: read HDR mastering metadata from AVFrame

2024-12-10 Thread Michael Niedermayer
On Fri, Dec 06, 2024 at 03:32:03PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> ---
>  libswscale/utils.c | 18 ++
>  1 file changed, 18 insertions(+)

should be ok

thx

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

If you think the mosad wants you dead since a long time then you are either
wrong or dead since a long time.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCHv2 1/2] avformat/iff: SndAnim decoding

2024-12-10 Thread Peter Ross
Fixes ticket #5553.
---
Additional hardening thanks to target_dem_fuzzer.c

 libavformat/iff.c | 311 +++---
 1 file changed, 210 insertions(+), 101 deletions(-)

diff --git a/libavformat/iff.c b/libavformat/iff.c
index 7601baa629..ab0488dd31 100644
--- a/libavformat/iff.c
+++ b/libavformat/iff.c
@@ -111,6 +111,8 @@ typedef struct IffDemuxContext {
 int  is_64bit;  ///< chunk size is 64-bit
 int64_t  body_pos;
 int64_t  body_end;
+int64_t  sbdy_pos;
+int64_t  resume_pos;
 uint32_t  body_size;
 svx8_compression_type   svx8_compression;
 unsigned  maud_bits;
@@ -122,7 +124,9 @@ typedef struct IffDemuxContext {
 unsigned  transparency; ///< transparency color index in palette
 unsigned  masking;  ///< masking method used
 uint8_t   tvdc[32]; ///< TVDC lookup table
-int64_t   pts;
+uint32_t  form_tag;
+int   audio_stream_index;
+int   video_stream_index;
 } IffDemuxContext;
 
 /* Metadata string read */
@@ -385,7 +389,7 @@ static int read_dst_frame(AVFormatContext *s, AVPacket *pkt)
 if (data_size & 1)
 avio_skip(pb, 1);
 pkt->flags |= AV_PKT_FLAG_KEY;
-pkt->stream_index = 0;
+pkt->stream_index = iff->audio_stream_index;
 pkt->duration = s->streams[0]->codecpar->sample_rate / 75;
 pkt->pos = chunk_pos;
 
@@ -416,11 +420,23 @@ static const uint8_t deep_bgra[]  = {0, 0, 0, 4, 0, 3, 0, 
8, 0, 2, 0, 8, 0, 1, 0
 static const uint8_t deep_argb[]  = {0, 0, 0, 4, 0,17, 0, 8, 0, 1, 0, 8, 0, 2, 
0, 8};
 static const uint8_t deep_abgr[]  = {0, 0, 0, 4, 0,17, 0, 8, 0, 3, 0, 8, 0, 2, 
0, 8};
 
+static AVStream * new_stream(AVFormatContext *s, AVStream **st_ptr, int 
*index_ptr, enum AVMediaType codec_type)
+{
+if (!*st_ptr) {
+*st_ptr = avformat_new_stream(s, NULL);
+if (!*st_ptr)
+return NULL;
+(*st_ptr)->codecpar->codec_type = codec_type;
+(*index_ptr) = (*st_ptr)->index;
+ }
+ return *st_ptr;
+}
+
 static int iff_read_header(AVFormatContext *s)
 {
 IffDemuxContext *iff = s->priv_data;
 AVIOContext *pb = s->pb;
-AVStream *st;
+AVStream *sta = NULL, *stv = NULL;
 uint8_t *buf;
 uint32_t chunk_id;
 uint64_t data_size;
@@ -430,16 +446,12 @@ static int iff_read_header(AVFormatContext *s)
 uint8_t fmt[16];
 int fmt_size;
 
-st = avformat_new_stream(s, NULL);
-if (!st)
-return AVERROR(ENOMEM);
-
-st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+iff->audio_stream_index = -1;
+iff->video_stream_index = -1;
 iff->is_64bit = avio_rl32(pb) == ID_FRM8;
 avio_skip(pb, iff->is_64bit ? 8 : 4);
-// codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and 
interlaced (ILBM) content
-st->codecpar->codec_tag = avio_rl32(pb);
-if (st->codecpar->codec_tag == ID_ANIM) {
+iff->form_tag = avio_rl32(pb);
+if (iff->form_tag == ID_ANIM) {
 avio_skip(pb, 12);
 }
 iff->bitmap_compression = -1;
@@ -461,23 +473,24 @@ static int iff_read_header(AVFormatContext *s)
 
 switch(chunk_id) {
 case ID_VHDR:
-st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-
 if (data_size < 14)
 return AVERROR_INVALIDDATA;
+if (!new_stream(s, &sta, &iff->audio_stream_index, 
AVMEDIA_TYPE_AUDIO))
+return AVERROR(ENOMEM);
 avio_skip(pb, 12);
-st->codecpar->sample_rate = avio_rb16(pb);
+sta->codecpar->sample_rate = avio_rb16(pb);
 if (data_size >= 16) {
 avio_skip(pb, 1);
 iff->svx8_compression = avio_r8(pb);
 }
+sta->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 break;
 
 case ID_MHDR:
-st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-
 if (data_size < 32)
 return AVERROR_INVALIDDATA;
+if (!new_stream(s, &sta, &iff->audio_stream_index, 
AVMEDIA_TYPE_AUDIO))
+return AVERROR(ENOMEM);
 avio_skip(pb, 4);
 iff->maud_bits = avio_rb16(pb);
 avio_skip(pb, 2);
@@ -486,14 +499,14 @@ static int iff_read_header(AVFormatContext *s)
 if (!den)
 return AVERROR_INVALIDDATA;
 avio_skip(pb, 2);
-st->codecpar->sample_rate = num / den;
-st->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
-st->codecpar->ch_layout.nb_channels = avio_rb16(pb);
+sta->codecpar->sample_rate = num / den;
+sta->codecpar->ch_layout.order   = AV_CHANNEL_ORDER_UNSPEC;
+sta->codecpar->ch_layout.nb_channels = avio_rb16(pb);
 iff->maud_compression = avio_rb16(pb);
-if (st->codecpar->ch_layout.nb_channels == 1)
-st->codecpar->ch_layout = 
(AVChan

[FFmpeg-devel] [PATCHv2 2/2] tests/fate/demux: IFF test case

2024-12-10 Thread Peter Ross
---
Test file:

https://pross.sdf.org/sandpit/Hammer2.sndanim

 tests/fate/demux.mak |  3 +++
 tests/ref/fate/iff-demux | 32 
 2 files changed, 35 insertions(+)
 create mode 100644 tests/ref/fate/iff-demux

diff --git a/tests/fate/demux.mak b/tests/fate/demux.mak
index e0d1fccc8f..3e6813f9da 100644
--- a/tests/fate/demux.mak
+++ b/tests/fate/demux.mak
@@ -54,6 +54,9 @@ fate-flv-demux: CMD = ffprobe_demux 
$(TARGET_SAMPLES)/flv/Enigma_Principles_of_L
 FATE_SAMPLES_DEMUX-$(CONFIG_GIF_DEMUXER) += fate-gif-demux
 fate-gif-demux: CMD = framecrc -i 
$(TARGET_SAMPLES)/gif/Newtons_cradle_animation_book_2.gif -c:v copy
 
+FATE_SAMPLES_DEMUX-$(CONFIG_IFF_DEMUXER) += fate-iff-demux
+fate-iff-demux: CMD = framecrc -i $(TARGET_SAMPLES)/iff/Hammer2.sndanim -c:v 
copy -c:a copy
+
 FATE_SAMPLES_DEMUX-$(call ALLYES, IV8_DEMUXER MPEG4VIDEO_PARSER) += 
fate-iv8-demux
 fate-iv8-demux: CMD = framecrc -i $(TARGET_SAMPLES)/iv8/zzz-partial.mpg -c:v 
copy
 
diff --git a/tests/ref/fate/iff-demux b/tests/ref/fate/iff-demux
new file mode 100644
index 00..43e711856c
--- /dev/null
+++ b/tests/ref/fate/iff-demux
@@ -0,0 +1,32 @@
+#extradata 0:   65, 0xad7f0b54
+#tb 0: 1/60
+#media_type 0: video
+#codec_id 0: iff_ilbm
+#dimensions 0: 320x200
+#sar 0: 0/1
+#tb 1: 1/14977
+#media_type 1: audio
+#codec_id 1: pcm_s8_planar
+#sample_rate 1: 14977
+#channel_layout_name 1: stereo
+0,  0,  0,   12,11124, 0x2446cd13
+1,  0,  0, 1497, 2994, 0x
+1,   1497,   1497, 1497, 2994, 0x
+1,   2994,   2994, 1497, 2994, 0x43c16baa
+0, 12, 12,6, 4608, 0x3e196585, F=0x0
+1,   4491,   4491, 1497, 2994, 0x47eefb28
+0, 18, 18,6, 4496, 0xe02350d6, F=0x0
+1,   5988,   5988, 1497, 2994, 0x0f11a833
+0, 24, 24,6, 4472, 0xd40dc2e6, F=0x0
+1,   7485,   7485, 1497, 2994, 0x44067560
+0, 30, 30,6, 4574, 0x69678743, F=0x0
+1,   8982,   8982, 1497, 2994, 0xd690cbf5
+0, 36, 36,6, 4548, 0xd8970f13, F=0x0
+1,  10479,  10479, 1497, 2994, 0x
+0, 42, 42,6, 4670, 0xfc35e0f3, F=0x0
+1,  11976,  11976, 2995, 5990, 0x
+0, 48, 48,6, 4388, 0xdee7fa79, F=0x0
+0, 54, 54,6, , 0x65ee3fa1, F=0x0
+1,  14971,  14971, 1497, 2994, 0x
+0, 60, 60,   12, 7344, 0xb76b3452, F=0x0
+0, 72, 72,6, 1586, 0xbee30464, F=0x0
-- 
2.45.2

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] avcodec: uninit hwaccel in case of software decoder

2024-12-10 Thread Anton Khirnov
Hi,
Quoting Thomas Guillem via ffmpeg-devel (2024-11-29 11:44:21)
> avcodec_get_hw_frames_parameters(), called by the user from get_format,
> is allocating ctx->internal->hwaccel_priv_data. But the hardware
> decoding setup may fail on the user side and it may fallback to software
> decoding. In that case, ctx->internal->hwaccel_priv_data is still
> allocated but not used anymore.
> 
> Fixes the following assert:
> 
> Assertion p_dst->hwaccel_threadsafe || (!dst->hwaccel && 
> !dst->internal->hwaccel_priv_data) failed at 
> src/libavcodec/pthread_frame.c:426
> ---
>  libavcodec/decode.c | 2 ++
>  1 file changed, 2 insertions(+)

I think the actual problem is that avcodec_get_hw_frames_parameters()
modifies the codec context, even though it's explicitly documented not
to. I discussed this with Lynne on IRC, and she's working on removing
the need for that from vulkan decoding, which should be a more proper
fix here.

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

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


Re: [FFmpeg-devel] [PATCH v3 1/2] checkasm/rv40dsp: cover more cases

2024-12-10 Thread Ronald S. Bultje
Hi,

On Thu, Dec 5, 2024 at 8:49 AM Ronald S. Bultje  wrote:

> Hi,
>
> On Thu, Dec 5, 2024 at 8:41 AM  wrote:
>
>> From: sunyuechi 
>>
>> Co-Authored-By: Ronald S. Bultje 
>> ---
>>  tests/checkasm/rv40dsp.c | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/checkasm/rv40dsp.c b/tests/checkasm/rv40dsp.c
>> index a1a873d430..c0d02ec81f 100644
>> --- a/tests/checkasm/rv40dsp.c
>> +++ b/tests/checkasm/rv40dsp.c
>> @@ -27,7 +27,7 @@
>>  #define randomize_buffers()  \
>>  do { \
>>  for (int i = 0; i < 16*18*2; i++)\
>> -src[i] = rnd() & 0x3;\
>> +src[i] = rnd() & 0xff;   \
>>  } while (0)
>>
>>  static void check_chroma_mc(void)
>> @@ -47,12 +47,12 @@ static void check_chroma_mc(void)
>>  #define CHECK_CHROMA_MC(name)
>>  \
>>  do {
>>   \
>>  if (check_func(h.name## 
>> _pixels_tab[size], #name "_mc%d", 1 << (3 - size))) { \
>> -for (int x = 0; x < 2; x++) {
>>  \
>> -for (int y = 0; y < 2; y++) {
>>  \
>> +for (int x = 0, mx = 0; x < 2; x++, mx = 1 + (rnd() %
>> 7)) {   \
>> +for (int y = 0, my = 0; y < 2; y++, my = 1 + (rnd()
>> % 7)) {   \
>>  memcpy(dst0, src, 16 * 18);
>>  \
>>  memcpy(dst1, src, 16 * 18);
>>  \
>> -call_ref(dst0, src, 16, 16, x, y);
>>   \
>> -call_new(dst1, src, 16, 16, x, y);
>>   \
>> +call_ref(dst0, src, 16, 16, mx, my);
>>   \
>> +call_new(dst1, src, 16, 16, mx, my);
>>   \
>>  if (memcmp(dst0, dst1, 16 * 16)) {
>>   \
>>  fprintf(stderr, #name ": x:%i, y:%i\n", x,
>> y);\
>>  fail();
>>  \
>> --
>> 2.47.1
>>
>
> LGTM.
>

Merged.

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

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


Re: [FFmpeg-devel] [PATCH v3 2/2] lavc/rv40dsp: fix RISC-V chroma_mc

2024-12-10 Thread Ronald S. Bultje
Hi,

On Fri, Dec 6, 2024 at 2:24 PM Rémi Denis-Courmont  wrote:

>
>
> Le 6 décembre 2024 13:19:29 GMT+01:00, Niklas Haas  a
> écrit :
> >On Thu, 05 Dec 2024 21:41:51 +0800 uk7b-at-foxmail@ffmpeg.org wrote:
> >> From: sunyuechi 
> >>
> >> ---
> >>  libavcodec/riscv/rv40dsp_rvv.S | 116 ++---
> >>  1 file changed, 78 insertions(+), 38 deletions(-)
> >>
> >> diff --git a/libavcodec/riscv/rv40dsp_rvv.S
> b/libavcodec/riscv/rv40dsp_rvv.S
> >> index ca431eb8ab..d4beb7f1e9 100644
> >> --- a/libavcodec/riscv/rv40dsp_rvv.S
> >> +++ b/libavcodec/riscv/rv40dsp_rvv.S
> >> @@ -20,15 +20,30 @@
> >>
> >>  #include "libavutil/riscv/asm.S"
> >>
> >> -.macro manual_avg dst src1 src2
> >> -vadd.vv \dst, \src1, \src2
> >> -vadd.vi \dst, \dst, 1
> >> -vsrl.vi \dst, \dst, 1
> >> -.endm
> >> +const rv40_bias
> >> +.byte  0, 16, 32, 16
> >> +.byte 32, 28, 32, 28
> >> +.byte  0, 32, 16, 32
> >> +.byte 32, 28, 32, 28
> >> +endconst
> >>
> >>  .macro  do_chroma_mc type unroll
> >> -csrwi   vxrm, 2
> >> +csrwi   vxrm, 0
> >> +addisp, sp, -16
> >> +#if __riscv_xlen == 32
> >> +sw  s2, (sp)
> >> +#elif __riscv_xlen == 64
> >> +sd  s2, (sp)
> >> +#else
> >> +sq  s2, (sp)
> >> +#endif
> >
> >You can use the macro `sx` from libavcodec/riscv/h264qpel_rvv.S
> >
> >(I suggest to move them into some common include path)
>
> As we need to backport this, should we merge this to stable and the sx/lx
> version to master? Or should we merge this to master so that we can
> cherry-pick the exact patch to master?
>

As discussed on IRC, I've merged this for now. The refactor can (and
should) be done on top of this, but this allows for backporting.

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

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


Re: [FFmpeg-devel] [PATCH v2 1/6] Update R-V V vvc_mc vset to support more lengths

2024-12-10 Thread Nuo Mi
Hi Yuechi,
The performance is good.

There are many similar .if blocks in vsetvlstatic8, vsetvlstatic16, and
vsetvlstatic32.
Could we define an intermediate macro, vsetvlstatic, and use it to
implement the above macros?
like:
 .macro vsetvlstatic8 w, vlen
vsetvlstatic 8, w, vlen, mf8, mf4, mf2, m1, m2, m3, m4
.endm

This can be addressed with another patch set.

On Sun, Dec 1, 2024 at 1:11 PM  wrote:

> From: sunyuechi 
>
> ---
>  libavcodec/riscv/vvc/vvc_mc_rvv.S | 46 +++
>  1 file changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/libavcodec/riscv/vvc/vvc_mc_rvv.S
> b/libavcodec/riscv/vvc/vvc_mc_rvv.S
> index 45f4750f82..18532616d9 100644
> --- a/libavcodec/riscv/vvc/vvc_mc_rvv.S
> +++ b/libavcodec/riscv/vvc/vvc_mc_rvv.S
> @@ -23,25 +23,25 @@
>  .macro vsetvlstatic8 w, vlen
>  .if \w == 2 && \vlen == 128
>  vsetivlizero, \w, e8, mf8, ta, ma
> -.elseif \w == 4 && \vlen == 128
> +.elseif \w <= 4 && \vlen == 128
>  vsetivlizero, \w, e8, mf4, ta, ma
> -.elseif \w == 8 && \vlen == 128
> +.elseif \w <= 8 && \vlen == 128
>  vsetivlizero, \w, e8, mf2, ta, ma
> -.elseif \w == 16 && \vlen == 128
> +.elseif \w <= 16 && \vlen == 128
>  vsetivlizero, \w, e8, m1, ta, ma
> -.elseif \w == 32 && \vlen == 128
> +.elseif \w <= 32 && \vlen == 128
>  li  t0, \w
>  vsetvli zero, t0, e8, m2, ta, ma
>  .elseif \w <= 4 && \vlen == 256
>  vsetivlizero, \w, e8, mf8, ta, ma
> -.elseif \w == 8 && \vlen == 256
> +.elseif \w <= 8 && \vlen == 256
>  vsetivlizero, \w, e8, mf4, ta, ma
> -.elseif \w == 16 && \vlen == 256
> +.elseif \w <= 16 && \vlen == 256
>  vsetivlizero, \w, e8, mf2, ta, ma
> -.elseif \w == 32 && \vlen == 256
> +.elseif \w <= 32 && \vlen == 256
>  li  t0, \w
>  vsetvli zero, t0, e8, m1, ta, ma
> -.elseif \w == 64 && \vlen == 256
> +.elseif \w <= 64 && \vlen == 256
>  li  t0, \w
>  vsetvli zero, t0, e8, m2, ta, ma
>  .else
> @@ -53,25 +53,25 @@
>  .macro vsetvlstatic16 w, vlen
>  .if \w == 2 && \vlen == 128
>  vsetivlizero, \w, e16, mf4, ta, ma
> -.elseif \w == 4 && \vlen == 128
> +.elseif \w <= 4 && \vlen == 128
>  vsetivlizero, \w, e16, mf2, ta, ma
> -.elseif \w == 8 && \vlen == 128
> +.elseif \w <= 8 && \vlen == 128
>  vsetivlizero, \w, e16, m1, ta, ma
> -.elseif \w == 16 && \vlen == 128
> +.elseif \w <= 16 && \vlen == 128
>  vsetivlizero, \w, e16, m2, ta, ma
> -.elseif \w == 32 && \vlen == 128
> +.elseif \w <= 32 && \vlen == 128
>  li  t0, \w
>  vsetvli zero, t0, e16, m4, ta, ma
>  .elseif \w <= 4 && \vlen == 256
>  vsetivlizero, \w, e16, mf4, ta, ma
> -.elseif \w == 8 && \vlen == 256
> +.elseif \w <= 8 && \vlen == 256
>  vsetivlizero, \w, e16, mf2, ta, ma
> -.elseif \w == 16 && \vlen == 256
> +.elseif \w <= 16 && \vlen == 256
>  vsetivlizero, \w, e16, m1, ta, ma
> -.elseif \w == 32 && \vlen == 256
> +.elseif \w <= 32 && \vlen == 256
>  li  t0, \w
>  vsetvli zero, t0, e16, m2, ta, ma
> -.elseif \w == 64 && \vlen == 256
> +.elseif \w <= 64 && \vlen == 256
>  li  t0, \w
>  vsetvli zero, t0, e16, m4, ta, ma
>  .else
> @@ -83,19 +83,19 @@
>  .macro vsetvlstatic32 w, vlen
>  .if \w == 2
>  vsetivlizero, \w, e32, mf2, ta, ma
> -.elseif \w == 4 && \vlen == 128
> +.elseif \w <= 4 && \vlen == 128
>  vsetivlizero, \w, e32, m1, ta, ma
> -.elseif \w == 8 && \vlen == 128
> +.elseif \w <= 8 && \vlen == 128
>  vsetivlizero, \w, e32, m2, ta, ma
> -.elseif \w == 16 && \vlen == 128
> +.elseif \w <= 16 && \vlen == 128
>  vsetivlizero, \w, e32, m4, ta, ma
> -.elseif \w == 4 && \vlen == 256
> +.elseif \w <= 4 && \vlen == 256
>  vsetivlizero, \w, e32, mf2, ta, ma
> -.elseif \w == 8 && \vlen == 256
> +.elseif \w <= 8 && \vlen == 256
>  vsetivlizero, \w, e32, m1, ta, ma
> -.elseif \w == 16 && \vlen == 256
> +.elseif \w <= 16 && \vlen == 256
>  vsetivlizero, \w, e32, m2, ta, ma
> -.els

Re: [FFmpeg-devel] [PATCH v2 1/6] Update R-V V vvc_mc vset to support more lengths

2024-12-10 Thread flow gg
Thank you, this approach can indeed address similar if else scenarios.

vsetvlstatic \w, \vlen, e8, mf8, mf4, mf2, m1, m2, m4
vsetvlstatic \w, \vlen, e16, mf4, mf2, m1, m2, m4, m8
vsetvlstatic \w, \vlen, e32, mf2, m1, m2, m4, m8, m8

I plan to submit it after this patch set gets merged.

Nuo Mi  于2024年12月10日周二 21:52写道:

> Hi Yuechi,
> The performance is good.
>
> There are many similar .if blocks in vsetvlstatic8, vsetvlstatic16, and
> vsetvlstatic32.
> Could we define an intermediate macro, vsetvlstatic, and use it to
> implement the above macros?
> like:
>  .macro vsetvlstatic8 w, vlen
> vsetvlstatic 8, w, vlen, mf8, mf4, mf2, m1, m2, m3, m4
> .endm
>
> This can be addressed with another patch set.
>
> On Sun, Dec 1, 2024 at 1:11 PM  wrote:
>
> > From: sunyuechi 
> >
> > ---
> >  libavcodec/riscv/vvc/vvc_mc_rvv.S | 46 +++
> >  1 file changed, 23 insertions(+), 23 deletions(-)
> >
> > diff --git a/libavcodec/riscv/vvc/vvc_mc_rvv.S
> > b/libavcodec/riscv/vvc/vvc_mc_rvv.S
> > index 45f4750f82..18532616d9 100644
> > --- a/libavcodec/riscv/vvc/vvc_mc_rvv.S
> > +++ b/libavcodec/riscv/vvc/vvc_mc_rvv.S
> > @@ -23,25 +23,25 @@
> >  .macro vsetvlstatic8 w, vlen
> >  .if \w == 2 && \vlen == 128
> >  vsetivlizero, \w, e8, mf8, ta, ma
> > -.elseif \w == 4 && \vlen == 128
> > +.elseif \w <= 4 && \vlen == 128
> >  vsetivlizero, \w, e8, mf4, ta, ma
> > -.elseif \w == 8 && \vlen == 128
> > +.elseif \w <= 8 && \vlen == 128
> >  vsetivlizero, \w, e8, mf2, ta, ma
> > -.elseif \w == 16 && \vlen == 128
> > +.elseif \w <= 16 && \vlen == 128
> >  vsetivlizero, \w, e8, m1, ta, ma
> > -.elseif \w == 32 && \vlen == 128
> > +.elseif \w <= 32 && \vlen == 128
> >  li  t0, \w
> >  vsetvli zero, t0, e8, m2, ta, ma
> >  .elseif \w <= 4 && \vlen == 256
> >  vsetivlizero, \w, e8, mf8, ta, ma
> > -.elseif \w == 8 && \vlen == 256
> > +.elseif \w <= 8 && \vlen == 256
> >  vsetivlizero, \w, e8, mf4, ta, ma
> > -.elseif \w == 16 && \vlen == 256
> > +.elseif \w <= 16 && \vlen == 256
> >  vsetivlizero, \w, e8, mf2, ta, ma
> > -.elseif \w == 32 && \vlen == 256
> > +.elseif \w <= 32 && \vlen == 256
> >  li  t0, \w
> >  vsetvli zero, t0, e8, m1, ta, ma
> > -.elseif \w == 64 && \vlen == 256
> > +.elseif \w <= 64 && \vlen == 256
> >  li  t0, \w
> >  vsetvli zero, t0, e8, m2, ta, ma
> >  .else
> > @@ -53,25 +53,25 @@
> >  .macro vsetvlstatic16 w, vlen
> >  .if \w == 2 && \vlen == 128
> >  vsetivlizero, \w, e16, mf4, ta, ma
> > -.elseif \w == 4 && \vlen == 128
> > +.elseif \w <= 4 && \vlen == 128
> >  vsetivlizero, \w, e16, mf2, ta, ma
> > -.elseif \w == 8 && \vlen == 128
> > +.elseif \w <= 8 && \vlen == 128
> >  vsetivlizero, \w, e16, m1, ta, ma
> > -.elseif \w == 16 && \vlen == 128
> > +.elseif \w <= 16 && \vlen == 128
> >  vsetivlizero, \w, e16, m2, ta, ma
> > -.elseif \w == 32 && \vlen == 128
> > +.elseif \w <= 32 && \vlen == 128
> >  li  t0, \w
> >  vsetvli zero, t0, e16, m4, ta, ma
> >  .elseif \w <= 4 && \vlen == 256
> >  vsetivlizero, \w, e16, mf4, ta, ma
> > -.elseif \w == 8 && \vlen == 256
> > +.elseif \w <= 8 && \vlen == 256
> >  vsetivlizero, \w, e16, mf2, ta, ma
> > -.elseif \w == 16 && \vlen == 256
> > +.elseif \w <= 16 && \vlen == 256
> >  vsetivlizero, \w, e16, m1, ta, ma
> > -.elseif \w == 32 && \vlen == 256
> > +.elseif \w <= 32 && \vlen == 256
> >  li  t0, \w
> >  vsetvli zero, t0, e16, m2, ta, ma
> > -.elseif \w == 64 && \vlen == 256
> > +.elseif \w <= 64 && \vlen == 256
> >  li  t0, \w
> >  vsetvli zero, t0, e16, m4, ta, ma
> >  .else
> > @@ -83,19 +83,19 @@
> >  .macro vsetvlstatic32 w, vlen
> >  .if \w == 2
> >  vsetivlizero, \w, e32, mf2, ta, ma
> > -.elseif \w == 4 && \vlen == 128
> > +.elseif \w <= 4 && \vlen == 128
> >  vsetivlizero, \w, e32, m1, ta, ma
> > -.elseif \w == 8 && \vlen == 128
> > +.elseif \w <= 8 && \vlen == 128
> >  vsetivlizero, \w, e32, m2, ta, ma
> > -.elseif \w == 16 && \vlen == 128
> > +.elseif \w <= 16 && \

Re: [FFmpeg-devel] [PATCH] essim patch

2024-12-10 Thread Michael Niedermayer
Hi Andrea

I havnt really followed your gsoc work so in case some of my comments
below differs from your mentor(s), please point that out to me.

also maybe your mentors can do a full review (in CC) as it seems
noone else has reviewed your patch.

thx

On Thu, Dec 05, 2024 at 06:59:29PM +0100, AndreaMastroberti wrote:
[...]> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index f84dec4805..0050874108 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -31,8 +31,8 @@
>
>  #include "version_major.h"
>
> -#define LIBAVFILTER_VERSION_MINOR   6
> -#define LIBAVFILTER_VERSION_MICRO 101
> +#define LIBAVFILTER_VERSION_MINOR   7
> +#define LIBAVFILTER_VERSION_MICRO 100
>
>
>  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
> diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c
> index 52b22a6870..53b9af4d26 100644
> --- a/libavfilter/vf_ssim.c
> +++ b/libavfilter/vf_ssim.c
> @@ -44,6 +44,7 @@
>  #include "filters.h"
>  #include "framesync.h"
>  #include "ssim.h"
> +#include 
>
>  typedef struct SSIMContext {
>  const AVClass *class;
> @@ -63,8 +64,15 @@ typedef struct SSIMContext {
>  int **temp;
>  int is_rgb;
>  double **score;
> +uint64_t **i1[4], **i2[4], **s1[4], **s2[4], **i12[4];
> +int int_img;
> +int win_size;
> +int stride;
> +PoolMethod pool;
>  int (*ssim_plane)(AVFilterContext *ctx, void *arg,
>int jobnr, int nb_jobs);
> +int (*ssim_plane_int)(AVFilterContext *ctx, void *arg,
> +  int jobnr, int nb_jobs);
>  SSIMDSPContext dsp;
>  } SSIMContext;
>

> @@ -74,6 +82,13 @@ typedef struct SSIMContext {
>  static const AVOption ssim_options[] = {
>  {"stats_file", "Set file where to store per-frame difference 
> information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, 
> FLAGS },
>  {"f",  "Set file where to store per-frame difference 
> information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, 
> FLAGS },
> +{ "int_img", "Compute SSIM using integral images", OFFSET(int_img), 
> AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
> +{ "window", "Window size", OFFSET(win_size), AV_OPT_TYPE_INT, { .i64 = 8 
> }, 8, 16, FLAGS },
> +{ "stride", "Stride length", OFFSET(stride), AV_OPT_TYPE_INT, { .i64 = 4 
> }, 4, 8, FLAGS },
> +{ "pool", "Pooling method", OFFSET(pool), AV_OPT_TYPE_INT, {.i64 = AVG}, 
> 0, 2, FLAGS, "pool" },
> +{ "avg",   "Average pooling", 0, AV_OPT_TYPE_CONST, {.i64 = AVG}, 0, 
> 0, FLAGS, "pool" },
> +{ "mink3", "Minkowski norm 3", 0, AV_OPT_TYPE_CONST, {.i64 = 
> MINK_3},   0, 0, FLAGS, "pool" },
> +{ "mink4", "Minkowski norm 4", 0, AV_OPT_TYPE_CONST, {.i64 = 
> MINK_4},   0, 0, FLAGS, "pool" },
>  { NULL }
>  };
>  

These can be vertically aligned like:

> +{ "avg",   "Average pooling",  0, AV_OPT_TYPE_CONST, {.i64 =
> AVG},   0, 0, FLAGS, "pool" },
> +{ "mink3", "Minkowski norm 3", 0, AV_OPT_TYPE_CONST, {.i64 = 
> MINK_3},   0, 0, FLAGS, "pool" },
> +{ "mink4", "Minkowski norm 4", 0, AV_OPT_TYPE_CONST, {.i64 = 
> MINK_4},   0, 0, FLAGS, "pool" },




> @@ -175,6 +190,28 @@ static float ssim_end1x(int64_t s1, int64_t s2, int64_t 
> ss, int64_t s12, int max
>   / ((float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (float)(vars + 
> ssim_c2));
>  }
>  

> +static float ssim_end1w(int s1, int s2, int ss, int s12, int win_size)
> +{
> +double ws = (double)win_size * win_size;
> +double ssim_c1 = 0.01 * 0.01 * 255 * 255 * ws;
> +double ssim_c2 = 0.03 * 0.03 * 255 * 255 * ws * (ws - 1);
> +
> +double fs1 = (double)s1;
> +double fs2 = (double)s2;
> +double fss = (double)ss;
> +double fs12 = (double)s12;
> +
> +double vars = fss * ws - fs1 * fs1 - fs2 * fs2;
> +double covar = fs12 * ws - fs1 * fs2;

this can be calculated in int or int64 avoiding rounding issues with floats


> +
> +double num = (2 * fs1 * fs2 + ssim_c1) * (2 * covar + ssim_c2);

if you multiply
0.01 * 0.01 * 255 * 255 * ws
by 50 then its an integer and you could avoid floats (assuming ws is 8 or 16)
before the num / den

not sure how usefull it is to avoid float/double here but as the input
is integers it seemed an idea that may be interresting
this way the numbers could be kept exact until num / den below i think


[...]
> +static int ssim_plane_int(AVFilterContext *ctx, void *arg,
> +  int jobnr, int nb_jobs)
> +{
> +SSIMContext *s = ctx->priv;
> +ThreadData *td = arg;
> +double *score = td->score[jobnr];
> +void *temp = td->temp[jobnr];
> +int stride = s->stride, win_size = s->win_size;
> +uint64_t *i1, *i2, *s1, *s2, *i12;
> +int offset;
> +
> +for (int c = 0; c < td->nb_components; c++) {
> +int width = td->planewidth[c];
> +int height = td->planeheight[c];

> +const int slice_start = ((height/stride) * jobnr) / nb_

Re: [FFmpeg-devel] [PATCH 4/6] lavc/vvc: Fix scaling matrix DC coef derivation

2024-12-10 Thread Nuo Mi
Hi Frank,
Thank you for the detail
Applied.

On Sat, Nov 30, 2024 at 6:11 PM Frank Plowman  wrote:

> Hi,
>
> Thank you very much for the review.  Responses inline.
>
> On 30/11/2024 06:39, Nuo Mi wrote:
> > Hi Frank,
> > Thank you for the patch set; I will apply it except for this one
> >
> > On Fri, Nov 29, 2024 at 6:19 AM Frank Plowman 
> wrote:
> >
> >> In 7.4.3.20 of H.266 (V3), there are two similarly-named variables:
> >> scalingMatrixDcPred and ScalingMatrixDcRec.  The old code set
> >> ScalingMatrixDcRec, rather than scalingMatrixDcPred, in the first two
> >> branches of the conditions on scaling_list_copy_mode_flag[id] and
> >> aps->scaling_list_pred_mode_flag[id].  This could lead to decode
> >> mismatches in sequences with explicitly-signalled scaling lists.
> >>
> > dc is scaling_list_dc_coef, and scalingMatrixDcPred is 8, 16,
> > scaling_matrix_dc_rec, or scaling_matrix_rec.
> > Then we use (dc + scalingMatrixDcPred) & 255 to get ScalingMatrixDcRec
> > The original logic looks correct to me. Did I miss something? Could you
> > send me the clip?
>
> In the code before the patch, we don't add together scalingMatrixDcPred
> and scaling_list_dc_coef in the first two cases.  Indeed, dc (i.e.
> scaling_list_dc_coef) is entirely unused if
> aps->scaling_list_pred_id_delta[id] is zero.
>
> Before we hit this if (id >= SL_START_16x16) block, dc is equal to
> scaling_list_dc_coef.  Then, one of three things can happen:
> * If scaling_list_copy_mode_flag[id] and scaling_list_pred_mode_flag[id]
>   are both equal to zero:
> * Before the patch, scaling_matrix_dc_rec is set equal to 8, i.e.
>   scalingMatrixDcPred.  Then, scaling_matrix_dc_rec is set equal to
>   dc & 255, i.e. scalingMatrixDcPred & 255.  Note the missing
>   scaling_list_dc_coef term.
> * After the patch, 8, i.e. scalingMatrixDcPred is *added* to dc.
>   After this, the value of dc is
>   scaling_matrix_dc_rec + scalingMatrixDcPred.  Then,
>   scaling_matrix_dc_rec is set to dc & 255, i.e.
>   (scalingMatrixDcPred + scaling_matrix_dc_rec) & 255.
> * Otherwise, if scaling_list_pred_id_delta[id] is equal to 0, the case
>   proceeds in a similar fashion as for the first case, but with
>   scalingMatrixDcPred equal to 16 instead of 8.
> * Otherwise, before before and after the patch, dependent on the value
>   of refId, either ScalingMatrixDcRec or scalingMatrixPred is added to
>   dc, hence the value of dc is equal to
>   scalingMatrixDcPred + scaling_list_dc_coef.  We then set
>   scaling_matrix_dc_rec equal to dc & 255.
>
> This final case is fine both before and after the patch, but the first
> two cases are incorrect before the patch as dc (i.e.
> scaling_list_dc_coef) is unused.
>
> I observed this behaviour in the bitstream vvc_frames_with_ltr.vvc,
> available here:
>
> https://chromium.googlesource.com/chromium/src/+/lkgr/media/test/data/vvc_frames_with_ltr.vvc
> .
>  Note to download, the txt button at the button of the page gives the
> file encoded in base64 format.  I think this issue first appears in the
> CU with top-left corner (232, 216) on the frame with POC 0.
>
> >
> >>
> >> Signed-off-by: Frank Plowman 
> >> ---
> >>  libavcodec/vvc/ps.c | 6 +++---
> >>  1 file changed, 3 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/libavcodec/vvc/ps.c b/libavcodec/vvc/ps.c
> >> index f32f1cc5a1..9bd2d01776 100644
> >> --- a/libavcodec/vvc/ps.c
> >> +++ b/libavcodec/vvc/ps.c
> >> @@ -1107,17 +1107,17 @@ static void scaling_derive(VVCScalingList *sl,
> >> const H266RawAPS *aps)
> >>  //dc
> >>  if (id >= SL_START_16x16) {
> >>  if (!aps->scaling_list_copy_mode_flag[id] &&
> >> !aps->scaling_list_pred_mode_flag[id]) {
> >> -sl->scaling_matrix_dc_rec[id - SL_START_16x16] = 8;
> >> +dc += 8;
> >>  } else if (!aps->scaling_list_pred_id_delta[id]) {
> >> -sl->scaling_matrix_dc_rec[id - SL_START_16x16] = 16;
> >> +dc += 16;
> >>  } else {
> >>  const int ref_id = id -
> >> aps->scaling_list_pred_id_delta[id];
> >>  if (ref_id >= SL_START_16x16)
> >>  dc += sl->scaling_matrix_dc_rec[ref_id -
> >> SL_START_16x16];
> >>  else
> >>  dc += sl->scaling_matrix_rec[ref_id][0];
> >>
> > This should be  sl->scaling_matrix_rec[0][0];
> > Is the issue related to this?
>
> This might be another issue, I'm not sure.  I tried making this change
> and didn't observe any difference on vvc_frames_with_ltr.yuv or any of
> the conformance bitstreams.  I tried this both with and without my patch
> applied also, and still changing this to [0][0] made no difference.
>
> >
> > -sl->scaling_matrix_dc_rec[id - SL_START_16x16] = dc &
> 255;
> >>  }
> >> +sl->scaling_matrix_dc_rec[id - SL_START_16x16] = dc & 255;
> >>  }
> >>
> >>  //ac
> >> --
> >> 2.47.0
> >>
>
> --
> Frank

[FFmpeg-devel] [PATCH 1/2] avformat/hevc: add support for writing alpha layer

2024-12-10 Thread Timo Rothenpieler
---
 libavformat/hevc.c | 138 -
 1 file changed, 123 insertions(+), 15 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 7cf0b0ffb2..50e7f91bd2 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -82,6 +82,8 @@ typedef struct HEVCDecoderConfigurationRecord {
 uint8_t  lengthSizeMinusOne;
 uint8_t  numOfArrays;
 HVCCNALUnitArray arrays[NB_ARRAYS];
+
+uint8_t alpha_layer_nuh_id;
 } HEVCDecoderConfigurationRecord;
 
 typedef struct HVCCProfileTierLevel {
@@ -149,6 +151,7 @@ static void hvcc_update_ptl(HEVCDecoderConfigurationRecord 
*hvcc,
 
 static void hvcc_parse_ptl(GetBitContext *gb,
HEVCDecoderConfigurationRecord *hvcc,
+   int profile_present_flag,
unsigned int max_sub_layers_minus1)
 {
 unsigned int i;
@@ -156,13 +159,17 @@ static void hvcc_parse_ptl(GetBitContext *gb,
 uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
 uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
 
-general_ptl.profile_space   = get_bits(gb, 2);
-general_ptl.tier_flag   = get_bits1(gb);
-general_ptl.profile_idc = get_bits(gb, 5);
-general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
-general_ptl.constraint_indicator_flags  = get_bits64(gb, 48);
-general_ptl.level_idc   = get_bits(gb, 8);
-hvcc_update_ptl(hvcc, &general_ptl);
+if (profile_present_flag) {
+general_ptl.profile_space   = get_bits(gb, 2);
+general_ptl.tier_flag   = get_bits1(gb);
+general_ptl.profile_idc = get_bits(gb, 5);
+general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
+general_ptl.constraint_indicator_flags  = get_bits64(gb, 48);
+general_ptl.level_idc   = get_bits(gb, 8);
+hvcc_update_ptl(hvcc, &general_ptl);
+} else {
+skip_bits(gb, 8); // general_level_idc
+}
 
 for (i = 0; i < max_sub_layers_minus1; i++) {
 sub_layer_profile_present_flag[i] = get_bits1(gb);
@@ -387,12 +394,16 @@ static void skip_sub_layer_ordering_info(GetBitContext 
*gb)
 static int hvcc_parse_vps(GetBitContext *gb, HVCCNALUnit *nal,
   HEVCDecoderConfigurationRecord *hvcc)
 {
+uint8_t vps_base_layer_internal_flag, vps_max_layers_minus1;
+uint8_t vps_sub_layer_ordering_info_present_flag, vps_max_layer_id;
+int vps_num_layer_sets_minus1;
+int i, j;
+
 nal->parameter_set_id = get_bits(gb, 4);
-/*
- * vps_reserved_three_2bits   u(2)
- * vps_max_layers_minus1  u(6)
- */
-skip_bits(gb, 8);
+
+vps_base_layer_internal_flag = get_bits(gb, 1);
+skip_bits(gb, 1); // vps_base_layer_available_flag
+vps_max_layers_minus1 = get_bits(gb, 6);
 
 nal->vps_max_sub_layers_minus1 = get_bits(gb, 3);
 
@@ -413,7 +424,104 @@ static int hvcc_parse_vps(GetBitContext *gb, HVCCNALUnit 
*nal,
  */
 skip_bits(gb, 17);
 
-hvcc_parse_ptl(gb, hvcc, nal->vps_max_sub_layers_minus1);
+hvcc_parse_ptl(gb, hvcc, 1, nal->vps_max_sub_layers_minus1);
+
+vps_sub_layer_ordering_info_present_flag = get_bits(gb, 1);
+for (i = (vps_sub_layer_ordering_info_present_flag ? 0 : 
nal->vps_max_sub_layers_minus1);
+ i <= nal->vps_max_sub_layers_minus1; i++) {
+get_ue_golomb(gb); // vps_max_dec_pic_buffering_minus1
+get_ue_golomb(gb); // vps_max_num_reorder_pics
+get_ue_golomb(gb); // vps_max_latency_increase_plus1
+}
+
+vps_max_layer_id = get_bits(gb, 6);
+vps_num_layer_sets_minus1 = get_ue_golomb(gb);
+skip_bits_long(gb, (vps_max_layer_id + 1) * vps_num_layer_sets_minus1); // 
layer_id_included_flag[i][j]
+
+if (get_bits(gb, 1)) { // vps_timing_info_present_flag
+int vps_num_hrd_parameters;
+
+skip_bits_long(gb, 64); // vps_num_units_in_tick, vps_time_scale
+
+if (get_bits(gb, 1)) // vps_poc_proportional_to_timing_flag
+get_ue_golomb(gb); // vps_num_ticks_poc_diff_one_minus1
+
+vps_num_hrd_parameters = get_ue_golomb(gb); // vps_num_hrd_parameters
+
+for (i = 0; i < vps_num_hrd_parameters; i++) {
+int cprms_present_flag;
+
+get_ue_golomb(gb); // hrd_layer_set_idx[i]
+if (i > 0)
+cprms_present_flag = get_bits(gb, 1);
+else
+cprms_present_flag = 1;
+
+skip_hrd_parameters(gb, cprms_present_flag, 
nal->vps_max_sub_layers_minus1);
+}
+}
+
+if (get_bits(gb, 1)) { // vps_extension_flag
+uint8_t num_scalability_types = 0;
+uint8_t max_layers_minus_1 = FFMIN(62, vps_max_layers_minus1);
+uint8_t splitting_flag, vps_nuh_layer_id_present_flag;
+uint8_t scalability_mask_flag[16] = { 0 };
+uint8_t dimension_id_len[16] = { 0 };
+uint8_t lay

[FFmpeg-devel] [PATCH 2/2] avcodec/libx265: add alpha layer encoding support

2024-12-10 Thread Timo Rothenpieler
---
 libavcodec/libx265.c | 51 
 1 file changed, 37 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 63cc497f83..1bf2068f36 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -42,6 +42,14 @@
 #include "atsc_a53.h"
 #include "sei.h"
 
+#if defined(X265_ENABLE_ALPHA)
+#define FF_X265_MAX_LAYERS MAX_LAYERS
+#elif X265_BUILD >= 210
+#define FF_X265_MAX_LAYERS 2
+#else
+#define FF_X265_MAX_LAYERS 1
+#endif
+
 typedef struct ReorderedData {
 int64_t duration;
 
@@ -539,6 +547,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
 ctx->dovi.cfg.dv_bl_signal_compatibility_id;
 #endif
 
+#if X265_BUILD >= 210 && FF_X265_MAX_LAYERS > 1
+if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) {
+if (ctx->api->param_parse(ctx->params, "alpha", "1") < 0) {
+av_log(avctx, AV_LOG_ERROR, "Loaded libx265 does not support alpha 
layer encoding.\n");
+return AVERROR(ENOTSUP);
+}
+}
+#endif
+
 ctx->encoder = ctx->api->encoder_open(ctx->params);
 if (!ctx->encoder) {
 av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
@@ -661,13 +678,10 @@ static int libx265_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 {
 libx265Context *ctx = avctx->priv_data;
 x265_picture x265pic;
+x265_picture x265pic_out[FF_X265_MAX_LAYERS] = { 0 };
 #if (X265_BUILD >= 210) && (X265_BUILD < 213)
-x265_picture x265pic_layers_out[MAX_SCALABLE_LAYERS];
-x265_picture* x265pic_lyrptr_out[MAX_SCALABLE_LAYERS];
-#else
-x265_picture x265pic_solo_out = { 0 };
+x265_picture *x265pic_lyrptr_out[FF_X265_MAX_LAYERS];
 #endif
-x265_picture* x265pic_out;
 x265_nal *nal;
 x265_sei *sei;
 uint8_t *dst;
@@ -687,7 +701,11 @@ static int libx265_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 ReorderedData *rd;
 int rd_idx;
 
+#if X265_BUILD >= 210
+for (i = 0; i < 4; i++) {
+#else
 for (i = 0; i < 3; i++) {
+#endif
x265pic.planes[i] = pic->data[i];
x265pic.stride[i] = pic->linesize[i];
 }
@@ -806,14 +824,14 @@ static int libx265_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 }
 
 #if (X265_BUILD >= 210) && (X265_BUILD < 213)
-for (i = 0; i < MAX_SCALABLE_LAYERS; i++)
-x265pic_lyrptr_out[i] = &x265pic_layers_out[i];
+for (i = 0; i < FF_ARRAY_ELEMS(x265pic_out); i++)
+x265pic_lyrptr_out[i] = &x265pic_out[i];
 
 ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
pic ? &x265pic : NULL, x265pic_lyrptr_out);
 #else
 ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
-   pic ? &x265pic : NULL, &x265pic_solo_out);
+   pic ? &x265pic : NULL, x265pic_out);
 #endif
 
 for (i = 0; i < sei->numPayloads; i++)
@@ -844,12 +862,6 @@ static int libx265_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 pkt->flags |= AV_PKT_FLAG_KEY;
 }
 
-#if (X265_BUILD >= 210) && (X265_BUILD < 213)
-x265pic_out = x265pic_lyrptr_out[0];
-#else
-x265pic_out = &x265pic_solo_out;
-#endif
-
 pkt->pts = x265pic_out->pts;
 pkt->dts = x265pic_out->dts;
 
@@ -907,6 +919,9 @@ static const enum AVPixelFormat x265_csp_eight[] = {
 AV_PIX_FMT_YUVJ444P,
 AV_PIX_FMT_GBRP,
 AV_PIX_FMT_GRAY8,
+#if X265_BUILD >= 210 && FF_X265_MAX_LAYERS > 1
+AV_PIX_FMT_YUVA420P,
+#endif
 AV_PIX_FMT_NONE
 };
 
@@ -924,6 +939,10 @@ static const enum AVPixelFormat x265_csp_ten[] = {
 AV_PIX_FMT_GBRP10,
 AV_PIX_FMT_GRAY8,
 AV_PIX_FMT_GRAY10,
+#if X265_BUILD >= 210 && FF_X265_MAX_LAYERS > 1
+AV_PIX_FMT_YUVA420P,
+AV_PIX_FMT_YUVA420P10,
+#endif
 AV_PIX_FMT_NONE
 };
 
@@ -946,6 +965,10 @@ static const enum AVPixelFormat x265_csp_twelve[] = {
 AV_PIX_FMT_GRAY8,
 AV_PIX_FMT_GRAY10,
 AV_PIX_FMT_GRAY12,
+#if X265_BUILD >= 210 && FF_X265_MAX_LAYERS > 1
+AV_PIX_FMT_YUVA420P,
+AV_PIX_FMT_YUVA420P10,
+#endif
 AV_PIX_FMT_NONE
 };
 
-- 
2.45.2

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

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/hevc: add support for writing alpha layer

2024-12-10 Thread James Almer

On 12/10/2024 4:16 PM, Timo Rothenpieler wrote:

---
  libavformat/hevc.c | 138 -
  1 file changed, 123 insertions(+), 15 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 7cf0b0ffb2..50e7f91bd2 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -82,6 +82,8 @@ typedef struct HEVCDecoderConfigurationRecord {
  uint8_t  lengthSizeMinusOne;
  uint8_t  numOfArrays;
  HVCCNALUnitArray arrays[NB_ARRAYS];
+
+uint8_t alpha_layer_nuh_id;
  } HEVCDecoderConfigurationRecord;
  
  typedef struct HVCCProfileTierLevel {

@@ -149,6 +151,7 @@ static void hvcc_update_ptl(HEVCDecoderConfigurationRecord 
*hvcc,
  
  static void hvcc_parse_ptl(GetBitContext *gb,

 HEVCDecoderConfigurationRecord *hvcc,
+   int profile_present_flag,
 unsigned int max_sub_layers_minus1)
  {
  unsigned int i;
@@ -156,13 +159,17 @@ static void hvcc_parse_ptl(GetBitContext *gb,
  uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
  uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
  
-general_ptl.profile_space   = get_bits(gb, 2);

-general_ptl.tier_flag   = get_bits1(gb);
-general_ptl.profile_idc = get_bits(gb, 5);
-general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
-general_ptl.constraint_indicator_flags  = get_bits64(gb, 48);
-general_ptl.level_idc   = get_bits(gb, 8);
-hvcc_update_ptl(hvcc, &general_ptl);
+if (profile_present_flag) {
+general_ptl.profile_space   = get_bits(gb, 2);
+general_ptl.tier_flag   = get_bits1(gb);
+general_ptl.profile_idc = get_bits(gb, 5);
+general_ptl.profile_compatibility_flags = get_bits_long(gb, 32);
+general_ptl.constraint_indicator_flags  = get_bits64(gb, 48);
+general_ptl.level_idc   = get_bits(gb, 8);
+hvcc_update_ptl(hvcc, &general_ptl);
+} else {


Nit: unnecesary brackets.


+skip_bits(gb, 8); // general_level_idc
+}
  
  for (i = 0; i < max_sub_layers_minus1; i++) {

  sub_layer_profile_present_flag[i] = get_bits1(gb);
@@ -387,12 +394,16 @@ static void skip_sub_layer_ordering_info(GetBitContext 
*gb)
  static int hvcc_parse_vps(GetBitContext *gb, HVCCNALUnit *nal,
HEVCDecoderConfigurationRecord *hvcc)
  {
+uint8_t vps_base_layer_internal_flag, vps_max_layers_minus1;
+uint8_t vps_sub_layer_ordering_info_present_flag, vps_max_layer_id;
+int vps_num_layer_sets_minus1;
+int i, j;
+
  nal->parameter_set_id = get_bits(gb, 4);
-/*
- * vps_reserved_three_2bits   u(2)
- * vps_max_layers_minus1  u(6)
- */
-skip_bits(gb, 8);
+
+vps_base_layer_internal_flag = get_bits(gb, 1);
+skip_bits(gb, 1); // vps_base_layer_available_flag
+vps_max_layers_minus1 = get_bits(gb, 6);
  
  nal->vps_max_sub_layers_minus1 = get_bits(gb, 3);
  
@@ -413,7 +424,104 @@ static int hvcc_parse_vps(GetBitContext *gb, HVCCNALUnit *nal,

   */
  skip_bits(gb, 17);
  
-hvcc_parse_ptl(gb, hvcc, nal->vps_max_sub_layers_minus1);

+hvcc_parse_ptl(gb, hvcc, 1, nal->vps_max_sub_layers_minus1);
+
+vps_sub_layer_ordering_info_present_flag = get_bits(gb, 1);
+for (i = (vps_sub_layer_ordering_info_present_flag ? 0 : 
nal->vps_max_sub_layers_minus1);
+ i <= nal->vps_max_sub_layers_minus1; i++) {
+get_ue_golomb(gb); // vps_max_dec_pic_buffering_minus1
+get_ue_golomb(gb); // vps_max_num_reorder_pics
+get_ue_golomb(gb); // vps_max_latency_increase_plus1
+}
+
+vps_max_layer_id = get_bits(gb, 6);
+vps_num_layer_sets_minus1 = get_ue_golomb(gb);
+skip_bits_long(gb, (vps_max_layer_id + 1) * vps_num_layer_sets_minus1); // 
layer_id_included_flag[i][j]
+
+if (get_bits(gb, 1)) { // vps_timing_info_present_flag
+int vps_num_hrd_parameters;
+
+skip_bits_long(gb, 64); // vps_num_units_in_tick, vps_time_scale
+
+if (get_bits(gb, 1)) // vps_poc_proportional_to_timing_flag
+get_ue_golomb(gb); // vps_num_ticks_poc_diff_one_minus1
+
+vps_num_hrd_parameters = get_ue_golomb(gb); // vps_num_hrd_parameters
+
+for (i = 0; i < vps_num_hrd_parameters; i++) {
+int cprms_present_flag;
+
+get_ue_golomb(gb); // hrd_layer_set_idx[i]
+if (i > 0)
+cprms_present_flag = get_bits(gb, 1);
+else
+cprms_present_flag = 1;
+
+skip_hrd_parameters(gb, cprms_present_flag, 
nal->vps_max_sub_layers_minus1);
+}
+}
+
+if (get_bits(gb, 1)) { // vps_extension_flag


Maybe move this to its own function, following the syntax in the spec.


+uint8_t num_scalability_types = 0;
+uint8_t max_layers_minus_1 = FFMIN(62, vps_max_layers_mi

[FFmpeg-devel] [PATCH 4/5] avformat/iamf_writer: add support for expanded channel layouts

2024-12-10 Thread James Almer
Defined in Immersive Audio Model and Formats 1.1.0, sections 3.6.2 and 3.7.3

Signed-off-by: James Almer 
---
 libavformat/iamf_writer.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 7703729e07..f15dabcb3e 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -240,8 +240,13 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const 
AVStreamGroup *stg, void
 break;
 
 if (j >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
-av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in 
stream group #%d\n", i);
-return AVERROR(EINVAL);
+for (j = 0; j < 
FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); j++)
+if (!av_channel_layout_compare(&layer->ch_layout, 
&ff_iamf_expanded_scalable_ch_layouts[j]))
+break;
+if (j >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) 
{
+av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout 
in stream group #%d\n", i);
+return AVERROR(EINVAL);
+}
 }
 }
 
@@ -539,13 +544,19 @@ static int scalable_channel_layout_config(const 
IAMFAudioElement *audio_element,
 avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
 for (int i = 0; i < element->nb_layers; i++) {
 const AVIAMFLayer *layer = element->layers[i];
-int layout;
+int layout, expanded_layout = -1;
 for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); 
layout++) {
 if (!av_channel_layout_compare(&layer->ch_layout, 
&ff_iamf_scalable_ch_layouts[layout]))
 break;
 }
+if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts))
+for (expanded_layout = 0; expanded_layout < 
FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); expanded_layout++) {
+if (!av_channel_layout_compare(&layer->ch_layout, 
&ff_iamf_expanded_scalable_ch_layouts[expanded_layout]))
+break;
+}
+av_assert0(expanded_layout > 0 || layout < 
FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
 init_put_bits(&pb, header, sizeof(header));
-put_bits(&pb, 4, layout);
+put_bits(&pb, 4, expanded_layout >= 0 ? 15 : layout);
 put_bits(&pb, 1, !!layer->output_gain_flags);
 put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN));
 put_bits(&pb, 2, 0); // reserved
@@ -556,6 +567,8 @@ static int scalable_channel_layout_config(const 
IAMFAudioElement *audio_element,
 put_bits(&pb, 2, 0);
 put_bits(&pb, 16, rescale_rational(layer->output_gain, 1 << 8));
 }
+if (expanded_layout >= 0)
+put_bits(&pb, 8, expanded_layout);
 flush_put_bits(&pb);
 avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
 }
-- 
2.47.1

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

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


[FFmpeg-devel] [PATCH 3/5] avformat/iamf_parse: add support for expanded channel layouts

2024-12-10 Thread James Almer
Defined in Immersive Audio Model and Formats 1.1.0, sections 3.6.2 and 3.7.3

Signed-off-by: James Almer 
---
 libavformat/iamf.c   | 62 +++-
 libavformat/iamf.h   |  4 ++-
 libavformat/iamf_parse.c |  7 -
 3 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/libavformat/iamf.c b/libavformat/iamf.c
index 3fcf145a85..a01c99ea67 100644
--- a/libavformat/iamf.c
+++ b/libavformat/iamf.c
@@ -45,7 +45,66 @@ const AVChannelLayout ff_iamf_scalable_ch_layouts[10] = {
 AV_CHANNEL_LAYOUT_BINAURAL,
 };
 
-const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13] = {
+const AVChannelLayout ff_iamf_expanded_scalable_ch_layouts[13] = {
+{
+.nb_channels = 1,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_LOW_FREQUENCY,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT,
+},
+{
+.nb_channels = 4,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT |
+   AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT,
+},
+AV_CHANNEL_LAYOUT_SURROUND,
+AV_CHANNEL_LAYOUT_9POINT1POINT6,
+AV_CHANNEL_LAYOUT_STEREO,
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT,
+},
+{
+.nb_channels = 2,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_TOP_SIDE_LEFT | AV_CH_TOP_SIDE_RIGHT,
+},
+{
+.nb_channels = 6,
+.order   = AV_CHANNEL_ORDER_NATIVE,
+.u.mask  = AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT |
+   AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT |
+   AV_CH_TOP_SIDE_LEFT | AV_CH_TOP_SIDE_RIGHT,
+},
+};
+
+const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14] = {
 { SOUND_SYSTEM_A_0_2_0, AV_CHANNEL_LAYOUT_STEREO },
 { SOUND_SYSTEM_B_0_5_0, AV_CHANNEL_LAYOUT_5POINT1_BACK },
 { SOUND_SYSTEM_C_2_5_0, AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK },
@@ -65,6 +124,7 @@ const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13] 
= {
 { SOUND_SYSTEM_10_2_7_0, AV_CHANNEL_LAYOUT_7POINT1POINT2 },
 { SOUND_SYSTEM_11_2_3_0, AV_CHANNEL_LAYOUT_3POINT1POINT2 },
 { SOUND_SYSTEM_12_0_1_0, AV_CHANNEL_LAYOUT_MONO },
+{ SOUND_SYSTEM_13_9_1_6, AV_CHANNEL_LAYOUT_9POINT1POINT6 },
 };
 
 void ff_iamf_free_audio_element(IAMFAudioElement **paudio_element)
diff --git a/libavformat/iamf.h b/libavformat/iamf.h
index fd8b57a096..ad874c1fa8 100644
--- a/libavformat/iamf.h
+++ b/libavformat/iamf.h
@@ -156,6 +156,7 @@ enum IAMF_Sound_System {
 SOUND_SYSTEM_10_2_7_0 = 10, // "Loudspeaker configuration for Sound System 
I" + Ltf + Rtf
 SOUND_SYSTEM_11_2_3_0 = 11, // Front subset of "Loudspeaker configuration 
for Sound System J"
 SOUND_SYSTEM_12_0_1_0 = 12, // Mono
+SOUND_SYSTEM_13_9_1_6 = 13, // Subset of "Loudspeaker configuration for 
Sound System H"
 };
 
 struct IAMFSoundSystemMap {
@@ -165,7 +166,8 @@ struct IAMFSoundSystemMap {
 
 FF_VISIBILITY_PUSH_HIDDEN
 extern const AVChannelLayout ff_iamf_scalable_ch_layouts[10];
-extern const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13];
+extern const AVChannelLayout ff_iamf_expanded_scalable_ch_layouts[13];
+extern const struct IAMFSoundSystemMap ff_iamf_sound_system_map[14];
 
 static inline IAMFCodecConfig *ff_iamf_get_codec_config(const IAMFContext *c,
 unsigned int 
codec_config_id)
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 1e1de167e6..6c2efc0a6c 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -356,6 +356,7 @@ static int scalable_channel_layout_config(void *s, 
AVIOContext *pb,
 AVIAMFLayer *layer;
 int loudspeaker_layout, output_gain_is_present_flag;
 int substream_count, coupled_substream_count;
+int expanded_loudspeaker_layout = -1;
 int ret, byte = avio_r8(pb);
 
 layer = av_iamf_audio_element_add_layer(audio_element->element);
@@ -379,7 +380,11 @@ static int scalable_channel_layout_config(void *s, 
AVIOContext *pb,
 layer->output_gain = av_make_q(sign_extend(avio_rb

[FFmpeg-devel] [PATCH 2/5] avutil/channel_layout: simplify the 22.2 layout definition

2024-12-10 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/channel_layout.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index 4e0be7bed2..5ec09f10b1 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -252,7 +252,7 @@ enum AVChannelOrder {
 #define AV_CH_LAYOUT_HEXADECAGONAL 
(AV_CH_LAYOUT_OCTAGONAL|AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)
 #define AV_CH_LAYOUT_BINAURAL  
(AV_CH_BINAURAL_LEFT|AV_CH_BINAURAL_RIGHT)
 #define AV_CH_LAYOUT_STEREO_DOWNMIX(AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
-#define AV_CH_LAYOUT_22POINT2  
(AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_BACK_CENTER|AV_CH_LOW_FREQUENCY_2|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_CENTER|AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT|AV_CH_TOP_BACK_CENTER|AV_CH_BOTTOM_FRONT_CENTER|AV_CH_BOTTOM_FRONT_LEFT|AV_CH_BOTTOM_FRONT_RIGHT)
+#define AV_CH_LAYOUT_22POINT2  
(AV_CH_LAYOUT_9POINT1POINT6|AV_CH_BACK_CENTER|AV_CH_LOW_FREQUENCY_2|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_CENTER|AV_CH_TOP_BACK_CENTER|AV_CH_BOTTOM_FRONT_CENTER|AV_CH_BOTTOM_FRONT_LEFT|AV_CH_BOTTOM_FRONT_RIGHT)
 
 #define AV_CH_LAYOUT_7POINT1_TOP_BACK AV_CH_LAYOUT_5POINT1POINT2_BACK
 
-- 
2.47.1

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

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


[FFmpeg-devel] [PATCH 5/5] fate/iamf: add a test for expanded layouts

2024-12-10 Thread James Almer
Signed-off-by: James Almer 
---
 tests/fate/iamf.mak   |  10 +
 tests/filtergraphs/iamf_9_1_6 |   9 +
 tests/ref/fate/iamf-9_1_6 | 635 ++
 tests/streamgroups/audio_element-9_1_6|   3 +
 tests/streamgroups/mix_presentation-9_1_6 |   2 +
 5 files changed, 659 insertions(+)
 create mode 100644 tests/filtergraphs/iamf_9_1_6
 create mode 100644 tests/ref/fate/iamf-9_1_6
 create mode 100644 tests/streamgroups/audio_element-9_1_6
 create mode 100644 tests/streamgroups/mix_presentation-9_1_6

diff --git a/tests/fate/iamf.mak b/tests/fate/iamf.mak
index e42117da6c..28c997a8df 100644
--- a/tests/fate/iamf.mak
+++ b/tests/fate/iamf.mak
@@ -27,6 +27,16 @@ fate-iamf-7_1_4: CMD = transcode wav $(SRC) iamf 
"-auto_conversion_filters \
   -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 
-streamid 5:5 -streamid 6:6 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] 
-map [SIDE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" 
\
   "-show_entries 
stream_group=index,id,nb_streams,type:stream_group_components:stream_group_stream=index,id:stream_group_stream_disposition"
 
+FATE_IAMF-$(call TRANSCODE, FLAC, IAMF, WAV_DEMUXER PCM_S16LE_DECODER 
ARESAMPLE_FILTER) += fate-iamf-9_1_6
+fate-iamf-9_1_6: tests/data/asynth-44100-12.wav 
tests/data/filtergraphs/iamf_9_1_6 tests/data/streamgroups/audio_element-9_1_6 
tests/data/streamgroups/mix_presentation-9_1_6
+fate-iamf-9_1_6: SRC = $(TARGET_PATH)/tests/data/asynth-44100-12.wav
+fate-iamf-9_1_6: CMD = transcode wav $(SRC) iamf "-auto_conversion_filters \
+  -/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_9_1_6 \
+  -/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-9_1_6 \
+  -/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-9_1_6 
\
+  -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 
-streamid 5:5 -streamid 6:6 -streamid 7:7 -streamid 8:8 -map [FRONT] -map 
[BACK] -map [CENTER] -map [LFE] -map [FRONT_CENTER] -map [SIDE] -map 
[TOP_FRONT] -map [TOP_BACK] -map [TOP_SIDE] -c:a flac -t 1" "-c:a copy -map 0" \
+  "-show_entries 
stream_group=index,id,nb_streams,type:stream_group_components:stream_group_stream=index,id:stream_group_stream_disposition"
+
 FATE_IAMF-$(call TRANSCODE, FLAC, IAMF, WAV_DEMUXER PCM_S16LE_DECODER 
ARESAMPLE_FILTER) += fate-iamf-ambisonic_1
 fate-iamf-ambisonic_1: tests/data/asynth-44100-4.wav 
tests/data/filtergraphs/iamf_ambisonic_1 
tests/data/streamgroups/audio_element-ambisonic_1 
tests/data/streamgroups/mix_presentation-ambisonic_1
 fate-iamf-ambisonic_1: SRC = $(TARGET_PATH)/tests/data/asynth-44100-4.wav
diff --git a/tests/filtergraphs/iamf_9_1_6 b/tests/filtergraphs/iamf_9_1_6
new file mode 100644
index 00..4cad1b6f6c
--- /dev/null
+++ b/tests/filtergraphs/iamf_9_1_6
@@ -0,0 +1,9 @@
+[0:a]channelmap=0|1:stereo[FRONT];
+[0:a]channelmap=4|5:stereo[BACK];
+[0:a]channelmap=2:mono[CENTER];
+[0:a]channelmap=3:mono[LFE];
+[0:a]channelmap=0|1:stereo[FRONT_CENTER];
+[0:a]channelmap=6|7:stereo[SIDE];
+[0:a]channelmap=8|9:stereo[TOP_FRONT];
+[0:a]channelmap=10|11:stereo[TOP_BACK];
+[0:a]channelmap=10|11:stereo[TOP_SIDE];
diff --git a/tests/ref/fate/iamf-9_1_6 b/tests/ref/fate/iamf-9_1_6
new file mode 100644
index 00..85394ee850
--- /dev/null
+++ b/tests/ref/fate/iamf-9_1_6
@@ -0,0 +1,635 @@
+1d1b9faf44a7906d08e499d2b3170211 *tests/data/fate/iamf-9_1_6.iamf
+128314 tests/data/fate/iamf-9_1_6.iamf
+#extradata 0:   34, 0xafa70d5e
+#extradata 1:   34, 0xafa70d5e
+#extradata 2:   34, 0xafa70d5e
+#extradata 3:   34, 0xafa70d5e
+#extradata 4:   34, 0xafa70d5e
+#extradata 5:   34, 0xafa70d5e
+#extradata 6:   34, 0xafa70d5e
+#extradata 7:   34, 0xaf7b0d5c
+#extradata 8:   34, 0xaf7b0d5c
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: flac
+#sample_rate 0: 44100
+#channel_layout_name 0: stereo
+#tb 1: 1/44100
+#media_type 1: audio
+#codec_id 1: flac
+#sample_rate 1: 44100
+#channel_layout_name 1: stereo
+#tb 2: 1/44100
+#media_type 2: audio
+#codec_id 2: flac
+#sample_rate 2: 44100
+#channel_layout_name 2: stereo
+#tb 3: 1/44100
+#media_type 3: audio
+#codec_id 3: flac
+#sample_rate 3: 44100
+#channel_layout_name 3: stereo
+#tb 4: 1/44100
+#media_type 4: audio
+#codec_id 4: flac
+#sample_rate 4: 44100
+#channel_layout_name 4: stereo
+#tb 5: 1/44100
+#media_type 5: audio
+#codec_id 5: flac
+#sample_rate 5: 44100
+#channel_layout_name 5: stereo
+#tb 6: 1/44100
+#media_type 6: audio
+#codec_id 6: flac
+#sample_rate 6: 44100
+#channel_layout_name 6: stereo
+#tb 7: 1/44100
+#media_type 7: audio
+#codec_id 7: flac
+#sample_rate 7: 44100
+#channel_layout_name 7: mono
+#tb 8: 1/44100
+#media_type 8: audio
+#codec_id 8: flac
+#sample_rate 8: 44100
+#channel_layout_name 8: mono
+0,  0,  0, 4608, 1399, 0x6e89566e
+1,  0,  0, 4608, 1399, 0x6e89566e
+2,  0,  0, 4608, 1396, 0x0dc

Re: [FFmpeg-devel] [PATCH v2] checkasm: vvc: Use checkasm_check for printing failing output

2024-12-10 Thread Martin Storsjö

On Mon, 9 Dec 2024, Ronald S. Bultje wrote:


On Mon, Dec 9, 2024 at 5:02 PM Martin Storsjö  wrote:
  Share the checkasm_check_pixel macro from hevc_pel in
  checkasm.h,
  to allow other tests to use the same. (To use it in other tests,
  those tests need to have a similar setup for high bitdepth
  pixels,
  with a local variable named "bit_depth".)

  This simplifies the code for checking the output, and can print
  the failing output (including a map of matching/mismatching
  elements) if checkasm is run with the -v/--verbose option.
  ---
  v2: Moved the macro to checkasm.h and added a comment about
  where
  it works and what it assumes. I checked that other checkasm
  tests
  like vp9dsp also have a similarly matching bit_depth parameter,
  so it might work quite well there too.
  ---
   tests/checkasm/checkasm.h | 12 
   tests/checkasm/hevc_pel.c |  9 -
   tests/checkasm/vvc_alf.c  | 10 ++
   3 files changed, 14 insertions(+), 17 deletions(-)


No further comments from me - LGTM.


Thanks, pushed.

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

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


Re: [FFmpeg-devel] [PATCH 1/2] aarch64/vvc: Fix clip in alf

2024-12-10 Thread Nuo Mi
On Tue, Dec 10, 2024 at 3:35 PM Martin Storsjö  wrote:

> On Tue, 10 Dec 2024, Zhao Zhili wrote:
>
> > From: Zhao Zhili 
> >
> > Fix test failure:
> > ./tests/checkasm/checkasm --test=vvc_alf 3607569773
> > ---
> > libavcodec/aarch64/vvc/alf.S | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
>
> After pushing (and after leaving it in git master for a little while),
> this probably should be backported to 7.1 as well, as the bug afaik is
> present there too.
>
Applied to master.
Thank you, Martin and Zhili

>
> // Martin
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
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 09/16] avfilter/vf_scale: add colorspace and transfer property options

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:08PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> In the long run, it would be ideal if we could add these to the avfilter
> negotiation as well, but for now, this is a good start.
> ---
>  doc/filters.texi   | 56 +++
>  libavfilter/vf_scale.c | 75 +-
>  2 files changed, 130 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 9068a8a4e7..eb7463db84 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -21189,6 +21189,62 @@ is used by default. Possible values:
>  @item bottom
>  @end table
>  
> +@item in_primaries
> +@item out_primaries
> +Set in/output RGB primaries.
> +
> +This allows the autodetected value to be overridden as well as allows forcing
> +a specific value used for the output and encoder. Possible values:
> +
> +@table @samp
> +@item auto/unknown
> +Choose automatically.
> +
> +@item bt709
> +@item bt470m
> +@item bt470bg
> +@item smpte170m
> +@item smpte240m
> +@item film
> +@item bt2020
> +@item smpte428
> +@item smpte431
> +@item smpte432
> +@item jedec-p22
> +@item ebu3213
> +@end table
> +
> +@item in_transfer
> +@item out_transfer
> +Set in/output transfer response curve (TRC).
> +
> +This allows the autodetected value to be overridden as well as allows forcing
> +a specific value used for the output and encoder. Possible values:
> +
> +@table @samp
> +@item auto/unknown
> +Choose automatically.
> +
> +@item bt709
> +@item bt470m
> +@item gamma22
> +@item bt470bg
> +@item gamma28
> +@item smpte170m
> +@item smpte240m
> +@item linear
> +@item iec61966-2-1
> +@item srgb
> +@item iec61966-2-4
> +@item xvycc
> +@item bt1361e
> +@item bt2020-10
> +@item bt2020-12
> +@item smpte2084
> +@item smpte428
> +@item arib-std-b67
> +@end table
> +

[...]

> @@ -1084,6 +1119,44 @@ static const AVOption scale_options[] = {
>  {"top",   NULL, 0, AV_OPT_TYPE_CONST, 
> {.i64=AVCHROMA_LOC_TOP}, 0, 0, FLAGS, .unit = "chroma_loc"},
>  {"bottomleft",NULL, 0, AV_OPT_TYPE_CONST, 
> {.i64=AVCHROMA_LOC_BOTTOMLEFT},  0, 0, FLAGS, .unit = "chroma_loc"},
>  {"bottom",NULL, 0, AV_OPT_TYPE_CONST, 
> {.i64=AVCHROMA_LOC_BOTTOM},  0, 0, FLAGS, .unit = "chroma_loc"},
> +{  "in_primaries", "set input primaries",   OFFSET(in_primaries),  
> AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AVCOL_PRI_NB-1, .flags = FLAGS, .unit = 
> "primaries" },
> +{ "out_primaries", "set output primaries",  OFFSET(out_primaries), 
> AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_UNSPECIFIED }, 0, AVCOL_PRI_NB-1, .flags 
> = FLAGS, .unit = "primaries"},
> +{"auto", NULL,  0, AV_OPT_TYPE_CONST, {.i64=-1}, 
>0, 0, FLAGS, .unit = "primaries"},
> +{"bt709",NULL,  0, AV_OPT_TYPE_CONST, 
> {.i64=AVCOL_PRI_BT709},   0, 0, FLAGS, .unit = "primaries"},
> +{"unknown",  NULL,  0, AV_OPT_TYPE_CONST, 
> {.i64=AVCOL_PRI_UNSPECIFIED}, 0, 0, FLAGS, .unit = "primaries"},

please document the meaning difference in the documentation for auto vs 
unspecified

thx

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

Take away the freedom of one citizen and you will be jailed, take away
the freedom of all citizens and you will be congratulated by your peers
in Parliament.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 13/16] swscale/lut3d: add 3DLUT dispatch system

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:12PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> This is a lightweight wrapper around the underlying color management system,
> whose job it is merely to manage the 3DLUT state and apply them to the frame
> data. This is where we might add platform-specific optimizations in the 
> future.
> 
> I also plan on adding support for more pixel formats in the future. In
> particular, we could support YUV or XYZ input formats directly using only
> negligible additional code in the 3DLUT setup functions. This would eliminate
> the major source of slowdown, which is currently the roundtrip to RGBA64.
> ---
>  libswscale/Makefile |   1 +
>  libswscale/lut3d.c  | 290 
>  libswscale/lut3d.h  |  98 +++
>  3 files changed, 389 insertions(+)
>  create mode 100644 libswscale/lut3d.c
>  create mode 100644 libswscale/lut3d.h
> 
> diff --git a/libswscale/Makefile b/libswscale/Makefile
> index c4e45d494e..267952d870 100644
> --- a/libswscale/Makefile
> +++ b/libswscale/Makefile
> @@ -14,6 +14,7 @@ OBJS = alphablend.o \
> graph.o  \
> half2float.o \
> input.o  \
> +   lut3d.o  \
> options.o\
> output.o \
> rgb2rgb.o\
> diff --git a/libswscale/lut3d.c b/libswscale/lut3d.c
> new file mode 100644
> index 00..e62820b244
> --- /dev/null
> +++ b/libswscale/lut3d.c
> @@ -0,0 +1,290 @@
> +/*
> + * Copyright (C) 2024 Niklas Haas
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include 
> +#include 
> +
> +#include "libavutil/attributes.h"
> +#include "libavutil/avassert.h"
> +#include "libavutil/mem.h"
> +
> +#include "cms.h"
> +#include "csputils.h"
> +#include "lut3d.h"
> +
> +SwsLut3D *sws_lut3d_alloc(void)
> +{
> +SwsLut3D *lut3d = av_malloc(sizeof(*lut3d));
> +if (!lut3d)
> +return NULL;
> +
> +lut3d->dynamic = false;
> +return lut3d;
> +}
> +
> +void sws_lut3d_free(SwsLut3D **plut3d)
> +{
> +av_freep(plut3d);
> +}
> +
> +bool sws_lut3d_test_fmt(enum AVPixelFormat fmt, int output)
> +{
> +return fmt == AV_PIX_FMT_RGBA64;
> +}
> +
> +enum AVPixelFormat sws_lut3d_pick_pixfmt(SwsFormat fmt, int output)
> +{
> +return AV_PIX_FMT_RGBA64;
> +}
> +

> +/**
> + * v0 and v1 are 'black' and 'white'
> + * v1 and v2 are closest RGB/CMY vertices

probably typo v2, v3 instead

thx

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

The real ebay dictionary, page 1
"Used only once"- "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH v2 14/16] swscale/graph: add color mapping pass

2024-12-10 Thread Michael Niedermayer
Hi

On Fri, Dec 06, 2024 at 03:32:13PM +0100, Niklas Haas wrote:
> From: Niklas Haas 
> 
> This leverages the previously introduced color management subsystem in order
> to adapt between transfer functions and color spaces, as well as for HDR tone
> mapping.
> 
> Take special care to handle grayscale formats without a colorspace
> gracefully.
> ---
>  libswscale/graph.c | 95 +-
>  1 file changed, 93 insertions(+), 2 deletions(-)

probably ok

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

I have often repented speaking, but never of holding my tongue.
-- Xenocrates


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] libavcodec/mpegaudio_parser.c: differentiate MPEG audio dual mono

2024-12-10 Thread Scott Theisen

On 12/9/24 02:31, Anton Khirnov wrote:

Quoting Scott Theisen (2024-11-30 08:38:54)

On 11/25/24 00:42, Anton Khirnov wrote:

Quoting Scott Theisen (2024-11-14 05:37:49)

@@ -85,7 +85,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
   if (s->header_count > header_threshold) {
   avctx->sample_rate= sr;
   av_channel_layout_uninit(&avctx->ch_layout);
-av_channel_layout_default(&avctx->ch_layout, channels);
+if (dual_mono) {
+av_channel_layout_custom_init(&avctx->ch_layout, 
2);

This can fail - the return code should be checked.


It can only fail if av_calloc() fails to allocate 48 bytes.  Should it
return buf_size or just use the default order?

Memory allocation failure should always propagate back to the caller.



The parsers can't return error codes, though.  See line 105 in 
libavcodec/mpegaudio_parser.c

```
return buf_size; /* parsers must not return error codes */
```

and lines 2911-2916 in libavcodec/avcodec.h
```
/* This callback never returns an error, a negative value means that
 * the frame start was in a previous packet. */
int (*parser_parse)(AVCodecParserContext *s,
    AVCodecContext *avctx,
    const uint8_t **poutbuf, int *poutbuf_size,
    const uint8_t *buf, int buf_size);
```

Regards,

Scott Theisen
___
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 5/7] avformat/mpegts: add s337m support

2024-12-10 Thread Martin Storsjö

On Tue, 10 Dec 2024, Scott Theisen wrote:

ff_* symbols are not exported and are internal to each library. Some of 
the other libraries `#include "libavutil/reverse.c"` in a file.  Should 
ff_reverse be renamed avpriv_reverse so that is not necessary?


No, this is intentionally done this way.

If we'd make it into avpriv_reverse, then we'd also need to distinguish 
between whether we're accessing it from within the same library where it 
is defined, or mark the declaration with dllimport, if building shared 
libraries with MSVC.


Back when ffmpeg was made to support MSVC and building shared libraries 
with it, we decided not to try to add dllimport for it; these tables are 
miniscule anyway. So if building shared libraries, we instead duplicate 
the tables within each shared library that uses them.


(Later we did end up adding selective dllimport for cross-library tables 
anyway though. But we tend to prefer to avoid avpriv symbols if possible, 
as they're effectively part of the ABI surface even if they're supposed to 
be private.)


In any case - just replicate the existing pattern for duplicating 
reverse.c into libavformat, like is done in the other libraries that use 
the symbol; changing how it is set up is a much larger discussion.


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

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


[FFmpeg-devel] [PATCH v2] avformat/mov: don't reallocate extradata when converting dvdsub palette

2024-12-10 Thread Marth64
After introduction of ff_dvdclut_palette_extradata_cat() to convert
DVD subtitle palettes from YUV to RGB, a leak is introduced because
of the call to ff_alloc_extradata(). This is not necessary, instead
we should free the extradata because ff_bprint_to_codecpar_extradata()
will finalize the bprint'ed string to the codecpar and set the length.

Fixes leak introduced in 3b0e6c0eccd7d61eb089370fc5f2196c2b30336f.

v2 also sets the extradata_size to 0 after it is freed.

Signed-off-by: Marth64 
---
 libavformat/mov.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 3820983a5d..26f1bf7e1b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10602,9 +10602,8 @@ static int mov_read_header(AVFormatContext *s)
 if (err < 0)
 return err;
 
-err = ff_alloc_extradata(st->codecpar, 
FF_DVDCLUT_EXTRADATA_SIZE);
-if (err < 0)
-return err;
+av_freep(&st->codecpar->extradata);
+st->codecpar->extradata_size = 0;
 
 err = ff_dvdclut_palette_extradata_cat(dvdsub_clut, 
FF_DVDCLUT_CLUT_SIZE,
st->codecpar);
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH] libavcodec/mpegaudio_parser.c: differentiate MPEG audio dual mono

2024-12-10 Thread Scott Theisen

On 12/9/24 02:30, Anton Khirnov wrote:

Quoting James Almer (2024-11-30 14:41:20)

On 11/14/2024 1:37 AM, Scott Theisen wrote:

When attempting to upstream this MythTV change in September 2022, it was 
recommended to
use AV_CHANNEL_ORDER_CUSTOM with two AV_CHAN_FRONT_CENTER channels. See
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220921192611.3241-1-scott.the@gmail.com/
---
   libavcodec/audiotoolboxdec.c|  4 ++--
   libavcodec/mpegaudio_parser.c   | 12 +---
   libavcodec/mpegaudiodecheader.c |  4 +++-
   libavcodec/mpegaudiodecheader.h |  2 +-
   tests/ref/fate/pva-demux|  2 +-
   5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
index 0f7ce8e4eb..d279d7bbc4 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -346,10 +346,10 @@ static av_cold int ffat_create_decoder(AVCodecContext 
*avctx,
   avctx->codec_id == AV_CODEC_ID_MP2 ||
   avctx->codec_id == AV_CODEC_ID_MP3)) {
   enum AVCodecID codec_id;
-int bit_rate;
+int bit_rate, dual_mono;
   if (ff_mpa_decode_header(AV_RB32(pkt->data), &avctx->sample_rate,
&in_format.mChannelsPerFrame, 
&avctx->frame_size,
- &bit_rate, &codec_id) < 0)
+ &bit_rate, &codec_id, &dual_mono) < 0)
   return AVERROR_INVALIDDATA;
   avctx->bit_rate = bit_rate;
   in_format.mSampleRate = avctx->sample_rate;
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index d54366f10a..d1a4ee6434 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -65,12 +65,12 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
   }
   }else{
   while(icodec_id;
   
   state= (state<<8) + buf[i++];
   
-ret = ff_mpa_decode_header(state, &sr, &channels, &frame_size, &bit_rate, &codec_id);

+ret = ff_mpa_decode_header(state, &sr, &channels, &frame_size, 
&bit_rate, &codec_id, &dual_mono);
   if (ret < 4) {
   if (i > 4)
   s->header_count = -2;
@@ -85,7 +85,13 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
   if (s->header_count > header_threshold) {
   avctx->sample_rate= sr;
   av_channel_layout_uninit(&avctx->ch_layout);
-av_channel_layout_default(&avctx->ch_layout, channels);
+if (dual_mono) {
+av_channel_layout_custom_init(&avctx->ch_layout, 
2);
+avctx->ch_layout.u.map[0].id = 
AV_CHAN_FRONT_CENTER;
+avctx->ch_layout.u.map[1].id = 
AV_CHAN_FRONT_CENTER;

Kind of sucks we have used FC to represent mono for so long that we
can't cleanly introduce a new channel that's strictly mono (with no
speaker location implied) and give it meaningful use.

AV_CHAN_UNKNOWN?



Using AV_CHAN_UNKNOWN would be fine with me.

However, would using AV_CHANNEL_ORDER_UNSPEC instead of 
AV_CHANNEL_ORDER_CUSTOM be better?


Regards,

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

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


Re: [FFmpeg-devel] [PATCH] avcodec: uninit hwaccel in case of software decoder

2024-12-10 Thread Thomas Guillem via ffmpeg-devel
Hi,

On Tue, Dec 10, 2024, at 19:29, Anton Khirnov wrote:
> Hi,
> Quoting Thomas Guillem via ffmpeg-devel (2024-11-29 11:44:21)
>> avcodec_get_hw_frames_parameters(), called by the user from get_format,
>> is allocating ctx->internal->hwaccel_priv_data. But the hardware
>> decoding setup may fail on the user side and it may fallback to software
>> decoding. In that case, ctx->internal->hwaccel_priv_data is still
>> allocated but not used anymore.
>> 
>> Fixes the following assert:
>> 
>> Assertion p_dst->hwaccel_threadsafe || (!dst->hwaccel && 
>> !dst->internal->hwaccel_priv_data) failed at 
>> src/libavcodec/pthread_frame.c:426
>> ---
>>  libavcodec/decode.c | 2 ++
>>  1 file changed, 2 insertions(+)
>
> I think the actual problem is that avcodec_get_hw_frames_parameters()
> modifies the codec context, even though it's explicitly documented not
> to. I discussed this with Lynne on IRC, and she's working on removing
> the need for that from vulkan decoding, which should be a more proper
> fix here.

Indeed, it seems to be a proper solution.

Note that 6.x and 7.1 will need a backport of the fix (or a workaround like 
this patch if it is too complex to backport).

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

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