ffmpeg: Correctly handle sample format
We previously assumed that the first preferred sample format is planar, but that may not be true for all codecs. Instead we should find a supported sample format that is planar.
This commit is contained in:
parent
17461b5d11
commit
8b9c01ded9
1 changed files with 19 additions and 1 deletions
|
@ -224,7 +224,25 @@ bool FFmpegAudioStream::Init(AVFormatContext* format_context) {
|
|||
// Configure audio codec context
|
||||
codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||
codec_context->bit_rate = Settings::values.audio_bitrate;
|
||||
codec_context->sample_fmt = codec->sample_fmts[0];
|
||||
if (codec->sample_fmts) {
|
||||
codec_context->sample_fmt = AV_SAMPLE_FMT_NONE;
|
||||
// Use any planar format
|
||||
const AVSampleFormat* ptr = codec->sample_fmts;
|
||||
while ((*ptr) != -1) {
|
||||
if (av_sample_fmt_is_planar((*ptr))) {
|
||||
codec_context->sample_fmt = (*ptr);
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
if (codec_context->sample_fmt == AV_SAMPLE_FMT_NONE) {
|
||||
LOG_ERROR(Render, "Specified audio encoder does not support any planar format");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
codec_context->sample_fmt = AV_SAMPLE_FMT_S16P;
|
||||
}
|
||||
|
||||
codec_context->sample_rate = AudioCore::native_sample_rate;
|
||||
codec_context->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||
codec_context->channels = 2;
|
||||
|
|
Loading…
Reference in a new issue