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

Function main

doc/examples/transcode_aac.c:778–883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778int main(int argc, char **argv)
779{
780 AVFormatContext *input_format_context = NULL, *output_format_context = NULL;
781 AVCodecContext *input_codec_context = NULL, *output_codec_context = NULL;
782 SwrContext *resample_context = NULL;
783 AVAudioFifo *fifo = NULL;
784 int ret = AVERROR_EXIT;
785
786 if (argc != 3) {
787 fprintf(stderr, "Usage: %s <input file> <output file>\n", argv[0]);
788 exit(1);
789 }
790
791 /* Open the input file for reading. */
792 if (open_input_file(argv[1], &input_format_context,
793 &input_codec_context))
794 goto cleanup;
795 /* Open the output file for writing. */
796 if (open_output_file(argv[2], input_codec_context,
797 &output_format_context, &output_codec_context))
798 goto cleanup;
799 /* Initialize the resampler to be able to convert audio sample formats. */
800 if (init_resampler(input_codec_context, output_codec_context,
801 &resample_context))
802 goto cleanup;
803 /* Initialize the FIFO buffer to store audio samples to be encoded. */
804 if (init_fifo(&fifo, output_codec_context))
805 goto cleanup;
806 /* Write the header of the output file container. */
807 if (write_output_file_header(output_format_context))
808 goto cleanup;
809
810 /* Loop as long as we have input samples to read or output samples
811 * to write; abort as soon as we have neither. */
812 while (1) {
813 /* Use the encoder's desired frame size for processing. */
814 const int output_frame_size = output_codec_context->frame_size;
815 int finished = 0;
816
817 /* Make sure that there is one frame worth of samples in the FIFO
818 * buffer so that the encoder can do its work.
819 * Since the decoder's and the encoder's frame size may differ, we
820 * need to FIFO buffer to store as many frames worth of input samples
821 * that they make up at least one frame worth of output samples. */
822 while (av_audio_fifo_size(fifo) < output_frame_size) {
823 /* Decode one frame worth of audio samples, convert it to the
824 * output sample format and put it into the FIFO buffer. */
825 if (read_decode_convert_and_store(fifo, input_format_context,
826 input_codec_context,
827 output_codec_context,
828 resample_context, &finished))
829 goto cleanup;
830
831 /* If we are at the end of the input file, we continue
832 * encoding the remaining audio samples to the output file. */
833 if (finished)
834 break;
835 }

Callers

nothing calls this directly

Calls 15

init_resamplerFunction · 0.85
init_fifoFunction · 0.85
write_output_file_headerFunction · 0.85
av_audio_fifo_sizeFunction · 0.85
load_encode_and_writeFunction · 0.85
encode_audio_frameFunction · 0.85
av_audio_fifo_freeFunction · 0.85
swr_freeFunction · 0.85
avcodec_free_contextFunction · 0.85
avio_closepFunction · 0.85

Tested by

no test coverage detected