2 Replies Latest reply on Jul 30, 2016 5:24 AM by xaymar

    Properly submitting NV12 input frames? (VCE Encoding)

    xaymar

      Hi, I've been trying to get actual VCE support (not one through WMF) into OBS Studio, but so far have failed to use CreateSurfaceFromHostNative and SubmitInput. I am not sure what parameters to give it when the input is not just one Plane, but multiple. Do I have to implement it myself in those cases?

       

      Memory Type is Host in case that matters, so there's no InitOpenGL, InitDX9 or InitDX11 anywhere.

       

      My current code looks like this:

      // Submit all Planes
        switch (s_surfaceFormat) {
        case amf::AMF_SURFACE_RGBA:
        // RGBA, Single Plane
        switch (s_memoryType) {
        case amf::AMF_MEMORY_DX11: // Not yet Implemented in OBS
        break;
        case amf::AMF_MEMORY_OPENGL: // Not yet Implemented in OBS
        break;
        default: // Host: RAM.
        res = amf_context->CreateSurfaceFromHostNative(s_surfaceFormat, s_Width, s_Height, frame->linesize[0], 0, frame->data[0], &surfaceIn, &amf_surfaceObserver);
        }
        break;
        case amf::AMF_SURFACE_NV12:
        // Y:U+V, Two Plane
        switch (s_memoryType) {
        case amf::AMF_MEMORY_DX11: // Not yet Implemented in OBS
        break;
        case amf::AMF_MEMORY_OPENGL: // Not yet Implemented in OBS
        break;
        default: // Host: RAM.
        res = amf_context->CreateSurfaceFromHostNative(s_surfaceFormat, s_Width, s_Height, frame->linesize[0], 2, frame->data[0], &surfaceIn, &amf_surfaceObserver);
        }
        }
      
      
        if (res != AMF_OK) {
        const wchar_t* errormsg = amf::AMFGetResultText(res);
        char* outbuf = new char[1024];
        wcstombs(outbuf, errormsg, 1024);
        AMF_LOG_ERROR("Encode: Failed to copy to AMF Surface, error code %d: %s.", res, outbuf);
        delete outbuf;
        return false;
        }
        AMF_LOG_INFO("Encode: Input copied to AMF Surface.");
      
      
        surfaceIn->SetPts(frame->pts);
      
      
        AMF_LOG_INFO("Encode: Submitting Surface to Encoder...");
        try {
        res = amf_encoder->SubmitInput(surfaceIn);
        } catch (...) {
        AMF_LOG_ERROR("Encode: Unknown Exception occured.");
        }
      

      (Copy-Pasting Tabs doesn't work, it seems. See the original Source here: OBS-AMD-Media-Framework/amf-h264.cpp)