implement aligned memory to speed up video frame encoding

This commit is contained in:
2019-11-13 23:27:32 +01:00
parent b719e4c7fc
commit 56fc581b04
8 changed files with 108 additions and 5 deletions

View File

@@ -1,11 +1,13 @@
#include "pch.h"
#include "mp4enc.h"
#include "util.h"
#include <codec_api.h>
#include <libyuv.h>
#define MP4V2_NO_STDINT_DEFS
#include <mp4v2/mp4v2.h>
#include "shader.h"
static void encoder_trace_callback(void* context, int level, const char* message)
{
@@ -105,13 +107,23 @@ bool MP4Encoder::encode(const Image& rgba) noexcept
if (rgba.width != m_width || rgba.height != m_height)
{
Image resized = rgba.resize(m_width, m_height);
//libyuv::ARGBScale
libyuv::ABGRToI420(resized.data(), resized.width * 4, pic.pData[0], m_width,
pic.pData[1], m_width / 2, pic.pData[2], m_width / 2, m_width, m_height);
}
else
{
libyuv::ABGRToI420(rgba.data(), rgba.width * 4, pic.pData[0], m_width,
pic.pData[1], m_width / 2, pic.pData[2], m_width / 2, m_width, m_height);
if (((uintptr_t)rgba.data() & 0xFF) != 0)
{
std::vector<uint8_t, AlignmentAllocator<uint8_t, 16>> aligned_buffer(rgba.data(), rgba.data() + (size_t)rgba.size());
libyuv::ABGRToI420(aligned_buffer.data(), rgba.width * 4, pic.pData[0], m_width,
pic.pData[1], m_width / 2, pic.pData[2], m_width / 2, m_width, m_height);
}
else
{
libyuv::ABGRToI420(rgba.data(), rgba.width * 4, pic.pData[0], m_width,
pic.pData[1], m_width / 2, pic.pData[2], m_width / 2, m_width, m_height);
}
}
if (m_encoder->EncodeFrame(&pic, &info))