[Libav-user] libvorbis encoder problem

Tomaž Rotovnik rotovnik.tomaz at gmail.com
Sat Mar 30 16:37:26 CET 2013


Hi

I checked *doc/examples/muxingc.c* file where an example generating MPEG AV
file is explained. Then I try to change AV format to "*webm*" (video is
encoded with VP8 and audio with vorbis encoder). I have problems with
setting the right parameters for vorbis encoder. When I debugging through
the code I figured out that vorbis only accepts (AV_SAMPLE_FMT_FLTP) sample
format type. Example was done with (AV_SAMPLE_FMT_S16). I looked into
source code to figure out that when I call **
**
*av**codec_fill_audio_frame(AVFrame, channels, sample_format, buffer,
buf_size, align)*,

in case of AV_SAMPLE_FMT_FLTP the buffer should be type *float** and audio
samples should have values between -1.0 to 1.0. For more than one channel
values are *not interleaved *(FLTP - float plain) but they are followed by
each other (array: all values for channel0, all values for channel 1, ...).

When I accept those changes in my code, unfortunately I still don't get
correct result. If I use mono (1 channel only) then the flag (got_packet)
returned from function *avcodec_encode_audio2* is set only once (after
around 5 consecutive calls), with *AVPacket->pts* timestamp set to some
huge values. Because of that only video is encoded.
When I set stereo mode I get error from function *av_interleaved_write_frame
* (-12).

I tested the same code and setting AV format to "*asf*", where audio is
encoded with WMA2 encoder and also accepts AV_SAMPLE_FMT_FLTP sample format
type. I got correct AV file which can be played with VLC player or Windows
media player.

I think I still need to set some flags for vorbis encoder, but I can't
figure out. I would appreciate any suggestions.

Best regards

For audio encoder I set those parameters:

c->sample_fmt = AV_SAMPLE_FMT_FLTP;
c->sample_rate = 44100;
c->channels = 1;

My code to prepare samples in AV_SAMPLE_FMT_FLTP sample format:

void TT_Transcode::get_audio_frame_fltp(float *fsamples, int
frame_size, intnb_channels)
{
    int j, i;
    float v;
    float *q;
    for (j = 0; j < frame_size; j++) {
        v = (sin(t) * 10000.0) / 32767.0f; //values between -1.0 and +1.0
        fsamples[ j ] = v;
        for (i = 1; i < nb_channels; i++)
        {
            fsamples[i * in_linesize + j] = v;
        }
        t += tincr;
        tincr += tincr2;
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130330/18b987d8/attachment.html>


More information about the Libav-user mailing list