diff --git a/libavdevice/alsa-audio-enc.c b/libavdevice/alsa-audio-enc.c index 5033a4894e..83e1d2f85f 100644 --- a/libavdevice/alsa-audio-enc.c +++ b/libavdevice/alsa-audio-enc.c @@ -47,12 +47,17 @@ static av_cold int audio_write_header(AVFormatContext *s1) { AlsaData *s = s1->priv_data; - AVStream *st; + AVStream *st = NULL; unsigned int sample_rate; enum AVCodecID codec_id; int res; + if (s1->nb_streams != 1 || s1->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) { + av_log(s1, AV_LOG_ERROR, "Only a single audio stream is supported.\n"); + return AVERROR(EINVAL); + } st = s1->streams[0]; + sample_rate = st->codec->sample_rate; codec_id = st->codec->codec_id; res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,