<div dir="ltr"><div>Which parameter caused the crash?<br><br>assume 

<b>_AVFifo is initialized.</b></div><div><b><br></b>   <b>int ret = av_audio_fifo_read(_AVFifo, (void **)output_frame->data, frame_size); </b> <- Here it crashes<br></div><div><br></div>can you upload all the source code including your test file? Maybe I can help to debug it.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 2, 2022 at 4:07 PM Dr. Sven Alisch <<a href="mailto:svenali@t-online.de">svenali@t-online.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear developers,<br>
<br>
My original material is a PCM stream (WAV) which I want to encode to MP3. I reformat it with swr_convert from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_FLTP and copy it to a AVFifo, because the frame sizes are different. In my encoding Function I read out my samples from that Fifo and want to send it to the encoder. I use a similar code like the code from tanscode_aac.c. It seems to work fine, but I can not read from Fifo and store the data in to output_frame->data. My program crashes. If I use a self created structure (a buffer I prepared of my own), than it works.<br>
Also strange for me is, that the linesize-parameter after the av_frame_get_buffer(output_frame, 0); is always for linesize[0] set. Why? I thought, that the FLTP (Planar) mode creates a line size for each channel?<br>
<br>
Here my code:<br>
<br>
    AVFrame *output_frame = av_frame_alloc();<br>
    if (!output_frame)<br>
    {<br>
        cerr << "Could not allocate output frame" << endl;<br>
        return;<br>
    }<br>
    const int frame_size = FFMIN(av_audio_fifo_size(_AVFifo), _CodecContext->frame_size);<br>
    output_frame->nb_samples = frame_size;<br>
    output_frame->format = _CodecContext->sample_fmt;<br>
    output_frame->sample_rate = _CodecContext->sample_rate;<br>
    output_frame->channel_layout = _CodecContext->channel_layout;<br>
<br>
    error = av_frame_get_buffer(output_frame, 0);<br>
    if (error < 0)<br>
    {<br>
        cerr << "Could not allocate output frame samples: " << av_err2str(error) << endl;<br>
        av_frame_free(&output_frame);<br>
        return;<br>
    }<br>
<br>
    AVPacket *output_packet = av_packet_alloc();<br>
    if (!output_packet)<br>
    {<br>
        cerr << "could not allocate the packet!" << endl;<br>
        return;<br>
    }<br>
<br>
    int ret = av_audio_fifo_read(_AVFifo, (void **)output_frame->data, frame_size);  <- Here it crashes<br>
    if (ret < frame_size)<br>
    {<br>
        cerr << "Could not read data from FIFO" << endl;<br>
        av_frame_free(&output_frame);<br>
        return;<br>
    }<br>
    cout << ret * sizeof(float) << " readed Bytes from AV Fifo." << endl;<br>
<br>
    output_frame->pts = _pts;<br>
    _pts += output_frame->nb_samples;<br>
<br>
    ret = avcodec_send_frame(_CodecContext, output_frame);<br>
    if (ret < 0)<br>
    {<br>
        cerr << "Error sending the frame to the encoder! Answer: " << ret << endl;<br>
    }<br>
<br>
    while (ret >= 0)<br>
    {<br>
        ret = avcodec_receive_packet(_CodecContext, output_packet);<br>
<br>
        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)<br>
        {<br>
            cerr << "Error encoding audio frame ... need more DATA ..." << endl;<br>
            return;<br>
        }<br>
        else if (ret < 0)<br>
        {<br>
            cerr << "Error encoding audio frame!" << endl;<br>
            return;<br>
        }<br>
<br>
        fwrite(output_packet->data, 1, output_packet->size, f);<br>
<br>
        av_packet_unref(output_packet);<br>
<br>
Thank you for help!<br>
<br>
Regards,<br>
Sven<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div>