实现效果如下:
当前 再播放按钮下添加一个窗口, 点击播放, 此时 ffplay播放视频显示在 特定窗口上.
主要是修改了 ffplay源码添加了一个参数接收 窗口句柄
ffplay.exe -i "D:\left\tz_g.mp4" -window_host 527658 -autoexit
实现原理就是ffplay 创建窗口方式 使用API :
window = SDL_CreateWindowFrom(window_host_handle);
具体内容可以参考如下dif:
code/FFmpeg/fftools/ffplay.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/code/FFmpeg/fftools/ffplay.c b/code/FFmpeg/fftools/ffplay.c
index 6a195e55..894dee8f 100644
--- a/code/FFmpeg/fftools/ffplay.c
+++ b/code/FFmpeg/fftools/ffplay.c
@@ -310,6 +310,7 @@ typedef struct VideoState {
static AVInputFormat *file_iformat;
static const char *input_filename;
static const char *window_title;
+static int window_host_handle = 0; // host 窗口句柄
static int default_width = 640;
static int default_height = 480;
static int screen_width = 0;
@@ -3599,6 +3600,7 @@ static const OptionDef options[] = {
{ "framedrop", OPT_BOOL | OPT_EXPERT, { &framedrop }, "drop frames when cpu is too slow", "" },
{ "infbuf", OPT_BOOL | OPT_EXPERT, { &infinite_buffer }, "don't limit the input buffer size (useful with realtime streams)", "" },
{ "window_title", OPT_STRING | HAS_ARG, { &window_title }, "set window title", "window title" },
+ { "window_host", OPT_INT | HAS_ARG, { &window_host_handle }, "set window host handle", "window handle" },
{ "left", OPT_INT | HAS_ARG | OPT_EXPERT, { &screen_left }, "set the x position for the left of the window", "x pos" },
{ "top", OPT_INT | HAS_ARG | OPT_EXPERT, { &screen_top }, "set the y position for the top of the window", "y pos" },
#if CONFIG_AVFILTER
@@ -3727,7 +3729,14 @@ int main(int argc, char **argv)
flags |= SDL_WINDOW_BORDERLESS;
else
flags |= SDL_WINDOW_RESIZABLE;
- window = SDL_CreateWindow(program_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, default_width, default_height, flags);
+
+ if (window_host_handle != 0) {
+ window = SDL_CreateWindowFrom(window_host_handle);
+ SDL_HideWindow(window);
+ } else {
+ window = SDL_CreateWindow(program_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, default_width, default_height, flags);
+ }
+
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
if (window) {
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);