Which parameter caused the crash? assume *_AVFifo is initialized.*
*int ret = av_audio_fifo_read(_AVFifo, (void **)output_frame->data, frame_size); * <- Here it crashes can you upload all the source code including your test file? Maybe I can help to debug it. On Sun, Oct 2, 2022 at 4:07 PM Dr. Sven Alisch <[email protected]> wrote: > Dear developers, > > 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. > 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? > > Here my code: > > AVFrame *output_frame = av_frame_alloc(); > if (!output_frame) > { > cerr << "Could not allocate output frame" << endl; > return; > } > const int frame_size = FFMIN(av_audio_fifo_size(_AVFifo), > _CodecContext->frame_size); > output_frame->nb_samples = frame_size; > output_frame->format = _CodecContext->sample_fmt; > output_frame->sample_rate = _CodecContext->sample_rate; > output_frame->channel_layout = _CodecContext->channel_layout; > > error = av_frame_get_buffer(output_frame, 0); > if (error < 0) > { > cerr << "Could not allocate output frame samples: " << > av_err2str(error) << endl; > av_frame_free(&output_frame); > return; > } > > AVPacket *output_packet = av_packet_alloc(); > if (!output_packet) > { > cerr << "could not allocate the packet!" << endl; > return; > } > > int ret = av_audio_fifo_read(_AVFifo, (void **)output_frame->data, > frame_size); <- Here it crashes > if (ret < frame_size) > { > cerr << "Could not read data from FIFO" << endl; > av_frame_free(&output_frame); > return; > } > cout << ret * sizeof(float) << " readed Bytes from AV Fifo." << endl; > > output_frame->pts = _pts; > _pts += output_frame->nb_samples; > > ret = avcodec_send_frame(_CodecContext, output_frame); > if (ret < 0) > { > cerr << "Error sending the frame to the encoder! Answer: " << ret > << endl; > } > > while (ret >= 0) > { > ret = avcodec_receive_packet(_CodecContext, output_packet); > > if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) > { > cerr << "Error encoding audio frame ... need more DATA ..." << > endl; > return; > } > else if (ret < 0) > { > cerr << "Error encoding audio frame!" << endl; > return; > } > > fwrite(output_packet->data, 1, output_packet->size, f); > > av_packet_unref(output_packet); > > Thank you for help! > > Regards, > Sven > _______________________________________________ > Libav-user mailing list > [email protected] > https://ffmpeg.org/mailman/listinfo/libav-user > > To unsubscribe, visit link above, or email > [email protected] with subject "unsubscribe". >
_______________________________________________ Libav-user mailing list [email protected] https://ffmpeg.org/mailman/listinfo/libav-user To unsubscribe, visit link above, or email [email protected] with subject "unsubscribe".
