Media ffmpeg/ffplay - 支持视频窗口位置偏移

Media ffmpeg/ffplay - 支持视频窗口位置偏移

说明

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" },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值