[FFmpeg-devel] possible bug in pcm.c

Lukasz M lukasz.m.luki at gmail.com
Mon Oct 21 00:52:12 CEST 2013


On 20 October 2013 23:56, Michael Niedermayer <michaelni at gmx.at> wrote:

> On Sun, Oct 20, 2013 at 10:54:36PM +0200, Lukasz M wrote:
> > On 20 October 2013 19:59, Michael Niedermayer <michaelni at gmx.at> wrote:
> >
> > > On Sun, Oct 20, 2013 at 05:05:16PM +0200, Lukasz M wrote:
> > > > Hi,
> > > >
> > > > I work on code that reads stream from input, decodes audio
> > > > with avcodec_decode_audio4 and then encode frame again.
> > > > Output muxer is pulse device. I use AV_CODEC_ID_PCM_S16LE codec
> (taken
> > > from
> > > > device) and AV_SAMPLE_FMT_S16 sample format
> > > >
> > > > Input has 2 channels. I got a noise on speakers. I was strugging a
> lot
> > > and
> > > > finally debugged it:
> > > >
> > > > after decoding with avcodec_decode_audio4, frame has sample
> > > > format AV_SAMPLE_FMT_S16P, 2 channels.
> > > > During encoding frame->data[0] is taken as a source for all samples,
> but
> > > it
> > > > has data only for one channel, second one is on frame->data[1]
> > > >
> > > > static int pcm_encode_frame(...)
> > > > [...]
> > > >     sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
> > > >     n           = frame->nb_samples * avctx->channels;
> > > >     samples     = (const short *)frame->data[0];
> > > >
> > > > [...]
> > > >
> > > > switch (avctx->codec->id) {
> > > > [...]
> > > >     case AV_CODEC_ID_PCM_S16LE:
> > > > #endif /* HAVE_BIGENDIAN */
> > > >     case AV_CODEC_ID_PCM_U8:
> > > >         memcpy(dst, samples, n * sample_size);
> > > >         break;
> > > >
> > > > It seems pcm_encode_frame doesn't support AV_SAMPLE_FMT_S16P frames
> > > > correctly.
> > >
> > > make sure that the sample format you use is in the list of
> > > supported formats of the AVCodec used
> > >
> >
> > I don't know what I was thinking about, but surprised it is not checked
> > anywere.
> > Thanks and sorry for spam.
>
> sample format should be checked by avcodec_open2()


You are right. I did check for return value, but didn't propagated it
outside and flow continued like no error.
I fixed it now anyway.
Thanks again for help and sorry for false alarm :)


More information about the ffmpeg-devel mailing list