说明
MINIGUI环境 + FFMPEG: 实现视频播放, 但是调整 MAIN_WINDOWS 位置无法实现将视频播放窗口一并调整, 查看源码发现
VideoState *is;
is->ytop = 0;
is->xleft = 0;
calculate_display_rect(&rect, is->xleft, is->ytop, is->width, is->height, vp->width, vp->height, vp->sar);
由此可以看出, FFPlay 的视频播放窗口是从 (0, 0) 开始的, 所以我们添加代码, 修改这两参数, 即可实现视频窗口位置偏移.
修改代码
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
old mode 100644
new mode 100755
index dcca9c2..d057c7c
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -60,6 +60,8 @@
#include <assert.h>
+#define SUPPORT_WINDOWS_OFFSET
+
const char program_name[] = "ffplay";
const int program_birth_year = 2003;
@@ -314,6 +316,10 @@ static int default_width = 640;
static int default_height = 480;
static int screen_width = 0;
static int screen_height = 0;
+#ifdef SUPPORT_WINDOWS_OFFSET
+static int screen_xleft = 0;
+static int screen_ytop = 0;
+#endif
static int audio_disable;
static int video_disable;
static int subtitle_disable;
@@ -1313,7 +1319,7 @@ static void set_default_window_size(int width, int height, AVRational sar)
static int video_open(VideoState *is)
{
int w,h;
-
+
if (screen_width) {
w = screen_width;
h = screen_height;
@@ -1334,6 +1340,16 @@ static int video_open(VideoState *is)
is->width = w;
is->height = h;
+
+#ifdef SUPPORT_WINDOWS_OFFSET
+ if (screen_xleft)
+ is->xleft = screen_xleft;
+
+ if (screen_ytop)
+ is->ytop = screen_ytop;
+
+ av_log(NULL, AV_LOG_ERROR, "xleft:%d, ytop:%d \n", is->xleft, is->ytop);
+#endif
return 0;
}
@@ -3459,6 +3475,21 @@ static int opt_height(void *optctx, const char *opt, const char *arg)
return 0;
}
+#ifdef SUPPORT_WINDOWS_OFFSET
+static int opt_xleft(void *optctx, const char *opt, const char *arg)
+{
+ screen_xleft = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ av_log(NULL, AV_LOG_ERROR, "screen_xleft: %d\n", screen_xleft);
+ return 0;
+}
+
+static int opt_ytop(void *optctx, const char *opt, const char *arg)
+{
+ screen_ytop = parse_number_or_die(opt, arg, OPT_INT64, 1, INT_MAX);
+ av_log(NULL, AV_LOG_ERROR, "screen_ytop: %d\n", screen_ytop);
+ return 0;
+}
+#endif
static int opt_format(void *optctx, const char *opt, const char *arg)
{
file_iformat = av_find_input_format(arg);
@@ -3552,6 +3583,10 @@ static const OptionDef options[] = {
CMDUTILS_COMMON_OPTIONS
{ "x", HAS_ARG, { .func_arg = opt_width }, "force displayed width", "width" },
{ "y", HAS_ARG, { .func_arg = opt_height }, "force displayed height", "height" },
+#ifdef SUPPORT_WINDOWS_OFFSET
+ { "xoff", HAS_ARG, { .func_arg = opt_xleft}, "force displayed x offset", "xoffset" },
+ { "yoff", HAS_ARG, { .func_arg = opt_ytop }, "force displayed y offset", "yoffset" },
+#endif
{ "s", HAS_ARG | OPT_VIDEO, { .func_arg = opt_frame_size }, "set frame size (WxH or abbreviation)", "size" },
{ "fs", OPT_BOOL, { &is_full_screen }, "force full screen" },
{ "an", OPT_BOOL, { &audio_disable }, "disable audio" },