2019-03-13 09:42:39 -04:00
|
|
|
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
|
2019-02-27 11:57:17 -05:00
|
|
|
|
|
|
|
|
#include "BaseVideoEncoder.h"
|
|
|
|
|
|
|
|
|
|
GAMEPLAYMEDIAENCODER_START
|
|
|
|
|
|
|
|
|
|
FBaseVideoEncoder::FBaseVideoEncoder(const FOutputSampleCallback& OutputCallback)
|
|
|
|
|
: OutputCallback(OutputCallback)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FBaseVideoEncoder::GetOutputType(TRefCountPtr<IMFMediaType>& OutType)
|
|
|
|
|
{
|
|
|
|
|
OutType = OutputType;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FBaseVideoEncoder::Initialize(const FVideoEncoderConfig& InConfig)
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(GameplayMediaEncoder, Log, TEXT("VideoEncoder config: %dx%d, %d FPS, %.2f Mbps"), InConfig.Width, InConfig.Height, InConfig.Framerate, InConfig.Bitrate / 1000000.0f);
|
|
|
|
|
|
|
|
|
|
CHECK_HR(MFCreateMediaType(OutputType.GetInitReference()));
|
|
|
|
|
CHECK_HR(OutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
|
|
|
|
|
CHECK_HR(OutputType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264));
|
|
|
|
|
CHECK_HR(OutputType->SetUINT32(MF_MT_AVG_BITRATE, InConfig.Bitrate));
|
|
|
|
|
CHECK_HR(MFSetAttributeRatio(OutputType, MF_MT_FRAME_RATE, InConfig.Framerate, 1));
|
|
|
|
|
CHECK_HR(MFSetAttributeSize(OutputType, MF_MT_FRAME_SIZE, InConfig.Width, InConfig.Height));
|
|
|
|
|
CHECK_HR(MFSetAttributeRatio(OutputType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
|
|
|
|
|
CHECK_HR(OutputType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
|
|
|
|
|
Config = InConfig;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FBaseVideoEncoder::SetBitrate(uint32 Bitrate)
|
|
|
|
|
{
|
|
|
|
|
check(IsInRenderingThread()); // encoders apply these changes immediately and not thread-safely
|
|
|
|
|
|
|
|
|
|
CHECK_HR(OutputType->SetUINT32(MF_MT_AVG_BITRATE, Bitrate));
|
|
|
|
|
Config.Bitrate = Bitrate;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FBaseVideoEncoder::SetFramerate(uint32 Framerate)
|
|
|
|
|
{
|
|
|
|
|
check(IsInRenderingThread()); // encoders apply these changes immediately and not thread-safely
|
|
|
|
|
|
|
|
|
|
CHECK_HR(MFSetAttributeRatio(OutputType, MF_MT_FRAME_RATE, Framerate, 1));
|
|
|
|
|
Config.Framerate = Framerate;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GAMEPLAYMEDIAENCODER_END
|
|
|
|
|
|