cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

xaymar
Adept I

Properly submitting NV12 input frames? (VCE Encoding)

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)

0 Likes
2 Replies
xaymar
Adept I

I got it to "work" now, the output is still wrong, but it seems to at least be visible now. I have one question though, what does AMF_REPEAT mean and why is it returned? Does it mean that it needs more data to encode? What do I do if I get AMF_REPEAT, but SubmitInput returns AMF_INPUT_FULL?

0 Likes
xaymar
Adept I

To Issue 1:

Turns out that the HPitch and VPitch of the AMF Surface is slightly larger than the actual needed area. This caused distortions and crashes in my original code. Solution: copy line by line and calculate the offset yourself.

To Issue 2:

Solved itself after Issue 1 was resolved.

0 Likes