MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / load_encode_and_write

Function load_encode_and_write

doc/examples/transcode_aac.c:727–760  ·  view source on GitHub ↗

* Load one audio frame from the FIFO buffer, encode and write it to the * output file. * @param fifo Buffer used for temporary storage * @param output_format_context Format context of the output file * @param output_codec_context Codec context of the output file * @return Error code (0 if successful) */

Source from the content-addressed store, hash-verified

725 * @return Error code (0 if successful)
726 */
727static int load_encode_and_write(AVAudioFifo *fifo,
728 AVFormatContext *output_format_context,
729 AVCodecContext *output_codec_context)
730{
731 /* Temporary storage of the output samples of the frame written to the file. */
732 AVFrame *output_frame;
733 /* Use the maximum number of possible samples per frame.
734 * If there is less than the maximum possible frame size in the FIFO
735 * buffer use this number. Otherwise, use the maximum possible frame size. */
736 const int frame_size = FFMIN(av_audio_fifo_size(fifo),
737 output_codec_context->frame_size);
738 int data_written;
739
740 /* Initialize temporary storage for one output frame. */
741 if (init_output_frame(&output_frame, output_codec_context, frame_size))
742 return AVERROR_EXIT;
743
744 /* Read as many samples from the FIFO buffer as required to fill the frame.
745 * The samples are stored in the frame temporarily. */
746 if (av_audio_fifo_read(fifo, (void **)output_frame->data, frame_size) < frame_size) {
747 fprintf(stderr, "Could not read data from FIFO\n");
748 av_frame_free(&output_frame);
749 return AVERROR_EXIT;
750 }
751
752 /* Encode one frame worth of audio samples. */
753 if (encode_audio_frame(output_frame, output_format_context,
754 output_codec_context, &data_written)) {
755 av_frame_free(&output_frame);
756 return AVERROR_EXIT;
757 }
758 av_frame_free(&output_frame);
759 return 0;
760}
761
762/**
763 * Write the trailer of the output file container.

Callers 1

mainFunction · 0.85

Calls 5

av_audio_fifo_sizeFunction · 0.85
init_output_frameFunction · 0.85
av_audio_fifo_readFunction · 0.85
av_frame_freeFunction · 0.85
encode_audio_frameFunction · 0.85

Tested by

no test coverage detected