From a3a07d2f565756771e9c4f0b9574dcffe51c2fa4 Mon Sep 17 00:00:00 2001 From: "Markus Kitsinger (SwooshyCueb)" Date: Tue, 26 Apr 2016 21:45:52 -0500 Subject: [PATCH] Some encoders don't like s16 --- src/common/ffmpeg.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/ffmpeg.cpp b/src/common/ffmpeg.cpp index 16937dd..56b6c9e 100644 --- a/src/common/ffmpeg.cpp +++ b/src/common/ffmpeg.cpp @@ -123,10 +123,16 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm oc = NULL; return MRET_ERR_NOMEM; } + + AVCodec *codec = avcodec_find_encoder(fmt->audio_codec); + ctx = aud_st->codec; ctx->codec_id = fmt->audio_codec; ctx->codec_type = AVMEDIA_TYPE_AUDIO; - ctx->sample_fmt = AV_SAMPLE_FMT_S16; + // Some encoders don't like s16 (SAMPLE_FMT_S16) + ctx->sample_fmt = codec->sample_fmts[0]; + // This was changed in the initial ffmpeg 3.0 update, + // but shouldn't (as far as I'm aware) cause problems with older versions ctx->bit_rate = 128000; // arbitrary; in case we're generating mp3 ctx->sample_rate = soundGetSampleRate(); ctx->channels = 2; @@ -135,7 +141,6 @@ MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fm if(fmt->flags & AVFMT_GLOBALHEADER) ctx->flags |= CODEC_FLAG_GLOBAL_HEADER; - AVCodec *codec = avcodec_find_encoder(fmt->audio_codec); #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,6,0) if(!codec || avcodec_open(ctx, codec)) { #else