FFmpeg
|
#include <stdio.h>
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include "libavcodec/avcodec.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/frame.h"
#include "libavutil/opt.h"
#include "libswresample/swresample.h"
Go to the source code of this file.
Macros | |
#define | OUTPUT_BIT_RATE 96000 |
#define | OUTPUT_CHANNELS 2 |
Functions | |
static int | open_input_file (const char *filename, AVFormatContext **input_format_context, AVCodecContext **input_codec_context) |
Open an input file and the required decoder. More... | |
static int | open_output_file (const char *filename, AVCodecContext *input_codec_context, AVFormatContext **output_format_context, AVCodecContext **output_codec_context) |
Open an output file and the required encoder. More... | |
static int | init_packet (AVPacket **packet) |
Initialize one data packet for reading or writing. More... | |
static int | init_input_frame (AVFrame **frame) |
Initialize one audio frame for reading from the input file. More... | |
static int | init_resampler (AVCodecContext *input_codec_context, AVCodecContext *output_codec_context, SwrContext **resample_context) |
Initialize the audio resampler based on the input and output codec settings. More... | |
static int | init_fifo (AVAudioFifo **fifo, AVCodecContext *output_codec_context) |
Initialize a FIFO buffer for the audio samples to be encoded. More... | |
static int | write_output_file_header (AVFormatContext *output_format_context) |
Write the header of the output file container. More... | |
static int | decode_audio_frame (AVFrame *frame, AVFormatContext *input_format_context, AVCodecContext *input_codec_context, int *data_present, int *finished) |
Decode one audio frame from the input file. More... | |
static int | init_converted_samples (uint8_t ***converted_input_samples, AVCodecContext *output_codec_context, int frame_size) |
Initialize a temporary storage for the specified number of audio samples. More... | |
static int | convert_samples (const uint8_t **input_data, uint8_t **converted_data, const int frame_size, SwrContext *resample_context) |
Convert the input audio samples into the output sample format. More... | |
static int | add_samples_to_fifo (AVAudioFifo *fifo, uint8_t **converted_input_samples, const int frame_size) |
Add converted input audio samples to the FIFO buffer for later processing. More... | |
static int | read_decode_convert_and_store (AVAudioFifo *fifo, AVFormatContext *input_format_context, AVCodecContext *input_codec_context, AVCodecContext *output_codec_context, SwrContext *resampler_context, int *finished) |
Read one audio frame from the input file, decode, convert and store it in the FIFO buffer. More... | |
static int | init_output_frame (AVFrame **frame, AVCodecContext *output_codec_context, int frame_size) |
Initialize one input frame for writing to the output file. More... | |
static int | encode_audio_frame (AVFrame *frame, AVFormatContext *output_format_context, AVCodecContext *output_codec_context, int *data_present) |
Encode one frame worth of audio to the output file. More... | |
static int | load_encode_and_write (AVAudioFifo *fifo, AVFormatContext *output_format_context, AVCodecContext *output_codec_context) |
Load one audio frame from the FIFO buffer, encode and write it to the output file. More... | |
static int | write_output_file_trailer (AVFormatContext *output_format_context) |
Write the trailer of the output file container. More... | |
int | main (int argc, char **argv) |
Variables | |
static int64_t | pts = 0 |
Simple audio converter
Definition in file transcode_aac.c.
#define OUTPUT_BIT_RATE 96000 |
Definition at line 48 of file transcode_aac.c.
#define OUTPUT_CHANNELS 2 |
Definition at line 50 of file transcode_aac.c.
|
static |
Open an input file and the required decoder.
filename | File to be opened | |
[out] | input_format_context | Format context of opened file |
[out] | input_codec_context | Codec context of opened file |
Definition at line 59 of file transcode_aac.c.
Referenced by main().
|
static |
Open an output file and the required encoder.
Also set some basic encoder parameters. Some of these parameters are based on the input file's parameters.
filename | File to be opened | |
input_codec_context | Codec context of input file | |
[out] | output_format_context | Format context of output file |
[out] | output_codec_context | Codec context of output file |
Definition at line 146 of file transcode_aac.c.
Referenced by main().
Initialize one data packet for reading or writing.
[out] | packet | Packet to be initialized |
Definition at line 254 of file transcode_aac.c.
Referenced by decode_audio_frame(), and encode_audio_frame().
Initialize one audio frame for reading from the input file.
[out] | frame | Frame to be initialized |
Definition at line 268 of file transcode_aac.c.
Referenced by read_decode_convert_and_store().
|
static |
Initialize the audio resampler based on the input and output codec settings.
If the input and output sample formats differ, a conversion is required libswresample takes care of this, but requires initialization.
input_codec_context | Codec context of the input file | |
output_codec_context | Codec context of the output file | |
[out] | resample_context | Resample context for the required conversion |
Definition at line 286 of file transcode_aac.c.
Referenced by main().
|
static |
Initialize a FIFO buffer for the audio samples to be encoded.
[out] | fifo | Sample buffer |
output_codec_context | Codec context of the output file |
Definition at line 330 of file transcode_aac.c.
Referenced by main().
|
static |
Write the header of the output file container.
output_format_context | Format context of the output file |
Definition at line 346 of file transcode_aac.c.
Referenced by main().
|
static |
Decode one audio frame from the input file.
frame | Audio frame to be decoded | |
input_format_context | Format context of the input file | |
input_codec_context | Codec context of the input file | |
[out] | data_present | Indicates whether data has been decoded |
[out] | finished | Indicates whether the end of file has been reached and all data has been decoded. If this flag is false, there is more data to be decoded, i.e., this function has to be called again. |
Definition at line 370 of file transcode_aac.c.
Referenced by read_decode_convert_and_store().
|
static |
Initialize a temporary storage for the specified number of audio samples.
The conversion requires temporary storage due to the different format. The number of audio samples to be allocated is specified in frame_size.
[out] | converted_input_samples | Array of converted samples. The dimensions are reference, channel (for multi-channel audio), sample. |
output_codec_context | Codec context of the output file | |
frame_size | Number of samples to be converted in each round |
Definition at line 444 of file transcode_aac.c.
Referenced by read_decode_convert_and_store().
|
static |
Convert the input audio samples into the output sample format.
The conversion happens on a per-frame basis, the size of which is specified by frame_size.
input_data | Samples to be decoded. The dimensions are channel (for multi-channel audio), sample. | |
[out] | converted_data | Converted samples. The dimensions are channel (for multi-channel audio), sample. |
frame_size | Number of samples to be converted | |
resample_context | Resample context for the conversion |
Definition at line 488 of file transcode_aac.c.
Referenced by read_decode_convert_and_store().
|
static |
Add converted input audio samples to the FIFO buffer for later processing.
fifo | Buffer to add the samples to |
converted_input_samples | Samples to be added. The dimensions are channel (for multi-channel audio), sample. |
frame_size | Number of samples to be converted |
Definition at line 514 of file transcode_aac.c.
Referenced by read_decode_convert_and_store().
|
static |
Read one audio frame from the input file, decode, convert and store it in the FIFO buffer.
fifo | Buffer used for temporary storage | |
input_format_context | Format context of the input file | |
input_codec_context | Codec context of the input file | |
output_codec_context | Codec context of the output file | |
resampler_context | Resample context for the conversion | |
[out] | finished | Indicates whether the end of file has been reached and all data has been decoded. If this flag is false, there is more data to be decoded, i.e., this function has to be called again. |
Definition at line 552 of file transcode_aac.c.
Referenced by main().
|
static |
Initialize one input frame for writing to the output file.
The frame will be exactly frame_size samples large.
[out] | frame | Frame to be initialized |
output_codec_context | Codec context of the output file | |
frame_size | Size of the frame |
Definition at line 619 of file transcode_aac.c.
Referenced by load_encode_and_write().
|
static |
Encode one frame worth of audio to the output file.
frame | Samples to be encoded | |
output_format_context | Format context of the output file | |
output_codec_context | Codec context of the output file | |
[out] | data_present | Indicates whether data has been encoded |
Definition at line 665 of file transcode_aac.c.
Referenced by load_encode_and_write(), and main().
|
static |
Load one audio frame from the FIFO buffer, encode and write it to the output file.
fifo | Buffer used for temporary storage |
output_format_context | Format context of the output file |
output_codec_context | Codec context of the output file |
Definition at line 737 of file transcode_aac.c.
Referenced by main().
|
static |
Write the trailer of the output file container.
output_format_context | Format context of the output file |
Definition at line 777 of file transcode_aac.c.
Referenced by main().
Definition at line 788 of file transcode_aac.c.
|
static |
Definition at line 654 of file transcode_aac.c.
Referenced by aal_read_packet(), activate(), add_crc_to_array(), ape_read_header(), asf_read_marker(), asf_read_pts(), asf_read_seek(), asf_write_packet(), av_buffersrc_close(), av_parser_parse2(), build_frame_code(), compare_crc_in_array(), config_input(), consume_from_fifos(), create_frame(), crystalhd_decode_packet(), curves_init(), dat_read_packet(), decode_frame(), decode_frame_header(), decode_vop_header(), dhav_read_seek(), dirac_combine_frame(), dirac_gptopts(), display_end_segment(), dnn_classify_activate(), dnn_classify_flush_frame(), dnn_detect_activate(), dnn_detect_flush_frame(), do_subtitle_out(), draw_mandelbrot(), encode_audio_frame(), eval_pts(), ff_af_queue_remove(), ff_amf_receive_packet(), ff_avfilter_link_set_in_status(), ff_avfilter_link_set_out_status(), ff_inlink_evaluate_timeline_at_frame(), ff_mediacodec_dec_send(), ff_outlink_set_status(), ff_subtitles_queue_seek(), ff_update_link_current_pts(), ff_write_chained(), filter_frame(), find_next_delta_ts(), flac_read_timestamp(), flush(), flush_frame(), flush_packet(), flv_read_packet(), frame_list_add_frame(), framesync_advance(), framesync_inject_frame(), framesync_inject_status(), framesync_pts_extrapolate(), func_pts(), get_concatdec_select(), get_frame_internal(), get_input_packet(), get_pkt_pts(), get_pts(), get_vcd_padding_size(), guess_correct_pts(), handle_klv(), handle_metadata(), ifilter_send_eof(), interpolate(), ivr_read_packet(), librav1e_receive_packet(), load_input_picture(), mf_sample_get_pts(), microdvd_read_header(), mkv_add_cuepoint(), mkv_assemble_cues(), mov_flush_fragment(), mov_read_sidx(), mov_read_trun(), mpeg_mux_write_packet(), mpegps_read_dts(), mpegps_read_packet(), mpegps_read_pes_header(), mpegts_write_packet_internal(), mpegts_write_pes(), mpsub_read_header(), nut_read_timestamp(), ogg_calc_pts(), ogg_get_length(), ogg_gptopts(), ogg_read_packet(), ogg_read_timestamp(), ogg_write_packet_internal(), output_single_frame(), parse_forced_key_frames(), parse_presentation_segment(), parse_psfile(), plot_freqs(), pp_bnk_seek(), prepare_packet(), print_report(), queue_picture(), read_frame_internal(), read_packet(), read_part_of_packet(), read_seek(), read_trun_duration(), rkmpp_write_data(), rm_read_index(), rm_read_seek(), rv34_parse(), scan_file(), scc_write_packet(), scd_seek(), send_filter_eof(), send_silence(), set_clock(), set_clock_at(), sub2video_heartbeat(), sub2video_push_ref(), sub2video_update(), subtitle_thread(), sup_read_packet(), sup_write_packet(), swr_next_pts(), theora_packet(), try_push_frame(), update_initial_timestamps(), update_pts(), update_time(), update_video_pts(), v4l2_set_pts(), vc1t_read_packet(), video_thread(), vp8_gptopts(), vtenc_cm_to_avpacket(), write_pts(), xcbgrab_read_packet(), xfade_activate(), xfade_opencl_activate(), and yuv4_read_seek().