2017-06-13 00:38:32 +02:00
|
|
|
#ifndef ENCODER_HPP
|
|
|
|
#define ENCODER_HPP
|
2017-06-11 23:56:06 +02:00
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QSize>
|
|
|
|
extern "C" {
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
}
|
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
struct OutputStream {
|
|
|
|
AVStream *st = NULL;
|
|
|
|
AVCodecContext *enc = NULL;
|
|
|
|
|
|
|
|
int64_t nextPts = 0;
|
2017-06-11 23:56:06 +02:00
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
AVFrame *frame = NULL;
|
|
|
|
|
|
|
|
SwsContext *sws = NULL;
|
|
|
|
};
|
|
|
|
|
2017-06-17 17:32:47 +02:00
|
|
|
struct CodecSettings {
|
|
|
|
int bitrate;
|
|
|
|
int gopSize;
|
|
|
|
int bFrames;
|
|
|
|
int mbDecisions;
|
|
|
|
QString h264Profile;
|
|
|
|
int h264Crf;
|
|
|
|
bool vp9Lossless;
|
|
|
|
};
|
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
class Encoder {
|
|
|
|
public:
|
2017-06-17 17:32:47 +02:00
|
|
|
Encoder(QString &targetFile, QSize res, CodecSettings *settings = NULL);
|
2017-06-13 00:38:32 +02:00
|
|
|
~Encoder();
|
2017-06-11 23:56:06 +02:00
|
|
|
bool addFrame(QImage frm);
|
|
|
|
bool isRunning();
|
2017-06-13 00:38:32 +02:00
|
|
|
bool end();
|
2017-06-11 23:56:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
AVCodec *codec = NULL;
|
2017-06-13 00:38:32 +02:00
|
|
|
|
|
|
|
OutputStream *out = new OutputStream;
|
|
|
|
AVFormatContext *fc = NULL;
|
2017-06-11 23:56:06 +02:00
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
QSize size;
|
|
|
|
|
|
|
|
void setFrameRGB(uint8_t *rgb);
|
|
|
|
};
|
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
#endif // ENCODER_HPP
|