[FFmpeg-devel] [PATCH] fftools/ffplay: Add option to scale down window to fit display

Adam Saponara as at php.net
Sun Dec 8 22:05:38 EET 2024


When enabled, the max width and height of the window will be
clamped to the size of the current display.

Signed-off-by: Adam Saponara <as at php.net>
---
 fftools/ffplay.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 2a572fc3aa..70ed445fb5 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -307,6 +307,7 @@ static const char *input_filename;
 static const char *window_title;
 static int default_width  = 640;
 static int default_height = 480;
+static int scale_down = 0;
 static int screen_width  = 0;
 static int screen_height = 0;
 static int screen_left = SDL_WINDOWPOS_CENTERED;
@@ -1333,10 +1334,24 @@ static void sigterm_handler(int sig)
 static void set_default_window_size(int width, int height, AVRational sar)
 {
     SDL_Rect rect;
+    SDL_DisplayMode dm;
+    int di;
+
     int max_width  = screen_width  ? screen_width  : INT_MAX;
     int max_height = screen_height ? screen_height : INT_MAX;
+
     if (max_width == INT_MAX && max_height == INT_MAX)
         max_height = height;
+
+    if (scale_down && window &&
+        (di = SDL_GetWindowDisplayIndex(window)) >= 0 &&
+        SDL_GetDesktopDisplayMode(di, &dm) == 0) {
+        if (max_width > dm.w)
+            max_width = dm.w;
+        if (max_height > dm.h)
+            max_height = dm.h;
+    }
+
     calculate_display_rect(&rect, 0, 0, max_width, max_height, width, height, sar);
     default_width  = rect.w;
     default_height = rect.h;
@@ -3666,6 +3681,7 @@ static const OptionDef options[] = {
     { "x",                  OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_width }, "force displayed width", "width" },
     { "y",                  OPT_TYPE_FUNC, OPT_FUNC_ARG, { .func_arg = opt_height }, "force displayed height", "height" },
     { "fs",                 OPT_TYPE_BOOL,            0, { &is_full_screen }, "force full screen" },
+    { "scale_down",         OPT_TYPE_BOOL,            0, { &scale_down }, "scale down width and height to fit display" },
     { "an",                 OPT_TYPE_BOOL,            0, { &audio_disable }, "disable audio" },
     { "vn",                 OPT_TYPE_BOOL,            0, { &video_disable }, "disable video" },
     { "sn",                 OPT_TYPE_BOOL,            0, { &subtitle_disable }, "disable subtitling" },
-- 
2.45.2



More information about the ffmpeg-devel mailing list