Plugin + Third Party Lib = AccessViolation

Hi,

okay i have a UE 4.7 Plugin (not tested it for 4.8 yet) which uses the ffmpeg lib to record the current screen to HDD. I tried the UE4 binary and the source version with different self-build ffmpeg libs.

Some more details: Win 8.1, x64 Build for Windows, latest stable ffmpeg release (also tried some older versions)

The frames are meant to be captured by the plugin via ILiveStreamingService functionality:

void PushVideoFrame( const FColor* VideoFrameBuffer ) { ... }

But i tried some other different approaches too, e.g. capturing slate backbuffers manually:

uint8_t* FVideoExportStream::GrabFrame()
{
	FSlateRenderer* SlateRenderer = FSlateApplicationBase::Get().GetRenderer().Get();
	uint8_t* buffer = (uint8_t*)ReadbackBuffers[ReadbackBufferIndex];
	if (ReadbackBuffers[ReadbackBufferIndex] != nullptr)
	{
		SlateRenderer->UnmapVirtualScreenBuffer();
	}

	TArray<FString> UnusedKeypressBuffer;
	SlateRenderer->CopyWindowsToVirtualScreenBuffer(UnusedKeypressBuffer);
	SlateRenderer->MapVirtualScreenBuffer(&ReadbackBuffers[ReadbackBufferIndex]);

	// Ping pong between buffers
	ReadbackBufferIndex = (ReadbackBufferIndex + 1) % 2;
	return buffer;
}

There is an extra thread for encoding and recording (video and audio). The problem may lie on ffmpeg side, as far as i can say it. But maybe someone has done somthing compareable/related and can help. I have an access violation when i write the encoded frame to file:

// Write the compressed frame to the media file.
ret = av_interleaved_write_frame(oc, &pkt); // Here the access violation happens

Console log: Unhandled exception at 0x000000006AE999FE (avformat-56.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000070.

I have done something similar successfully with OpenCV (which cannot record audio, that is why i use ffmpeg), and had no problem writing to file. In fact, the file is created, but not filled with data; due to the access violation…

I hope that some UE engine or graphics dev can point me to the error or a potential solution. If you need some additional infos, just say it.

Thanks in advance,
Hans