[Libav-user] Conversion from mp3 to aac/mp4 container problem

Taha Ansari mtaha.ansari at gmail.com
Mon Jun 24 12:34:24 CEST 2013

You can't change input sample format like that, input sample format is

> what decoder outputs, nothing else.
> Same apply to sample format that encoder accepts.
> So you first need to make sure that you do not change sample format
> of decoder and that sample format for encoder is actually supported.
That makes sense, so I modified swr initialization function like this:

        swr = swr_alloc();
        av_opt_set_int(swr, "in_channel_layout",
codec_ctx_audio->channel_layout, 0);
        av_opt_set_int(swr, "out_channel_layout",
codec_ctx_audio->channel_layout,  0);
        av_opt_set_int(swr, "in_sample_rate",
codec_ctx_audio->sample_rate, 0);
        av_opt_set_int(swr, "out_sample_rate",
codec_ctx_audio->sample_rate, 0);
        av_opt_set_sample_fmt(swr, "in_sample_fmt",
codec_ctx_audio->sample_fmt, 0);
        av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16,  0);

So I'm letting decoder decide whatever format it is comfortable with.

Buf for encoder, I know AV_SAMPLE_FMT_S16 has given me compatible results
so far (otherwise crashing). So I keep it like this and run my program:
same results, unfortunately (btw codec_ctx_audio->sample_fmt shows
AV_SAMPLE_FMT_S16P inside debugger anyway).

The success I'm talking of, from AV_SAMPLE_FMT_S16 have been from some
other test, i.e. if i try to encode an mp4 file as mp4 file (makes no sense
but this exercise makes me visualize my guess for 'AV_SAMPLE_FMT_S16' is
working, i.e. mp4 to mp4 conversion from my code runs just fine).

Obviously, I need to improve encoding functions, somehow. But I can't put
my finger on it. <sad>

Cleary examples are not documented properly and needs improving ASAP.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130624/dcddef68/attachment.html>

More information about the Libav-user mailing list