From c9524c5c9154644d7e1cbab0f035848d3506e125 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 14 Nov 2015 01:50:55 +0100 Subject: [PATCH] Switch to uncompressed (32-bit) PCM. Saves a little CPU processing power. Also requires us to switch muxer. --- defs.h | 12 ++++++------ h264encode.cpp | 17 +++++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/defs.h b/defs.h index 3b48cdd..580ced7 100644 --- a/defs.h +++ b/defs.h @@ -5,13 +5,13 @@ #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 +#define AUDIO_OUTPUT_CODEC AV_CODEC_ID_PCM_S32LE +#define AUDIO_OUTPUT_SAMPLE_FMT AV_SAMPLE_FMT_S32 +#define AUDIO_OUTPUT_BIT_RATE 0 -#define LOCAL_DUMP_FILE_NAME "test.ts" -#define STREAM_MUX_NAME "mpegts" -#define MUX_OPTS {} +#define LOCAL_DUMP_FILE_NAME "test.mov" +#define STREAM_MUX_NAME "mov" +#define MUX_OPTS {{ "movflags", "empty_moov+frag_keyframe+default_base_moof" }} // In bytes. Beware, if too small, stream clients will start dropping data. #define MUX_BUFFER_SIZE 10485760 diff --git a/h264encode.cpp b/h264encode.cpp index 6e946d9..04ad669 100644 --- a/h264encode.cpp +++ b/h264encode.cpp @@ -1698,14 +1698,19 @@ int H264Encoder::save_codeddata(storage_task task) AVFrame *frame = avcodec_alloc_frame(); frame->nb_samples = audio.size() / 2; - frame->format = AV_SAMPLE_FMT_FLTP; + frame->format = AV_SAMPLE_FMT_S32; frame->channel_layout = AV_CH_LAYOUT_STEREO; - unique_ptr planar_samples(new float[audio.size()]); - avcodec_fill_audio_frame(frame, 2, AV_SAMPLE_FMT_FLTP, (const uint8_t*)planar_samples.get(), audio.size() * sizeof(float), 0); - for (int i = 0; i < frame->nb_samples; ++i) { - planar_samples[i] = audio[i * 2 + 0]; - planar_samples[i + frame->nb_samples] = audio[i * 2 + 1]; + unique_ptr int_samples(new int32_t[audio.size()]); + avcodec_fill_audio_frame(frame, 2, AV_SAMPLE_FMT_S32, (const uint8_t*)int_samples.get(), audio.size() * sizeof(int32_t), 0); + for (int i = 0; i < frame->nb_samples * 2; ++i) { + if (audio[i] >= 1.0f) { + int_samples[i] = 2147483647; + } else if (audio[i] <= -1.0f) { + int_samples[i] = -2147483647; + } else { + int_samples[i] = lrintf(audio[i] * 2147483647.0f); + } } AVPacket pkt; -- 2.39.2