add MP4Encoder class and test timelapse exporting

This commit is contained in:
2019-10-31 23:22:09 +01:00
parent 8e94d6b401
commit 9eecf60219
11 changed files with 283 additions and 47 deletions

33
src/mp4enc.h Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include "image.h"
class MP4Encoder
{
struct Frame
{
enum class kType : uint8_t { IFrame, PFrame, Unknown };
kType type;
std::vector<uint8_t> data;
};
struct Header
{
std::vector<uint8_t> SPS_data;
std::vector<uint8_t> PPS_data;
uint8_t avc_profile;
uint8_t avc_profile_compat;
uint8_t avc_level;
};
class ISVCEncoder* m_encoder = nullptr;
int m_width = 0;
int m_height = 0;
int m_bitrate = 1000 << 10;
float m_framerate = 0;
Header m_header;
std::vector<Frame> m_frames;
std::vector<uint8_t> m_yuv_buffer;
public:
bool init(int width, int height, int fps, int bitrate) noexcept;
bool encode(const Image& rgba) noexcept;
bool write_mp4(const std::string& filename) const noexcept;
void destroy() noexcept;
};