#define OUTPUT_FREQUENCY 48000
#define FPS 60
+#define AUDIO_OUTPUT_CODEC AV_CODEC_ID_MP3
+#define AUDIO_OUTPUT_SAMPLE_FMT AV_SAMPLE_FMT_FLTP
+#define AUDIO_OUTPUT_BIT_RATE 256000
+
#endif // !defined(_DEFS_H)
AVFrame *frame = avcodec_alloc_frame();
frame->nb_samples = audio.size() / 2;
- frame->format = AV_SAMPLE_FMT_FLT;
+ frame->format = AV_SAMPLE_FMT_FLTP;
frame->channel_layout = AV_CH_LAYOUT_STEREO;
unique_ptr<float[]> planar_samples(new float[audio.size()]);
H264Encoder::H264Encoder(QSurface *surface, int width, int height, HTTPD *httpd)
: current_storage_frame(0), surface(surface), httpd(httpd)
{
- AVCodec *codec_audio = avcodec_find_encoder(AV_CODEC_ID_MP3);
+ AVCodec *codec_audio = avcodec_find_encoder(AUDIO_OUTPUT_CODEC);
context_audio = avcodec_alloc_context3(codec_audio);
- context_audio->bit_rate = 256000;
+ context_audio->bit_rate = AUDIO_OUTPUT_BIT_RATE;
context_audio->sample_rate = OUTPUT_FREQUENCY;
- context_audio->sample_fmt = AV_SAMPLE_FMT_FLTP;
+ context_audio->sample_fmt = AUDIO_OUTPUT_SAMPLE_FMT;
context_audio->channels = 2;
context_audio->channel_layout = AV_CH_LAYOUT_STEREO;
context_audio->time_base = AVRational{1, TIMEBASE};
avstream_video->codec->chroma_sample_location = AVCHROMA_LOC_LEFT; // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma().
avstream_video->codec->field_order = AV_FIELD_PROGRESSIVE;
- AVCodec *codec_audio = avcodec_find_encoder(AV_CODEC_ID_MP3);
+ AVCodec *codec_audio = avcodec_find_encoder(AUDIO_OUTPUT_CODEC);
avstream_audio = avformat_new_stream(avctx, codec_audio);
if (avstream_audio == nullptr) {
fprintf(stderr, "avformat_new_stream() failed\n");
exit(1);
}
avstream_audio->time_base = AVRational{1, TIMEBASE};
- avstream_audio->codec->bit_rate = 256000;
+ avstream_audio->codec->bit_rate = AUDIO_OUTPUT_BIT_RATE;
avstream_audio->codec->sample_rate = OUTPUT_FREQUENCY;
- avstream_audio->codec->sample_fmt = AV_SAMPLE_FMT_FLTP;
+ avstream_audio->codec->sample_fmt = AUDIO_OUTPUT_SAMPLE_FMT;
avstream_audio->codec->channels = 2;
avstream_audio->codec->channel_layout = AV_CH_LAYOUT_STEREO;
avstream_audio->codec->time_base = AVRational{1, TIMEBASE};