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

Paul B Mahol onemda at gmail.com
Mon Jun 24 12:46:01 CEST 2013

On 6/24/13, Taha Ansari <mtaha.ansari at gmail.com> wrote:
> 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);
>         swr_init(swr);
> 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).

"Compatible" results from rest of thread means its wrong one, as it gives
wrong output.

Planar sample format have data in different format stored in memory thus if
you do not use it correctly crash happens....

> 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.

More information about the Libav-user mailing list