繁体   English   中英

如何将 DirectShow 视频播放器嵌入 SDL 窗口

[英]How to Embed DirectShow Video Player to SDL Window

我正在尝试在 SDL 窗口中使用 DirectShow 库播放视频文件,我使用Microsoft Docs提供的库,当我尝试单独构建它时工作正常,但 main.cpp 中的代码需要在HWND创建一个单独的窗口工作,我想在现有的 SDL_Window 中使用它。

main.cpp 中的代码

HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"DirectShow Playback", 
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

我的代码

SDL_SysWMinfo info; 
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(g_window, &info);
HWND hwnd = GetWindow(info.info.win.window, GWL_WNDPROC);

我已经有SDL_Window* g_windowSDL_Renderer* g_rendererSDL_Thread* video_tid但似乎不适用于HWND hwnd

另外,如果我成功了,那么我将更改ShowWindow(hwnd, nCmdShow); ?

这里是完整的代码:

TUserFunc(void, PlayVideo, HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow, bool testvideo)
{
    // Register the window class.
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";
    
    WNDCLASS wc = { };
    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

       SDL_SysWMinfo info; 
       SDL_VERSION(&info.version);
       SDL_GetWindowWMInfo(g_window, &info);
       HWND hwnd = GetWindow(info.info.win.window, GWL_WNDPROC);

    if (hwnd == NULL)
    {
        NotifyError(NULL, L"CreateWindowEx failed.");
    }

    ShowWindow(hwnd, nCmdShow);

    // Run the message loop.

    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

PD:当我使用 main.cpp 的 HWND hwnd 时,视频播放但在隐藏窗口中,SDL 窗口保持完全冻结

DirectShow 视频渲染器支持所谓的“无窗口模式”,您可以使用它:

使用无窗口模式

无窗口模式通过让 VMR 直接在应用程序窗口的客户区上绘制,使用 DirectDraw 来剪辑视频矩形,从而避免了这些问题。

旧的 Windows SDK提供了相关的示例(例如vmr9/windowless )。

在旧的Windows SDK是一个名为样本的过场动画,结合与put_WindowStyle(WS_CHILD)无边距并将其绑定到SDL窗口完美的作品,谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM