[Libav-user] libswresample vs libavfilter for target format conversion

Paul B Mahol onemda at gmail.com
Tue Mar 19 09:57:14 CET 2013


On 3/18/13, Jorge Israel Pena <jorgepblank at gmail.com> wrote:
> Hey, this is my first time decoding audio and I'm currently trying to
> figure out the best way to convert audio to the target format.
>
> My understanding is that when the audio is decoded, in order to play it
> through the sound system (with say pulseaudio), it should be converted to
> the sound system's target format if it isn't already in that format, like
> say if my target format is two channels, S16 non-planar, 44100hz. After
> consulting the ffplay source I found that they use libswresample. However
> I've also found mention of using libavfilter for this purpose. I have no
> experience with libavfilter but it seems to me like a very recent commit to
> ffplay adds support for it:
> https://github.com/FFmpeg/FFmpeg/commit/e96175ad7b576ad57b83d399193ef10b2bb016ae
> so
> I can probably learn from that.

No you can not. That commit is for using audio filters via ffplay and
have nothing
to do with libswresample.

>
> It seems like it uses the 'abuffer' filter, is this the one to use for this
> case? It doesn't strike me (from the doxygen) as a filter used for
> conversion. It seems to me like it's setup as an `abuffer` for the input
> and an `abuffersink` for the output, and the `abuffersink`'s parameters
> describe the target format. So when a frame is put in and pulled out from
> the filter graph it's automatically converted to that format due to the
> parameters passed to 'abuffersink'?
>
> I had also previously seen someone say to use the 'aformat' filter for this
> purpose. Is there a difference? Looking at the list of filters, I also see
> "aconvert: Sample format and channel layout conversion audio filter" and
> "resample: Sample format and channel layout conversion audio filter". So I
> see there's abuffer, aformat, aconvert, and resample, so I'm pretty
> confused here and would really appreciate any clarification. Then again I
> know nothing about the whole filter system so this may be something very
> simple/obvious.
>
> Aside from that, what are the benefits of using libavfilter for converting
> to the target format over using libswresample? It seems to me like after
> the initial setup for avfilter, the actual conversion process seems a lot
> simpler, simply consisting of putting frames and pulling them out of the
> filter graph. Is this the benefit?

Again you are wrong. It is trivial to convert beetween various sample formats
with libswresample. And you do not need to use libavfilter's filters for this.
ffmpeg/ffplay just use filter(s) to convert it to wanted format but you
are not required to use filter way, it is just another abstraction of
libswresample.

>
> Thanks, I would really appreciate some clarification for this.
>
> --
> - Jorge Israel Pena
>


More information about the Libav-user mailing list