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
12 #include <libavcodec/avcodec.h>
13 #include <libavformat/avformat.h>
14 #include <libswresample/swresample.h>
15 #include <libavutil/frame.h>
18 #include "shared/ffmpeg_raii.h"
24 AudioEncoder(const std::string &codec_name, int bit_rate, const AVOutputFormat *oformat);
27 void add_mux(Mux *mux) { // Does not take ownership.
30 void encode_audio(const std::vector<float> &audio, int64_t audio_pts);
31 void encode_last_audio();
33 AVCodecParametersWithDeleter get_codec_parameters();
36 void encode_audio_one_frame(const float *audio, size_t num_samples, int64_t audio_pts);
38 std::vector<float> audio_queue;
39 int64_t last_pts = 0; // The first pts after all audio we've encoded.
42 SwrContext *resampler;
43 AVFrame *audio_frame = nullptr;
44 std::vector<Mux *> muxes;
47 #endif // !defined(_AUDIO_ENCODER_H)