]> git.sesse.net Git - ffmpeg/commitdiff
avdevice/sdl2: add option to set window position
authorDave Rice <dave@dericed.com>
Mon, 1 Oct 2018 21:17:24 +0000 (17:17 -0400)
committerMarton Balint <cus@passwd.hu>
Tue, 23 Oct 2018 17:42:32 +0000 (19:42 +0200)
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

Some changes by Marton Balint:
- allow negative position (partially or fully out-of-screen positions seem to
  be sanitized automatically by SDL (or my WM?), so no special handling is
  needed)
- only show window after the position is set
- do not use resizable and borderless flags at the same time, that caused
  issues in ffplay
- add docs

Signed-off-by: Marton Balint <cus@passwd.hu>
doc/outdevs.texi
libavdevice/sdl2.c
libavdevice/version.h

index 2518f9b55950edf09b87dd01aed1e3c6466b115a..7509ac695db2723cacd6d9479219de255dc3955d 100644 (file)
@@ -398,6 +398,10 @@ Set the SDL window size, can be a string of the form
 If not specified it defaults to the size of the input video,
 downscaled according to the aspect ratio.
 
+@item window_x
+@item window_y
+Set the position of the window on the screen.
+
 @item window_fullscreen
 Set fullscreen mode when non-zero value is provided.
 Default value is zero.
index da5143078eef8b5d3121dd533d40e91d4e325eba..d6fc74a66c7650098c1f90e890235d95e4bb33d1 100644 (file)
@@ -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;
@@ -155,8 +156,6 @@ static int sdl2_write_trailer(AVFormatContext *s)
     return 0;
 }
 
-#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_WINDOW_RESIZABLE)
-
 static int sdl2_write_header(AVFormatContext *s)
 {
     SDLContext *sdl = s->priv_data;
@@ -196,8 +195,9 @@ static int sdl2_write_header(AVFormatContext *s)
     }
 
     /* resize texture to width and height from the codec context information */
-    flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
-                             (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : 0);
+    flags = SDL_WINDOW_HIDDEN |
+            (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
+            (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : SDL_WINDOW_RESIZABLE);
 
     /* initialization */
     if (!sdl->inited){
@@ -216,6 +216,8 @@ static int sdl2_write_header(AVFormatContext *s)
     }
 
     SDL_SetWindowTitle(sdl->window, sdl->window_title);
+    SDL_SetWindowPosition(sdl->window, sdl->window_x, sdl->window_y);
+    SDL_ShowWindow(sdl->window);
 
     sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING,
                                      codecpar->width, codecpar->height);
@@ -337,6 +339,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 = SDL_WINDOWPOS_CENTERED }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+    { "window_y",          "set SDL window y position",  OFFSET(window_y),     AV_OPT_TYPE_INT,        { .i64 = SDL_WINDOWPOS_CENTERED }, INT_MIN, 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 },
index e6ee009cc45545760d0e099f8812c37988ce85df..c35c98aedbf7cc57b70f16fbfcf2dadfc8459ca1 100644 (file)
@@ -29,7 +29,7 @@
 
 #define LIBAVDEVICE_VERSION_MAJOR  58
 #define LIBAVDEVICE_VERSION_MINOR   4
-#define LIBAVDEVICE_VERSION_MICRO 105
+#define LIBAVDEVICE_VERSION_MICRO 106
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \