2020-02-05 18:57:20 -05:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GifRecorder.h"
|
|
|
|
#include "gif.h"
|
|
|
|
|
|
|
|
GifRecorder::GifRecorder()
|
|
|
|
{
|
|
|
|
_gif.reset(new GifWriter());
|
|
|
|
}
|
|
|
|
|
|
|
|
GifRecorder::~GifRecorder()
|
|
|
|
{
|
|
|
|
StopRecording();
|
|
|
|
}
|
|
|
|
|
2021-03-10 11:13:28 -05:00
|
|
|
bool GifRecorder::StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps)
|
2020-02-05 18:57:20 -05:00
|
|
|
{
|
|
|
|
_outputFile = filename;
|
|
|
|
_recording = GifBegin(_gif.get(), filename.c_str(), width, height, 2, 8, false);
|
|
|
|
_frameCounter = 0;
|
|
|
|
return _recording;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GifRecorder::StopRecording()
|
|
|
|
{
|
2021-03-10 11:13:28 -05:00
|
|
|
if(_recording) {
|
2020-02-05 18:57:20 -05:00
|
|
|
GifEnd(_gif.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GifRecorder::AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps)
|
|
|
|
{
|
|
|
|
_frameCounter++;
|
2021-03-10 11:13:28 -05:00
|
|
|
|
|
|
|
if(fps < 55 || (_frameCounter % 6) != 0) {
|
2020-02-05 18:57:20 -05:00
|
|
|
//At 60 FPS, skip 1 of every 6 frames (max FPS for GIFs is 50fps)
|
|
|
|
GifWriteFrame(_gif.get(), (uint8_t*)frameBuffer, width, height, 2, 8, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GifRecorder::AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GifRecorder::IsRecording()
|
|
|
|
{
|
|
|
|
return _recording;
|
|
|
|
}
|
|
|
|
|
|
|
|
string GifRecorder::GetOutputFile()
|
|
|
|
{
|
|
|
|
return _outputFile;
|
2021-03-10 11:13:28 -05:00
|
|
|
}
|