[FFmpeg-devel] [PATCH v2 4/8] avfilter/vf_scale*: strip metadata on size change

Niklas Haas ffmpeg at haasn.xyz
Wed Dec 4 16:51:05 EET 2024


From: Niklas Haas <git at haasn.dev>

---
 libavfilter/vf_scale.c        | 2 ++
 libavfilter/vf_scale_cuda.c   | 3 +++
 libavfilter/vf_scale_npp.c    | 3 +++
 libavfilter/vf_scale_vaapi.c  | 3 +++
 libavfilter/vf_scale_vt.c     | 2 ++
 libavfilter/vf_scale_vulkan.c | 3 +++
 6 files changed, 16 insertions(+)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index d86e50f79b..9a396f1fd3 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -832,6 +832,8 @@ scale:
     out->colorspace = outlink->colorspace;
     if (scale->out_chroma_loc != AVCHROMA_LOC_UNSPECIFIED)
         out->chroma_location = scale->out_chroma_loc;
+    if (out->width != in->width || out->height != in->height)
+        av_frame_remove_side_data_by_props(out, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
 
     av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
               (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
diff --git a/libavfilter/vf_scale_cuda.c b/libavfilter/vf_scale_cuda.c
index eb8beee771..5dafbe4824 100644
--- a/libavfilter/vf_scale_cuda.c
+++ b/libavfilter/vf_scale_cuda.c
@@ -536,6 +536,9 @@ static int cudascale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
     if (ret < 0)
         return ret;
 
+    if (out->width != in->width || out->height != in->height)
+        av_frame_remove_side_data_by_props(out, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
+
     return 0;
 }
 
diff --git a/libavfilter/vf_scale_npp.c b/libavfilter/vf_scale_npp.c
index 0c38987687..214cd0ad8e 100644
--- a/libavfilter/vf_scale_npp.c
+++ b/libavfilter/vf_scale_npp.c
@@ -897,6 +897,9 @@ scale:
     if (ret < 0)
         return ret;
 
+    if (out->width != in->width || out->height != in->height)
+        av_frame_remove_side_data_by_props(out, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
+
     return 0;
 }
 
diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index 65db05c23d..a6a9e9f507 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -137,6 +137,9 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
     if (err < 0)
         goto fail;
 
+    if (output_frame->width != input_frame->width || output_frame->height != input_frame->height)
+        av_frame_remove_side_data_by_props(output_frame, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
+
     if (ctx->colour_primaries != AVCOL_PRI_UNSPECIFIED)
         output_frame->color_primaries = ctx->colour_primaries;
     if (ctx->colour_transfer != AVCOL_TRC_UNSPECIFIED)
diff --git a/libavfilter/vf_scale_vt.c b/libavfilter/vf_scale_vt.c
index eff23a6f39..004fc9ace8 100644
--- a/libavfilter/vf_scale_vt.c
+++ b/libavfilter/vf_scale_vt.c
@@ -160,6 +160,8 @@ static int scale_vt_filter_frame(AVFilterLink *link, AVFrame *in)
     out->crop_top = 0;
     out->crop_right = 0;
     out->crop_bottom = 0;
+    if (out->width != in->width || out->height != in->height)
+        av_frame_remove_side_data_by_props(out, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
 
     av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
               (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
diff --git a/libavfilter/vf_scale_vulkan.c b/libavfilter/vf_scale_vulkan.c
index d675a309a8..9f621b26d0 100644
--- a/libavfilter/vf_scale_vulkan.c
+++ b/libavfilter/vf_scale_vulkan.c
@@ -287,6 +287,9 @@ static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
     if (err < 0)
         goto fail;
 
+    if (out->width != in->width || out->height != in->height)
+        av_frame_remove_side_data_by_props(out, AV_SIDE_DATA_PROP_SIZE_DEPENDENT);
+
     if (s->out_range != AVCOL_RANGE_UNSPECIFIED)
         out->color_range = s->out_range;
     if (s->vkctx.output_format != s->vkctx.input_format)
-- 
2.47.0



More information about the ffmpeg-devel mailing list