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

Function main

doc/examples/decode_audio.c:106–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106int main(int argc, char **argv)
107{
108 const char *outfilename, *filename;
109 const AVCodec *codec;
110 AVCodecContext *c= NULL;
111 AVCodecParserContext *parser = NULL;
112 int len, ret;
113 FILE *f, *outfile;
114 uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
115 uint8_t *data;
116 size_t data_size;
117 AVPacket *pkt;
118 AVFrame *decoded_frame = NULL;
119 enum AVSampleFormat sfmt;
120 int n_channels = 0;
121 const char *fmt;
122
123 if (argc <= 2) {
124 fprintf(stderr, "Usage: %s <input file> <output file>\n", argv[0]);
125 exit(0);
126 }
127 filename = argv[1];
128 outfilename = argv[2];
129
130 pkt = av_packet_alloc();
131 if (!pkt) {
132 fprintf(stderr, "Could not allocate AVPacket\n");
133 exit(1); /* or proper cleanup and returning */
134 }
135
136 /* find the MPEG audio decoder */
137 codec = avcodec_find_decoder(AV_CODEC_ID_MP2);
138 if (!codec) {
139 fprintf(stderr, "Codec not found\n");
140 exit(1);
141 }
142
143 parser = av_parser_init(codec->id);
144 if (!parser) {
145 fprintf(stderr, "Parser not found\n");
146 exit(1);
147 }
148
149 c = avcodec_alloc_context3(codec);
150 if (!c) {
151 fprintf(stderr, "Could not allocate audio codec context\n");
152 exit(1);
153 }
154
155 /* open it */
156 if (avcodec_open2(c, codec, NULL) < 0) {
157 fprintf(stderr, "Could not open codec\n");
158 exit(1);
159 }
160
161 f = fopen(filename, "rb");
162 if (!f) {
163 fprintf(stderr, "Could not open %s\n", filename);

Callers

nothing calls this directly

Calls 15

av_packet_allocFunction · 0.85
avcodec_find_decoderFunction · 0.85
av_parser_initFunction · 0.85
avcodec_alloc_context3Function · 0.85
avcodec_open2Function · 0.85
av_frame_allocFunction · 0.85
av_parser_parse2Function · 0.85
av_sample_fmt_is_planarFunction · 0.85
av_get_sample_fmt_nameFunction · 0.85
av_get_packed_sample_fmtFunction · 0.85
avcodec_free_contextFunction · 0.85
av_parser_closeFunction · 0.85

Tested by

no test coverage detected