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

37 lines
1.9 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>
enum class LiveVideoProfile { Automatic, H264ConstrainedBaseline, H265Main };
struct LiveVideoConfig {
int width = 1280, height = 720, fps = 30, bitrate = 2500000, codec = 1, rotation = 0;
LiveVideoProfile profile = LiveVideoProfile::Automatic;
int level = 0, references = 0, vbvBits = 0; // level: AVC level_idc / HEVC general_level_idc; 0 — auto.
QString backend; // Пусто — проба доступных; непусто — только уже проверенный encoder.
bool operator==(const LiveVideoConfig&) const = default;
};
struct LiveEncodedFrame { QByteArray data; uint64_t pts = 0; bool key = false; };
class LiveVideoEncoder {
public:
LiveVideoEncoder();
~LiveVideoEncoder();
bool open(const LiveVideoConfig& config);
bool setBitrate(int bitrate); // true — изменение на следующем кадре; false — нужна смена видеоконтекста
void close();
bool encode(const QImage& image, uint64_t pts, bool key, QList<LiveEncodedFrame>& 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;
};