Skip to content

Commit

Permalink
Merge pull request #439 from jellyfin/jellyfin-7.0-fix-vt-color-range
Browse files Browse the repository at this point in the history
avfilter/*videotoolbox: fix color range handling
  • Loading branch information
gnattu authored Aug 21, 2024
2 parents acea697 + efdad37 commit a893486
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 11 deletions.
4 changes: 2 additions & 2 deletions debian/patches/0004-add-cuda-tonemap-impl.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2836,8 +2836,8 @@ Index: FFmpeg/libavfilter/vf_tonemap_cuda.c
+ { "p", "Set color primaries", OFFSET(pri), AV_OPT_TYPE_INT, {.i64 = AVCOL_PRI_BT709}, -1, INT_MAX, FLAGS, .unit = "primaries" },
+ { "bt709", 0, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_BT709}, 0, 0, FLAGS, .unit = "primaries" },
+ { "bt2020", 0, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_BT2020}, 0, 0, FLAGS, .unit = "primaries" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_MPEG}, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_MPEG}, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "tv", 0, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_MPEG}, 0, 0, FLAGS, .unit = "range" },
+ { "pc", 0, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, .unit = "range" },
+ { "limited", 0, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_MPEG}, 0, 0, FLAGS, .unit = "range" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2160,8 +2160,8 @@ Index: FFmpeg/libavfilter/vf_tonemap_opencl.c
+ { "p", "Set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_BT709 }, -1, INT_MAX, FLAGS, "primaries" },
+ { "bt709", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_PRI_BT709 }, 0, 0, FLAGS, "primaries" },
+ { "bt2020", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_PRI_BT2020 }, 0, 0, FLAGS, "primaries" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_MPEG }, -1, INT_MAX, FLAGS, "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_MPEG }, -1, INT_MAX, FLAGS, "range" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS, "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS, "range" },
+ { "tv", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" },
+ { "pc", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" },
+ { "limited", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Index: FFmpeg/libavfilter/vf_scale_vt.c

err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
&s->output_width,
@@ -198,11 +214,18 @@ static int scale_vt_config_output(AVFilt
@@ -198,13 +214,21 @@ static int scale_vt_config_output(AVFilt

hw_frame_ctx_in = (AVHWFramesContext *)inlink->hw_frames_ctx->data;

Expand All @@ -56,8 +56,11 @@ Index: FFmpeg/libavfilter/vf_scale_vt.c
+ hw_frame_ctx_out->sw_format = out_format;
hw_frame_ctx_out->width = outlink->w;
hw_frame_ctx_out->height = outlink->h;
+ ((AVVTFramesContext *)hw_frame_ctx_out->hwctx)->color_range = ((AVVTFramesContext *)hw_frame_ctx_in->hwctx)->color_range;

@@ -234,6 +257,8 @@ static const AVOption scale_vt_options[]
err = ff_filter_init_hw_frames(avctx, outlink, 1);
if (err < 0)
@@ -234,6 +258,8 @@ static const AVOption scale_vt_options[]
OFFSET(colour_primaries_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
{ "color_transfer", "Output colour transfer characteristics",
OFFSET(colour_transfer_string), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,51 @@ Index: FFmpeg/libavutil/hwcontext_videotoolbox.h
*/
int av_vt_pixbuf_set_attachments(void *log_ctx,
CVPixelBufferRef pixbuf, const struct AVFrame *src);
Index: FFmpeg/libavfilter/vf_yadif_videotoolbox.m
===================================================================
--- FFmpeg.orig/libavfilter/vf_yadif_videotoolbox.m
+++ FFmpeg/libavfilter/vf_yadif_videotoolbox.m
@@ -24,6 +24,7 @@
#include "yadif.h"
#include "libavutil/avassert.h"
#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_videotoolbox.h"
#include "libavutil/objc.h"

#include <assert.h>
@@ -94,9 +95,6 @@ static void call_kernel(AVFilterContext

[buffer commit];
[buffer waitUntilCompleted];
-
- ff_objc_release(&encoder);
- ff_objc_release(&buffer);
}

