63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
#pragma once
|
||
|
||
#include "VideoEncoderBase.h"
|
||
#include "common/config.h"
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
// 合规守护:DISABLE_FFMPEG_FOR_TEST=1 时整类移出编译单元,避免 GPL 传染(与 c0a632a 对齐)
|
||
#if defined(_WIN64) && !DISABLE_FFMPEG_FOR_TEST
|
||
|
||
struct AVCodecContext;
|
||
struct AVFrame;
|
||
struct AVPacket;
|
||
|
||
// FFmpeg 硬编 AV1 实现。
|
||
// 后端探测顺序:av1_nvenc (NVIDIA RTX 40+) → av1_amf (AMD RX 7000+) → av1_qsv
|
||
// (Intel Arc / 11 代+ 部分核显)。AV1 硬编硬件门槛比 H.264 高得多 —— 没合适
|
||
// 硬件时 open 全部失败,由 EncoderFactory 自动回退到 H.264 路径。
|
||
//
|
||
// 注意:FFmpeg 7.1 没有 av1_mf 兜底,因此本类的探测列表比 H.264 短一项。
|
||
class CFFmpegAV1Encoder : public VideoEncoderBase
|
||
{
|
||
public:
|
||
CFFmpegAV1Encoder();
|
||
~CFFmpegAV1Encoder() override;
|
||
|
||
bool open(const EncoderParams& params) override;
|
||
void close() override;
|
||
|
||
int encode(
|
||
uint8_t* rgb,
|
||
uint8_t bpp,
|
||
uint32_t stride,
|
||
uint32_t width,
|
||
uint32_t height,
|
||
uint8_t** lppData,
|
||
uint32_t* lpSize,
|
||
int direction = 1
|
||
) override;
|
||
|
||
void forceIDR() override { m_forceIDR = true; }
|
||
void setBitrate(int kbps) override;
|
||
VideoCodec codec() const override { return VideoCodec::AV1; }
|
||
const char* backendName() const override { return m_backend.c_str(); }
|
||
|
||
private:
|
||
bool tryOpenBackend(const char* name, const EncoderParams& p);
|
||
void cleanupCodec();
|
||
int convertRGB24ToNV12(uint8_t* rgb, uint32_t stride,
|
||
uint32_t width, uint32_t height, int direction);
|
||
|
||
AVCodecContext* m_ctx = nullptr;
|
||
AVFrame* m_frame = nullptr;
|
||
AVPacket* m_packet = nullptr;
|
||
std::vector<uint8_t> m_outputBuffer;
|
||
std::vector<uint8_t> m_i420Scratch;
|
||
int64_t m_pts = 0;
|
||
bool m_forceIDR = false;
|
||
std::string m_backend;
|
||
};
|
||
|
||
#endif // _WIN64 && !DISABLE_FFMPEG_FOR_TEST
|