From 653ea43b8c06065a764b2f8960b1858beb83aa73 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 14 Nov 2015 01:00:16 +0100 Subject: [PATCH] Move audio codec choice into defs.h. --- defs.h | 4 ++++ h264encode.cpp | 8 ++++---- httpd.cpp | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/defs.h b/defs.h index fe27804..9e3dfd5 100644 --- a/defs.h +++ b/defs.h @@ -5,4 +5,8 @@ #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) diff --git a/h264encode.cpp b/h264encode.cpp index dd2c805..6e946d9 100644 --- a/h264encode.cpp +++ b/h264encode.cpp @@ -1698,7 +1698,7 @@ int H264Encoder::save_codeddata(storage_task task) 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 planar_samples(new float[audio.size()]); @@ -1833,11 +1833,11 @@ static int print_input() 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}; diff --git a/httpd.cpp b/httpd.cpp index 359bd72..281bbcf 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -113,16 +113,16 @@ HTTPD::Mux::Mux(AVFormatContext *avctx, int width, int height) 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}; -- 2.39.2