1 // A class to encode audio (using ffmpeg) and send it to a Mux.
3 #ifndef _AUDIO_ENCODER_H
4 #define _AUDIO_ENCODER_H 1
10 #include <libavcodec/avcodec.h>
11 #include <libavresample/avresample.h>
12 #include <libavutil/frame.h>
19 AudioEncoder(const std::string &codec_name, int bit_rate, const std::vector<Mux *> &muxes);
22 void encode_audio(const std::vector<float> &audio, int64_t audio_pts);
23 void encode_last_audio();
25 const AVCodec *get_codec() { return ctx->codec; }
28 void encode_audio_one_frame(const float *audio, size_t num_samples, int64_t audio_pts);
30 std::vector<float> audio_queue;
31 int64_t last_pts = 0; // The first pts after all audio we've encoded.
34 AVAudioResampleContext *resampler;
35 AVFrame *audio_frame = nullptr;
36 std::vector<Mux *> muxes;
39 #endif // !defined(_AUDIO_ENCODER_H)