diff mbox

[FFmpeg-devel,2/2] avdevice/sdl2 : add option to set window position

Message ID C1D3C069-6F10-4A79-875C-26E1AFB6C1A4@dericed.com
State New
Headers show

Commit Message

Dave Rice Oct. 1, 2018, 9:17 p.m. UTC
Allows arrangement of multiple windows such as:
ffmpeg -re -f lavfi -i mandelbrot -f sdl -window_x 1 -window_y 1 mandelbrot -vf waveform,format=yuv420p -f sdl -window_x 641 -window_y 1 waveform -vf vectorscope,format=yuv420p -f sdl -window_x 1 -window_y 481 vectorscop

From 00438983c96b5db227b9975a2c160fc6aac5219d Mon Sep 17 00:00:00 2001
From: Dave Rice <dave@dericed.com>
Date: Mon, 1 Oct 2018 17:08:35 -0400
Subject: [PATCH 2/2] avdevice/sdl2 : add option to set window position

---
 libavdevice/sdl2.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Gyan Oct. 2, 2018, 5:32 a.m. UTC | #1
On Tue, Oct 2, 2018 at 2:47 AM Dave Rice <dave@dericed.com> wrote:

> Allows arrangement of multiple windows such as:
> ffmpeg -re -f lavfi -i mandelbrot -f sdl -window_x 1 -window_y 1
> mandelbrot -vf waveform,format=yuv420p -f sdl -window_x 641 -window_y 1
> waveform -vf vectorscope,format=yuv420p -f sdl -window_x 1 -window_y 481
> vectorscop
>
> From 00438983c96b5db227b9975a2c160fc6aac5219d Mon Sep 17 00:00:00 2001
> From: Dave Rice <dave@dericed.com>
> Date: Mon, 1 Oct 2018 17:08:35 -0400
> Subject: [PATCH 2/2] avdevice/sdl2 : add option to set window position
>
> +    if (!sdl->window_x)
> +        sdl->window_x = SDL_WINDOWPOS_CENTERED;
> +    if (!sdl->window_y)
> +        sdl->window_y = SDL_WINDOWPOS_CENTERED;
> +    SDL_SetWindowPosition(sdl->window, sdl->window_x, sdl->window_y);
>

What happens if the user value implies fully or partially out-of-canvas
rendering?

For the former case, we may want to print a warning and reposition the
window.
If a partial window is drawable, then negative values can be valid and the
lower range bound should be INT_MIN
Also, the user can't position a window at top-left (0,0), so the default
should probably be INT_MAX.

Gyan
Dave Rice Oct. 3, 2018, 9:03 p.m. UTC | #2
> On Oct 2, 2018, at 1:32 AM, Gyan <gyandoshi@gmail.com> wrote:
> 
> On Tue, Oct 2, 2018 at 2:47 AM Dave Rice <dave@dericed.com> wrote:
> 
>> Allows arrangement of multiple windows such as:
>> ffmpeg -re -f lavfi -i mandelbrot -f sdl -window_x 1 -window_y 1
>> mandelbrot -vf waveform,format=yuv420p -f sdl -window_x 641 -window_y 1
>> waveform -vf vectorscope,format=yuv420p -f sdl -window_x 1 -window_y 481
>> vectorscop
>> 
>> From 00438983c96b5db227b9975a2c160fc6aac5219d Mon Sep 17 00:00:00 2001
>> From: Dave Rice <dave@dericed.com>
>> Date: Mon, 1 Oct 2018 17:08:35 -0400
>> Subject: [PATCH 2/2] avdevice/sdl2 : add option to set window position
>> 
>> +    if (!sdl->window_x)
>> +        sdl->window_x = SDL_WINDOWPOS_CENTERED;
>> +    if (!sdl->window_y)
>> +        sdl->window_y = SDL_WINDOWPOS_CENTERED;
>> +    SDL_SetWindowPosition(sdl->window, sdl->window_x, sdl->window_y);
>> 
> 
> What happens if the user value implies fully or partially out-of-canvas
> rendering?

I attempted to add an error message but am uncertain how to access the width and height of the canvas used. Any advice?

> For the former case, we may want to print a warning and reposition the
> window.
> If a partial window is drawable, then negative values can be valid and the
> lower range bound should be INT_MIN
> Also, the user can't position a window at top-left (0,0), so the default
> should probably be INT_MAX.
> 
> Gyan
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Gyan Oct. 8, 2018, 4:42 a.m. UTC | #3
On Thu, Oct 4, 2018 at 2:33 AM Dave Rice <dave@dericed.com> wrote:

>
>
> I attempted to add an error message but am uncertain how to access the
> width and height of the canvas used. Any advice?
>

I believe you need to call SDL_GetCurrentDisplayMode.

See https://wiki.libsdl.org/SDL_GetCurrentDisplayMode

Gyan
diff mbox

Patch

diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index da5143078e..69c541da23 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -40,6 +40,7 @@  typedef struct {
     SDL_Renderer *renderer;
     char *window_title;
     int window_width, window_height;  /**< size of the window */
+    int window_x, window_y;           /**< position of the window */
     int window_fullscreen;
     int window_borderless;
     int enable_quit_action;
@@ -217,6 +218,12 @@  static int sdl2_write_header(AVFormatContext *s)
 
     SDL_SetWindowTitle(sdl->window, sdl->window_title);
 
+    if (!sdl->window_x)
+        sdl->window_x = SDL_WINDOWPOS_CENTERED;
+    if (!sdl->window_y)
+        sdl->window_y = SDL_WINDOWPOS_CENTERED;
+    SDL_SetWindowPosition(sdl->window, sdl->window_x, sdl->window_y);
+
     sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING,
                                      codecpar->width, codecpar->height);
 
@@ -337,6 +344,8 @@  static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt)
 static const AVOption options[] = {
     { "window_title",      "set SDL window title",       OFFSET(window_title), AV_OPT_TYPE_STRING,     { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_size",       "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
+    { "window_x",          "set SDL window x position",  OFFSET(window_x),     AV_OPT_TYPE_INT,        { .i64 = 0 },    0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+    { "window_y",          "set SDL window y position",  OFFSET(window_y),     AV_OPT_TYPE_INT,        { .i64 = 0 },    0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_fullscreen", "set SDL window fullscreen",  OFFSET(window_fullscreen), AV_OPT_TYPE_BOOL,  { .i64 = 0 },    0, 1, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_borderless", "set SDL window border off",  OFFSET(window_borderless), AV_OPT_TYPE_BOOL,  { .i64 = 0 },    0, 1, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_enable_quit", "set if quit action is available", OFFSET(enable_quit_action), AV_OPT_TYPE_INT, {.i64=1},   0, 1, AV_OPT_FLAG_ENCODING_PARAM },