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

Function main

doc/examples/resample_audio.c:85–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85int main(int argc, char **argv)
86{
87 AVChannelLayout src_ch_layout = AV_CHANNEL_LAYOUT_STEREO, dst_ch_layout = AV_CHANNEL_LAYOUT_SURROUND;
88 int src_rate = 48000, dst_rate = 44100;
89 uint8_t **src_data = NULL, **dst_data = NULL;
90 int src_nb_channels = 0, dst_nb_channels = 0;
91 int src_linesize, dst_linesize;
92 int src_nb_samples = 1024, dst_nb_samples, max_dst_nb_samples;
93 enum AVSampleFormat src_sample_fmt = AV_SAMPLE_FMT_DBL, dst_sample_fmt = AV_SAMPLE_FMT_S16;
94 const char *dst_filename = NULL;
95 FILE *dst_file;
96 int dst_bufsize;
97 const char *fmt;
98 struct SwrContext *swr_ctx;
99 char buf[64];
100 double t;
101 int ret;
102
103 if (argc != 2) {
104 fprintf(stderr, "Usage: %s output_file\n"
105 "API example program to show how to resample an audio stream with libswresample.\n"
106 "This program generates a series of audio frames, resamples them to a specified "
107 "output format and rate and saves them to an output file named output_file.\n",
108 argv[0]);
109 exit(1);
110 }
111 dst_filename = argv[1];
112
113 dst_file = fopen(dst_filename, "wb");
114 if (!dst_file) {
115 fprintf(stderr, "Could not open destination file %s\n", dst_filename);
116 exit(1);
117 }
118
119 /* create resampler context */
120 swr_ctx = swr_alloc();
121 if (!swr_ctx) {
122 fprintf(stderr, "Could not allocate resampler context\n");
123 ret = AVERROR(ENOMEM);
124 goto end;
125 }
126
127 /* set options */
128 av_opt_set_chlayout(swr_ctx, "in_chlayout", &src_ch_layout, 0);
129 av_opt_set_int(swr_ctx, "in_sample_rate", src_rate, 0);
130 av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", src_sample_fmt, 0);
131
132 av_opt_set_chlayout(swr_ctx, "out_chlayout", &dst_ch_layout, 0);
133 av_opt_set_int(swr_ctx, "out_sample_rate", dst_rate, 0);
134 av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", dst_sample_fmt, 0);
135
136 /* initialize the resampling context */
137 if ((ret = swr_init(swr_ctx)) < 0) {
138 fprintf(stderr, "Failed to initialize the resampling context\n");
139 goto end;
140 }
141
142 /* allocate source and destination samples buffers */

Callers

nothing calls this directly

Calls 15

swr_allocFunction · 0.85
av_opt_set_chlayoutFunction · 0.85
av_opt_set_intFunction · 0.85
av_opt_set_sample_fmtFunction · 0.85
swr_initFunction · 0.85
fill_samplesFunction · 0.85
swr_get_delayFunction · 0.85
av_freepFunction · 0.85
av_samples_allocFunction · 0.85
swr_convertFunction · 0.85

Tested by

no test coverage detected