Audio encoding problem

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Audio encoding problem

Mustafa Yavuz
Hi,
I would like to encode decoded frames in signed 16 bit little endian
format. By input audio is in f32le format, 1 channels and 48000 sampling
rate. When I run the code below it just lower the size of file by half,
that only number of channels affects encoding. Sampling rate that I
assigned enc_ctx->sample_rate variable has  no effect. I do not why it does
not work. I also do not want to use resampling function which are
deprecated. I have also examined and tried the code in your offical website
and it did not work for some reasons, I asked it in stackoverflow
here<http://stackoverflow.com/questions/18383442/encoding-by-using-ffmpeg-library>
.

Code is here <http://codepaste.net/rgqpc9>

Thanks..
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Nicolas George-2
Le sextidi 6 fructidor, an CCXXI, Mustafa Yavuz a écrit :
> I would like to encode decoded frames in signed 16 bit little endian
> format.

You forgot to specify: PCM.

> Code is here <http://codepaste.net/rgqpc9>

#    enc_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
#    enc_ctx->bit_rate = 64000;
#    enc_ctx->sample_rate    = 11025;
#    enc_ctx->channel_layout = AV_CH_LAYOUT_MONO ;
#    enc_ctx->channels       = 1;

You got the wrong idea that this is asking the PCM encoder to encode at a
specific sample rate and with a specific channel count. It does not work
that way. You are saying to the encoder what you are giving it as input.
Since you are actually giving it something completely different, it does not
work at all.

You have to convert and remix the audio stream. For that, you can use
libswresample directly or libavfilter.

By the way, you will never achieve 64000 bit/s with these settings, your
bit_rate field is completely wrong.

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Mustafa Yavuz
bit_rate is another problem for me. Is not it sample_rate *
bit_count_per_sample? Why do we need to adjust it in encoder? It also does
not change anything even I comment out that line. For your another replies,
I also thought, I need to resample it before encoding, but now I don't
understand the functionality of sample_rate, channel number parameters in
av_codec_context class, does not it resample it while encoding?


2013/8/23 Nicolas George <[hidden email]>

> Le sextidi 6 fructidor, an CCXXI, Mustafa Yavuz a écrit :
> > I would like to encode decoded frames in signed 16 bit little endian
> > format.
>
> You forgot to specify: PCM.
>
> > Code is here <http://codepaste.net/rgqpc9>
>
> #    enc_ctx->sample_fmt = AV_SAMPLE_FMT_S16;
> #    enc_ctx->bit_rate = 64000;
> #    enc_ctx->sample_rate    = 11025;
> #    enc_ctx->channel_layout = AV_CH_LAYOUT_MONO ;
> #    enc_ctx->channels       = 1;
>
> You got the wrong idea that this is asking the PCM encoder to encode at a
> specific sample rate and with a specific channel count. It does not work
> that way. You are saying to the encoder what you are giving it as input.
> Since you are actually giving it something completely different, it does
> not
> work at all.
>
> You have to convert and remix the audio stream. For that, you can use
> libswresample directly or libavfilter.
>
> By the way, you will never achieve 64000 bit/s with these settings, your
> bit_rate field is completely wrong.
>
> Regards,
>
> --
>   Nicolas George
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Nicolas George-2
Le sextidi 6 fructidor, an CCXXI, Mustafa Yavuz a écrit :
> bit_rate is another problem for me. Is not it sample_rate *
> bit_count_per_sample?

In the PCM case, it is, if the bit count includes all channels. But you
probably do not need to use a pocket calculator to notice that 11025×16×1 is
not 64000.

> Why do we need to adjust it in encoder?

For PCM, you do not need to. For lossy codecs, that propose a trade between
bit rate and quality, you may want to set it to encode at fixed bit rate.

> I need to resample it before encoding, but now I don't understand the
> functionality of sample_rate, channel number parameters in
> av_codec_context class, does not it resample it while encoding?

No, it does not resample for encoding. For PCM, sample rate will not make
any difference. The channel count will make a difference, because it will
tell how many values per sample there is, but the channel layout is
irrelevant.

For other codecs, sample rate will make a difference: lossy codecs will use
frequency filters to eliminate noise that can not be heard by the human ear,
and this kind of noise does not look the same at 8000 Hz and at 48000 Hz.
And the channel layout may have an impact: there is not the same kind of
channel coupling between front and back than between left and right, and you
do not encode the sub-woofer channel the same way as the others.

> 2013/8/23 Nicolas George <[hidden email]>

Please do not top-post on this mailing-list. If you do not know what it
means, look it up.

Regards,

--
  Nicolas George

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Mustafa Yavuz
ok, thank you for your explanations Nicolas, now I will ask a  last
question, these resampling functions are stated as deprecated. What are new
versions of them and Is there any sample codes explaining how to do it?
Thank you..
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Carl Eugen Hoyos
Mustafa Yavuz <89.yavuz <at> gmail.com> writes:

> ok, thank you for your explanations Nicolas, now I will
> ask a last question, these resampling functions are
> stated as deprecated. What are new versions of them and
> Is there any sample codes explaining how to do it?

I don't think the functions that Nicolas proposed are
deprecated, see doc/examples/resampling_audio.c

Carl Eugen

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: Audio encoding problem

Mustafa Yavuz
Ok, I was talking about av_audio_resample_init, audio_resample functions
which are in avcodec.h and deprecated but yours are different functions
comes from swresample.h. Problem solved. Thanks..


2013/8/23 Carl Eugen Hoyos <[hidden email]>

> Mustafa Yavuz <89.yavuz <at> gmail.com> writes:
>
> > ok, thank you for your explanations Nicolas, now I will
> > ask a last question, these resampling functions are
> > stated as deprecated. What are new versions of them and
> > Is there any sample codes explaining how to do it?
>
> I don't think the functions that Nicolas proposed are
> deprecated, see doc/examples/resampling_audio.c
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user