[Libav-user] How to fill an AVFrame with audio data

Denis Gottardello info at denisgottardello.it
Thu May 7 10:11:39 EEST 2020


Hi, this is a function taken from an ffmpeg example
How can I fill the frame with my data buffer (const uchar* data, int Length)?

***************************************
    AVFrame *frame = OutputStreamAudio.pAVFrameTemp;
    int j, i, v;
    int16_t *q = (int16_t*)frame->data[0];

    /* check if we want to generate more frames */
    if (av_compare_ts(OutputStreamAudio.next_pts, OutputStreamAudio.pAVCodecContext->time_base, STREAM_DURATION, (AVRational){ 1, 1 }) >= 0) return NULL;

    for (j = 0; j <frame->nb_samples; j++) {
        v = (int)(sin(OutputStreamAudio.t) * 10000);
        for (i = 0; i < OutputStreamAudio.pAVCodecContext->channels; i++) *q++ = v;
        OutputStreamAudio.t     += OutputStreamAudio.tincr;
        OutputStreamAudio.tincr += OutputStreamAudio.tincr2;
    }

    frame->pts = OutputStreamAudio.next_pts;
    OutputStreamAudio.next_pts  += frame->nb_samples;

    return frame;
***************************************

Regards


+39.347.4070897
http://www.labcsp.com[1]
http://www.denisgottardello.it[2]
GMT+1
Skype: mrdebug

--------
[1] http://www.labcsp.com
[2] http://www.denisgottardello.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200507/55300a43/attachment.html>


More information about the Libav-user mailing list