static void filter(AVFilterContext *ctx, AVFrame *dst,
@@ -321,8 +319,9 @@ static int config_input(AVFilterLink *in

static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0))
{
- AVHWFramesContext *output_frames;
+ AVHWFramesContext *output_frames, *input_frames;
AVFilterContext *ctx = link->src;
+ AVFilterLink *inlink = link->src->inputs[0];
YADIFVTContext *s = ctx->priv;
YADIFContext *y = &s->yadif;
int ret = 0;
@@ -343,12 +342,14 @@ static int do_config_output(AVFilterLink
goto exit;
}

+ input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
output_frames = (AVHWFramesContext*)link->hw_frames_ctx->data;

output_frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
output_frames->sw_format = s->input_frames->sw_format;
output_frames->width = ctx->inputs[0]->w;
output_frames->height = ctx->inputs[0]->h;
+ ((AVVTFramesContext *)output_frames->hwctx)->color_range = ((AVVTFramesContext *)input_frames->hwctx)->color_range;

ret = ff_filter_init_hw_frames(ctx, link, 10);
if (ret < 0)
4 changes: 3 additions & 1 deletion debian/patches/0050-add-vf-overlay-videotoolbox-filter.patch
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Index: FFmpeg/libavfilter/vf_overlay_videotoolbox.m
===================================================================
--- /dev/null
+++ FFmpeg/libavfilter/vf_overlay_videotoolbox.m
@@ -0,0 +1,749 @@
@@ -0,0 +1,751 @@
+/*
+ * Copyright (C) 2024 Gnattu OC <[email protected]>
+ *
Expand All @@ -259,6 +259,7 @@ Index: FFmpeg/libavfilter/vf_overlay_videotoolbox.m
+#include "metal/utils.h"
+#include "framesync.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_videotoolbox.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/objc.h"
Expand Down Expand Up @@ -888,6 +889,7 @@ Index: FFmpeg/libavfilter/vf_overlay_videotoolbox.m
+ output_frames->sw_format = main_frames->sw_format;
+ output_frames->width = inlink_main->w;
+ output_frames->height = inlink_main->h;
+ ((AVVTFramesContext *)output_frames->hwctx)->color_range = ((AVVTFramesContext *)main_frames->hwctx)->color_range;
+
+ ret = ff_filter_init_hw_frames(avctx, link, 1);
+ if (ret < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Index: FFmpeg/libavfilter/vf_transpose_vt.m
===================================================================
--- /dev/null
+++ FFmpeg/libavfilter/vf_transpose_vt.m
@@ -0,0 +1,381 @@
@@ -0,0 +1,383 @@
+/*
+ * Copyright (c) 2023 Zhao Zhili <[email protected]>
+ * Copyright (c) 2024 Gnattu OC <[email protected]>
Expand All @@ -331,6 +331,7 @@ Index: FFmpeg/libavfilter/vf_transpose_vt.m
+#include <VideoToolbox/VideoToolbox.h>
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_videotoolbox.h"
+#include "libavutil/opt.h"
+#include "libavutil/objc.h"
+#include "internal.h"
Expand Down Expand Up @@ -486,6 +487,7 @@ Index: FFmpeg/libavfilter/vf_transpose_vt.m
+ hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
+ hw_frame_ctx_out->width = outlink->w;
+ hw_frame_ctx_out->height = outlink->h;
+ ((AVVTFramesContext *)hw_frame_ctx_out->hwctx)->color_range = ((AVVTFramesContext *)hw_frame_ctx_in->hwctx)->color_range;
+
+ err = ff_filter_init_hw_frames(avctx, outlink, 1);
+ if (err < 0)
Expand Down
12 changes: 9 additions & 3 deletions debian/patches/0052-add-vf-tonemap-videotoolbox-filter.patch
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ Index: FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
===================================================================
--- /dev/null
+++ FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
@@ -0,0 +1,1148 @@
@@ -0,0 +1,1154 @@
+/*
+ * Copyright (c) 2024 Gnattu OC <[email protected]>
+ *
Expand Down Expand Up @@ -1711,6 +1711,12 @@ Index: FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
+ out_frames_ctx->width = outlink->w;
+ out_frames_ctx->height = outlink->h;
+
+ if (ctx->range != -1) {
+ ((AVVTFramesContext *)out_frames_ctx->hwctx)->color_range = ctx->range;
+ } else {
+ ((AVVTFramesContext *)out_frames_ctx->hwctx)->color_range = ((AVVTFramesContext *)in_frames_ctx->hwctx)->color_range;
+ }
+
+ ret = ff_filter_init_hw_frames(avctx, outlink, 1);
+ if (ret < 0)
+ return ret;
Expand Down Expand Up @@ -2040,8 +2046,8 @@ Index: FFmpeg/libavfilter/vf_tonemap_videotoolbox.m
+ { "p", "Set color primaries", OFFSET(primaries), AV_OPT_TYPE_INT, { .i64 = AVCOL_PRI_BT709 }, -1, INT_MAX, FLAGS, .unit = "primaries" },
+ { "bt709", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_PRI_BT709 }, 0, 0, FLAGS, .unit = "primaries" },
+ { "bt2020", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_PRI_BT2020 }, 0, 0, FLAGS, .unit = "primaries" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_MPEG }, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = AVCOL_RANGE_MPEG }, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "range", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "r", "Set color range", OFFSET(range), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS, .unit = "range" },
+ { "tv", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
+ { "pc", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
+ { "limited", 0, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
Expand Down

0 comments on commit a893486

Please sign in to comment.