39 #define AUDIO_INBUF_SIZE 20480 40 #define AUDIO_REFILL_THRESH 4096 51 fprintf(stderr,
"Error submitting the packet to the decoder\n");
61 fprintf(stderr,
"Error during decoding\n");
67 fprintf(stderr,
"Failed to calculate data size\n");
71 for (ch = 0; ch < dec_ctx->
channels; ch++)
72 fwrite(frame->
data[ch] + data_size*i, 1, data_size, outfile);
76 int main(
int argc,
char **argv)
78 const char *outfilename, *filename;
91 fprintf(stderr,
"Usage: %s <input file> <output file>\n", argv[0]);
95 outfilename = argv[2];
102 fprintf(stderr,
"Codec not found\n");
108 fprintf(stderr,
"Parser not found\n");
114 fprintf(stderr,
"Could not allocate audio codec context\n");
120 fprintf(stderr,
"Could not open codec\n");
124 f = fopen(filename,
"rb");
126 fprintf(stderr,
"Could not open %s\n", filename);
129 outfile = fopen(outfilename,
"wb");
139 while (data_size > 0) {
140 if (!decoded_frame) {
142 fprintf(stderr,
"Could not allocate audio frame\n");
151 fprintf(stderr,
"Error while parsing\n");
158 decode(c, pkt, decoded_frame, outfile);
161 memmove(inbuf, data, data_size);
163 len = fread(data + data_size, 1,
173 decode(c, pkt, decoded_frame, outfile);
This structure describes decoded (raw) audio or video data.
Memory handling functions.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AUDIO_REFILL_THRESH
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
reference-counted frame API
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
void av_parser_close(AVCodecParserContext *s)
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
AVCodecParserContext * av_parser_init(int codec_id)
Libavcodec external API header.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void av_free(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static AVCodecContext * dec_ctx
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int channels
number of audio channels
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int main(int argc, char **argv)
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_NOPTS_VALUE
Undefined timestamp value.