Skip to content

Commit

Permalink
Some encoders don't like s16
Browse files Browse the repository at this point in the history
  • Loading branch information
SwooshyCueb committed Apr 27, 2016
1 parent 029a5fc commit a3a07d2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/common/ffmpeg.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit a3a07d2

Please sign in to comment.