aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-10-26 20:57:57 +0200
committerdec05eba <dec05eba@protonmail.com>2024-10-26 20:58:00 +0200
commit112640282d236587dff0fd09e5137bfbc4cfec06 (patch)
tree6eebc9f62bcfb0738d2967b76d2ccd1e42d5b6af /src/utils.c
parent5ffa725367244bf24121a50e60831a9ed0283288 (diff)
Add option to change output resolution (-s)
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index c28208d..bad16d9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -738,6 +738,8 @@ bool vaapi_copy_drm_planes_to_video_surface(AVCodecContext *video_codec_context,
.height = dest_size.y
};
+ const bool scaled = dest_size.x != source_size.x || dest_size.y != source_size.y;
+
// Copying a surface to another surface will automatically perform the color conversion. Thanks vaapi!
VAProcPipelineParameterBuffer params = {0};
params.surface = input_surface_id;
@@ -745,7 +747,7 @@ bool vaapi_copy_drm_planes_to_video_surface(AVCodecContext *video_codec_context,
params.surface_region = &source_region;
params.output_region = &output_region;
params.output_background_color = 0;
- params.filter_flags = VA_FRAME_PICTURE;
+ params.filter_flags = scaled ? (VA_FILTER_SCALING_HQ | VA_FILTER_INTERPOLATION_BILINEAR) : 0;
params.pipeline_flags = VA_PROC_PIPELINE_FAST;
params.input_color_properties.colour_primaries = 1;
@@ -877,3 +879,20 @@ bool vaapi_copy_egl_image_to_video_surface(gsr_egl *egl, EGLImage image, vec2i s
return success;
}
+
+vec2i scale_keep_aspect_ratio(vec2i from, vec2i to) {
+ if(from.x == 0 || from.y == 0)
+ return (vec2i){0, 0};
+
+ const double height_to_width_ratio = (double)from.y / (double)from.x;
+ from.x = to.x;
+ from.y = from.x * height_to_width_ratio;
+
+ if(from.y > to.y) {
+ const double width_height_ratio = (double)from.x / (double)from.y;
+ from.y = to.y;
+ from.x = from.y * width_height_ratio;
+ }
+
+ return from;
+}