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

Function init_output_frame

doc/examples/transcode_aac.c:609–641  ·  view source on GitHub ↗

* Initialize one input frame for writing to the output file. * The frame will be exactly frame_size samples large. * @param[out] frame Frame to be initialized * @param output_codec_context Codec context of the output file * @param frame_size Size of the frame * @return Error code (0 if successful) */

Source from the content-addressed store, hash-verified

607 * @return Error code (0 if successful)
608 */
609static int init_output_frame(AVFrame **frame,
610 AVCodecContext *output_codec_context,
611 int frame_size)
612{
613 int error;
614
615 /* Create a new frame to store the audio samples. */
616 if (!(*frame = av_frame_alloc())) {
617 fprintf(stderr, "Could not allocate output frame\n");
618 return AVERROR_EXIT;
619 }
620
621 /* Set the frame's parameters, especially its size and format.
622 * av_frame_get_buffer needs this to allocate memory for the
623 * audio samples of the frame.
624 * Default channel layouts based on the number of channels
625 * are assumed for simplicity. */
626 (*frame)->nb_samples = frame_size;
627 av_channel_layout_copy(&(*frame)->ch_layout, &output_codec_context->ch_layout);
628 (*frame)->format = output_codec_context->sample_fmt;
629 (*frame)->sample_rate = output_codec_context->sample_rate;
630
631 /* Allocate the samples of the created frame. This call will make
632 * sure that the audio frame can hold as many samples as specified. */
633 if ((error = av_frame_get_buffer(*frame, 0)) < 0) {
634 fprintf(stderr, "Could not allocate output frame samples (error '%s')\n",
635 av_err2str(error));
636 av_frame_free(frame);
637 return error;
638 }
639
640 return 0;
641}
642
643/* Global timestamp for the audio frames. */
644static int64_t pts = 0;

Callers 1

load_encode_and_writeFunction · 0.85

Calls 4

av_frame_allocFunction · 0.85
av_channel_layout_copyFunction · 0.85
av_frame_get_bufferFunction · 0.85
av_frame_freeFunction · 0.85

Tested by

no test coverage detected