#pragma once #include "screencast/capture/capture.h" #include "screencast/codec/error.h" #include #include #include #include namespace sc { struct EncodedFrame { uint64_t capture_timestamp_ns = 0; uint32_t rtp_timestamp = 0; bool is_keyframe = false; std::vector data; // Annex-B H.264 NAL units }; struct EncoderConfig { std::string codec_name = "h264"; int width = 0; int height = 0; int frame_rate_num = 30; int frame_rate_den = 1; // CRF (constant rate factor, 0-51): the target visual quality level. // Lower = better quality. 23 is x264's default; screen content looks // good at 20-24. int crf = 22; // Maximum bitrate in kbps (the VBV cap). The encoder uses fewer bits on // static content and more on motion, but never exceeds this. int bitrate_kbps = 4000; bool hardware_accel = false; }; class Encoder { public: virtual ~Encoder() = default; // Encode one captured frame. Returns an empty vector if the encoder emits // no packet for this frame. virtual CodecResult> encode(const CapturedFrame& frame) = 0; // Flush the encoder and return any remaining packets. virtual CodecResult> flush() = 0; // Force the next output frame to be a keyframe. virtual void request_keyframe() = 0; // Codec-specific parameters required by a decoder (SPS/PPS for H.264). virtual std::vector get_extradata() const = 0; }; class EncoderFactory { public: static CodecResult> create(const EncoderConfig& config); }; } // namespace sc