scar-chat7/client/media/video_encoder.h

53 lines
1.2 KiB
C
Raw Normal View History

#ifndef SCAR_VIDEO_ENCODER_H
#define SCAR_VIDEO_ENCODER_H
#include <vector>
#include <cstdint>
#include <memory>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
}
namespace scar {
class VideoEncoder {
public:
VideoEncoder();
~VideoEncoder();
2025-12-07 20:12:08 -07:00
// Initialize encoder
// bitrate in bits per second (default 2Mbps)
// spa_format: SPA video format from PipeWire (0 = auto-detect as BGR0)
bool initialize(int width, int height, int fps, int bitrate = 2000000, uint32_t spa_format = 0);
// Encode a raw frame (BGR0 format from PipeWire)
// Returns encoded packet data, empty if error or no packet yet
std::vector<uint8_t> encode(const uint8_t* frame_data, uint32_t frame_size);
// Flush any remaining frames
std::vector<uint8_t> flush();
// Cleanup
void cleanup();
private:
AVCodecContext* codec_ctx_;
AVFrame* frame_;
AVPacket* packet_;
SwsContext* sws_ctx_;
int width_;
int height_;
int frame_counter_;
bool initialized_;
};
} // namespace scar
#endif // SCAR_VIDEO_ENCODER_H