Files
utun2/tools/chatgui/src/stream_video_encoder.h
T

33 lines
1.5 KiB
C++

/* FFmpeg live encoder: один worker владеет контекстом, конвертером и decoder configuration.
* open/encode/close последовательны; каждый KEY содержит uAV2 envelope. Пакеты имеют capture PTS.
* Encoder открывается по фактическим возможностям; GPU имеет приоритет, затем software того же кодека. */
#pragma once
#include <QByteArray>
#include <QImage>
#include <QString>
#include <QList>
#include <memory>
#include <cstdint>
struct StreamVideoConfig {
int width = 1280, height = 720, fps = 30, bitrate = 2500000, codec = 1, rotation = 0;
bool operator==(const StreamVideoConfig&) const = default;
};
struct StreamEncodedFrame { QByteArray data; uint64_t pts = 0; bool key = false; };
class StreamVideoEncoder {
public:
StreamVideoEncoder();
~StreamVideoEncoder();
bool open(const StreamVideoConfig& config);
bool setBitrate(int bitrate); // true — изменение на следующем кадре; false — нужна смена видеоконтекста
void close();
bool encode(const QImage& image, uint64_t pts, bool key, QList<StreamEncodedFrame>& output);
QString error() const;
QString name() const;
static QList<int> available(); // реальная проба открытия и первого KEY; вызывать вне GUI
static QString codecName(int codec);
private:
struct Impl;
std::unique_ptr<Impl> m;
};