[FFmpeg-user] how to use swr_convert_frame convert audio form s16p to s16

He Lei helei0908 at hotmail.com
Thu Nov 17 11:43:58 EET 2016


Hi,
My sources like this:
              AVFrame *pOutFrame = av_frame_alloc();
              pOutFrame->channel_layout = AV_CH_LAYOUT_STEREO;
              pOutFrame->format = AVSampleFormat::AV_SAMPLE_FMT_S16;
              pOutFrame->sample_rate = 44100;
              static SwrContext* m_pSwrCtx = swr_alloc_set_opts(NULL, AV_CH_LAYOUT_STEREO,        AV_SAMPLE_FMT_S16, 44100,  pFrame->channel_layout,(AVSampleFormat)pFrame->format, pFrame->sample_rate, 0, NULL);
              swr_init(m_pSwrCtx);

              swr_convert_frame(m_pSwrCtx, pOutFrame, pFrame));//return 0
              av_frame_free(&pOutFrame);

pFrame { nb_channel =2;fotmat=s16p;nb_sample=1024,rate=44100}
After called swr_convert_frame;
I found the linesize[0] of pOutFrame is incorrect,;
according to common sense:
pOutFrame linesize[0] should be nb_channel * nb_sample * sample_bytes,
That is 2*1024*2 = 4096 (format is S16), but it’s 4224;
What's wrong with me……





More information about the ffmpeg-user mailing list