Blackmagic SDK - OpenGL Letterbox和FFMPEG

时间:2015-03-17 16:31:08

标签: c++ opengl ffmpeg video-capture video-recording

因此,由于缺乏对所需视频格式的支持,我使用DirectShow过滤器离开了我的想法。 本机API使用OpenGL,我是初学者。 我偶然发现了以下问题:

  1. 如何根据传递给OpenGL的Frame的宽度和高度自动应用信箱或邮箱(我使用bpctrlanchormap.h自动调整所有内容并获得挤压/拉伸图像)

  2. 如何录制OpenGL流的视频(我环顾四周,看到ffmpeg应该可以这样做,但我无法让它运行。)还有什么好听的是录音到同一个麦克风文件

  3. 我正在使用Blackmagic“Capture Preview”样本。

    这是初始化OpenGL渲染器并传递帧

    的源代码
    #include "stdafx.h"
    #include <gl/gl.h>
    #include "PreviewWindow.h"
    
    PreviewWindow::PreviewWindow()
    : m_deckLinkScreenPreviewHelper(NULL), m_refCount(1), m_previewBox(NULL), m_previewBoxDC(NULL), m_openGLctx(NULL)
    {}
    
    PreviewWindow::~PreviewWindow()
    {
        if (m_deckLinkScreenPreviewHelper != NULL)
        {
            m_deckLinkScreenPreviewHelper->Release();
            m_deckLinkScreenPreviewHelper = NULL;
        }
    
        if (m_openGLctx != NULL)
        {
            wglDeleteContext(m_openGLctx);
            m_openGLctx = NULL;
        }
    
        if (m_previewBoxDC != NULL)
        {
            m_previewBox->ReleaseDC(m_previewBoxDC);
            m_previewBoxDC = NULL;
        }
    }
    
    bool        PreviewWindow::init(CStatic *previewBox)
    {
        m_previewBox = previewBox;
    
        // Create the DeckLink screen preview helper
        if (CoCreateInstance(CLSID_CDeckLinkGLScreenPreviewHelper, NULL, CLSCTX_ALL, IID_IDeckLinkGLScreenPreviewHelper (void**)&m_deckLinkScreenPreviewHelper) != S_OK)
        return false;
    
        // Initialise OpenGL
        return initOpenGL();
    }
    
    bool        PreviewWindow::initOpenGL()
    {
        PIXELFORMATDESCRIPTOR   pixelFormatDesc;
        int                     pixelFormat;
        bool                    result = false;
    
        //
        // Here, we create an OpenGL context attached to the screen preview box
        // so we can use it later on when we need to draw preview frames.
    
        // Get the preview box drawing context
        m_previewBoxDC = m_previewBox->GetDC();
        if (m_previewBoxDC == NULL)
            return false;
    
        // Ensure the preview box DC uses ARGB pixel format
        ZeroMemory(&pixelFormatDesc, sizeof(pixelFormatDesc));
        pixelFormatDesc.nSize = sizeof(pixelFormatDesc);
        pixelFormatDesc.nVersion = 1;
        pixelFormatDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
        pixelFormatDesc.iPixelType = PFD_TYPE_RGBA;
        pixelFormatDesc.cColorBits = 32;
        pixelFormatDesc.cDepthBits = 16;
        pixelFormatDesc.cAlphaBits = 8;
        pixelFormatDesc.iLayerType = PFD_MAIN_PLANE;
        pixelFormat = ChoosePixelFormat(m_previewBoxDC->m_hDC, &pixelFormatDesc);
        if (SetPixelFormat(m_previewBoxDC->m_hDC, pixelFormat, &pixelFormatDesc) == false)
            return false;
    
        // Create OpenGL rendering context
        m_openGLctx = wglCreateContext(m_previewBoxDC->m_hDC);
        if (m_openGLctx == NULL)
            return false;
        // Make the new OpenGL context the current rendering context so
        // we can initialise the DeckLink preview helper
        if (wglMakeCurrent(m_previewBoxDC->m_hDC, m_openGLctx) == FALSE)
            return false;
    
        if (m_deckLinkScreenPreviewHelper->InitializeGL() == S_OK)
            result = true;
    
        // Reset the OpenGL rendering context
        wglMakeCurrent(NULL, NULL);
    
        return result;
    }
    
    HRESULT         PreviewWindow::DrawFrame(IDeckLinkVideoFrame* theFrame)
    {
        // Make sure we are initialised
        if ((m_deckLinkScreenPreviewHelper == NULL) || (m_previewBoxDC == NULL) || (m_openGLctx == NULL))
            return E_FAIL;
    
        // First, pass the frame to the DeckLink screen preview helper
        m_deckLinkScreenPreviewHelper->SetFrame(theFrame);
    
        // Then set the OpenGL rendering context to the one we created before
        wglMakeCurrent(m_previewBoxDC->m_hDC, m_openGLctx);
    
        // and let the helper take care of the drawing
        m_deckLinkScreenPreviewHelper->PaintGL();
    
        // Last, reset the OpenGL rendering context
        wglMakeCurrent(NULL, NULL);
    
        return S_OK;
    }
    

0 个答案:

没有答案