Libav
avcodec.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 
35 #ifdef HAVE_AV_CONFIG_H
36 #undef HAVE_AV_CONFIG_H
37 #endif
38 
39 #include "libavcodec/avcodec.h"
41 #include "libavutil/common.h"
42 #include "libavutil/imgutils.h"
43 #include "libavutil/mathematics.h"
44 #include "libavutil/samplefmt.h"
45 
46 #define INBUF_SIZE 4096
47 #define AUDIO_INBUF_SIZE 20480
48 #define AUDIO_REFILL_THRESH 4096
49 
50 /* check that a given sample format is supported by the encoder */
51 static int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt)
52 {
53  const enum AVSampleFormat *p = codec->sample_fmts;
54 
55  while (*p != AV_SAMPLE_FMT_NONE) {
56  if (*p == sample_fmt)
57  return 1;
58  p++;
59  }
60  return 0;
61 }
62 
63 /* just pick the highest supported samplerate */
64 static int select_sample_rate(AVCodec *codec)
65 {
66  const int *p;
67  int best_samplerate = 0;
68 
69  if (!codec->supported_samplerates)
70  return 44100;
71 
72  p = codec->supported_samplerates;
73  while (*p) {
74  best_samplerate = FFMAX(*p, best_samplerate);
75  p++;
76  }
77  return best_samplerate;
78 }
79 
80 /* select layout with the highest channel count */
81 static int select_channel_layout(AVCodec *codec)
82 {
83  const uint64_t *p;
84  uint64_t best_ch_layout = 0;
85  int best_nb_channels = 0;
86 
87  if (!codec->channel_layouts)
88  return AV_CH_LAYOUT_STEREO;
89 
90  p = codec->channel_layouts;
91  while (*p) {
93 
94  if (nb_channels > best_nb_channels) {
95  best_ch_layout = *p;
96  best_nb_channels = nb_channels;
97  }
98  p++;
99  }
100  return best_ch_layout;
101 }
102 
103 /*
104  * Audio encoding example
105  */
106 static void audio_encode_example(const char *filename)
107 {
108  AVCodec *codec;
109  AVCodecContext *c= NULL;
110  AVFrame *frame;
111  AVPacket pkt;
112  int i, j, k, ret, got_output;
113  int buffer_size;
114  FILE *f;
115  uint16_t *samples;
116  float t, tincr;
117 
118  printf("Audio encoding\n");
119 
120  /* find the MP2 encoder */
122  if (!codec) {
123  fprintf(stderr, "codec not found\n");
124  exit(1);
125  }
126 
127  c = avcodec_alloc_context3(codec);
128 
129  /* put sample parameters */
130  c->bit_rate = 64000;
131 
132  /* check that the encoder supports s16 pcm input */
134  if (!check_sample_fmt(codec, c->sample_fmt)) {
135  fprintf(stderr, "encoder does not support %s",
137  exit(1);
138  }
139 
140  /* select other audio parameters supported by the encoder */
141  c->sample_rate = select_sample_rate(codec);
144 
145  /* open it */
146  if (avcodec_open2(c, codec, NULL) < 0) {
147  fprintf(stderr, "could not open codec\n");
148  exit(1);
149  }
150 
151  f = fopen(filename, "wb");
152  if (!f) {
153  fprintf(stderr, "could not open %s\n", filename);
154  exit(1);
155  }
156 
157  /* frame containing input raw audio */
158  frame = av_frame_alloc();
159  if (!frame) {
160  fprintf(stderr, "could not allocate audio frame\n");
161  exit(1);
162  }
163 
164  frame->nb_samples = c->frame_size;
165  frame->format = c->sample_fmt;
166  frame->channel_layout = c->channel_layout;
167 
168  /* the codec gives us the frame size, in samples,
169  * we calculate the size of the samples buffer in bytes */
170  buffer_size = av_samples_get_buffer_size(NULL, c->channels, c->frame_size,
171  c->sample_fmt, 0);
172  samples = av_malloc(buffer_size);
173  if (!samples) {
174  fprintf(stderr, "could not allocate %d bytes for samples buffer\n",
175  buffer_size);
176  exit(1);
177  }
178  /* setup the data pointers in the AVFrame */
179  ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,
180  (const uint8_t*)samples, buffer_size, 0);
181  if (ret < 0) {
182  fprintf(stderr, "could not setup audio frame\n");
183  exit(1);
184  }
185 
186  /* encode a single tone sound */
187  t = 0;
188  tincr = 2 * M_PI * 440.0 / c->sample_rate;
189  for(i=0;i<200;i++) {
190  av_init_packet(&pkt);
191  pkt.data = NULL; // packet data will be allocated by the encoder
192  pkt.size = 0;
193 
194  for (j = 0; j < c->frame_size; j++) {
195  samples[2*j] = (int)(sin(t) * 10000);
196 
197  for (k = 1; k < c->channels; k++)
198  samples[2*j + k] = samples[2*j];
199  t += tincr;
200  }
201  /* encode the samples */
202  ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);
203  if (ret < 0) {
204  fprintf(stderr, "error encoding audio frame\n");
205  exit(1);
206  }
207  if (got_output) {
208  fwrite(pkt.data, 1, pkt.size, f);
209  av_packet_unref(&pkt);
210  }
211  }
212  fclose(f);
213 
214  av_freep(&samples);
215  av_frame_free(&frame);
217 }
218 
219 /*
220  * Audio decoding.
221  */
222 static void audio_decode_example(const char *outfilename, const char *filename)
223 {
224  AVCodec *codec;
225  AVCodecContext *c= NULL;
226  int len;
227  FILE *f, *outfile;
229  AVPacket avpkt;
230  AVFrame *decoded_frame = NULL;
231 
232  av_init_packet(&avpkt);
233 
234  printf("Audio decoding\n");
235 
236  /* find the MPEG audio decoder */
238  if (!codec) {
239  fprintf(stderr, "codec not found\n");
240  exit(1);
241  }
242 
243  c = avcodec_alloc_context3(codec);
244 
245  /* open it */
246  if (avcodec_open2(c, codec, NULL) < 0) {
247  fprintf(stderr, "could not open codec\n");
248  exit(1);
249  }
250 
251  f = fopen(filename, "rb");
252  if (!f) {
253  fprintf(stderr, "could not open %s\n", filename);
254  exit(1);
255  }
256  outfile = fopen(outfilename, "wb");
257  if (!outfile) {
258  av_free(c);
259  exit(1);
260  }
261 
262  /* decode until eof */
263  avpkt.data = inbuf;
264  avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
265 
266  while (avpkt.size > 0) {
267  int got_frame = 0;
268 
269  if (!decoded_frame) {
270  if (!(decoded_frame = av_frame_alloc())) {
271  fprintf(stderr, "out of memory\n");
272  exit(1);
273  }
274  }
275 
276  len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
277  if (len < 0) {
278  fprintf(stderr, "Error while decoding\n");
279  exit(1);
280  }
281  if (got_frame) {
282  /* if a frame has been decoded, output it */
283  int data_size = av_samples_get_buffer_size(NULL, c->channels,
284  decoded_frame->nb_samples,
285  c->sample_fmt, 1);
286  fwrite(decoded_frame->data[0], 1, data_size, outfile);
287  }
288  avpkt.size -= len;
289  avpkt.data += len;
290  if (avpkt.size < AUDIO_REFILL_THRESH) {
291  /* Refill the input buffer, to avoid trying to decode
292  * incomplete frames. Instead of this, one could also use
293  * a parser, or use a proper container format through
294  * libavformat. */
295  memmove(inbuf, avpkt.data, avpkt.size);
296  avpkt.data = inbuf;
297  len = fread(avpkt.data + avpkt.size, 1,
298  AUDIO_INBUF_SIZE - avpkt.size, f);
299  if (len > 0)
300  avpkt.size += len;
301  }
302  }
303 
304  fclose(outfile);
305  fclose(f);
306 
308  av_frame_free(&decoded_frame);
309 }
310 
311 /*
312  * Video encoding example
313  */
314 static void video_encode_example(const char *filename)
315 {
316  AVCodec *codec;
317  AVCodecContext *c= NULL;
318  int i, ret, x, y, got_output;
319  FILE *f;
320  AVFrame *picture;
321  AVPacket pkt;
322  uint8_t endcode[] = { 0, 0, 1, 0xb7 };
323 
324  printf("Video encoding\n");
325 
326  /* find the mpeg1video encoder */
328  if (!codec) {
329  fprintf(stderr, "codec not found\n");
330  exit(1);
331  }
332 
333  c = avcodec_alloc_context3(codec);
334  picture = av_frame_alloc();
335 
336  /* put sample parameters */
337  c->bit_rate = 400000;
338  /* resolution must be a multiple of two */
339  c->width = 352;
340  c->height = 288;
341  /* frames per second */
342  c->time_base= (AVRational){1,25};
343  c->gop_size = 10; /* emit one intra frame every ten frames */
344  c->max_b_frames=1;
346 
347  /* open it */
348  if (avcodec_open2(c, codec, NULL) < 0) {
349  fprintf(stderr, "could not open codec\n");
350  exit(1);
351  }
352 
353  f = fopen(filename, "wb");
354  if (!f) {
355  fprintf(stderr, "could not open %s\n", filename);
356  exit(1);
357  }
358 
359  ret = av_image_alloc(picture->data, picture->linesize, c->width, c->height,
360  c->pix_fmt, 32);
361  if (ret < 0) {
362  fprintf(stderr, "could not alloc raw picture buffer\n");
363  exit(1);
364  }
365  picture->format = c->pix_fmt;
366  picture->width = c->width;
367  picture->height = c->height;
368 
369  /* encode 1 second of video */
370  for(i=0;i<25;i++) {
371  av_init_packet(&pkt);
372  pkt.data = NULL; // packet data will be allocated by the encoder
373  pkt.size = 0;
374 
375  fflush(stdout);
376  /* prepare a dummy image */
377  /* Y */
378  for(y=0;y<c->height;y++) {
379  for(x=0;x<c->width;x++) {
380  picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
381  }
382  }
383 
384  /* Cb and Cr */
385  for(y=0;y<c->height/2;y++) {
386  for(x=0;x<c->width/2;x++) {
387  picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
388  picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
389  }
390  }
391 
392  picture->pts = i;
393 
394  /* encode the image */
395  ret = avcodec_encode_video2(c, &pkt, picture, &got_output);
396  if (ret < 0) {
397  fprintf(stderr, "error encoding frame\n");
398  exit(1);
399  }
400 
401  if (got_output) {
402  printf("encoding frame %3d (size=%5d)\n", i, pkt.size);
403  fwrite(pkt.data, 1, pkt.size, f);
404  av_packet_unref(&pkt);
405  }
406  }
407 
408  /* get the delayed frames */
409  for (got_output = 1; got_output; i++) {
410  fflush(stdout);
411 
412  ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
413  if (ret < 0) {
414  fprintf(stderr, "error encoding frame\n");
415  exit(1);
416  }
417 
418  if (got_output) {
419  printf("encoding frame %3d (size=%5d)\n", i, pkt.size);
420  fwrite(pkt.data, 1, pkt.size, f);
421  av_packet_unref(&pkt);
422  }
423  }
424 
425  /* add sequence end code to have a real MPEG file */
426  fwrite(endcode, 1, sizeof(endcode), f);
427  fclose(f);
428 
430  av_freep(&picture->data[0]);
431  av_frame_free(&picture);
432  printf("\n");
433 }
434 
435 /*
436  * Video decoding example
437  */
438 
439 static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize,
440  char *filename)
441 {
442  FILE *f;
443  int i;
444 
445  f=fopen(filename,"w");
446  fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255);
447  for(i=0;i<ysize;i++)
448  fwrite(buf + i * wrap,1,xsize,f);
449  fclose(f);
450 }
451 
452 static void video_decode_example(const char *outfilename, const char *filename)
453 {
454  AVCodec *codec;
455  AVCodecContext *c= NULL;
456  int frame, got_picture, len;
457  FILE *f;
458  AVFrame *picture;
460  char buf[1024];
461  AVPacket avpkt;
462 
463  av_init_packet(&avpkt);
464 
465  /* set end of buffer to 0 (this ensures that no overreading happens for damaged MPEG streams) */
466  memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);
467 
468  printf("Video decoding\n");
469 
470  /* find the MPEG-1 video decoder */
472  if (!codec) {
473  fprintf(stderr, "codec not found\n");
474  exit(1);
475  }
476 
477  c = avcodec_alloc_context3(codec);
478  picture = av_frame_alloc();
479 
481  c->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames
482 
483  /* For some codecs, such as msmpeg4 and mpeg4, width and height
484  MUST be initialized there because this information is not
485  available in the bitstream. */
486 
487  /* open it */
488  if (avcodec_open2(c, codec, NULL) < 0) {
489  fprintf(stderr, "could not open codec\n");
490  exit(1);
491  }
492 
493  /* the codec gives us the frame size, in samples */
494 
495  f = fopen(filename, "rb");
496  if (!f) {
497  fprintf(stderr, "could not open %s\n", filename);
498  exit(1);
499  }
500 
501  frame = 0;
502  for(;;) {
503  avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
504  if (avpkt.size == 0)
505  break;
506 
507  /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
508  and this is the only method to use them because you cannot
509  know the compressed data size before analysing it.
510 
511  BUT some other codecs (msmpeg4, mpeg4) are inherently frame
512  based, so you must call them with all the data for one
513  frame exactly. You must also initialize 'width' and
514  'height' before initializing them. */
515 
516  /* NOTE2: some codecs allow the raw parameters (frame size,
517  sample rate) to be changed at any frame. We handle this, so
518  you should also take care of it */
519 
520  /* here, we use a stream based decoder (mpeg1video), so we
521  feed decoder and see if it could decode a frame */
522  avpkt.data = inbuf;
523  while (avpkt.size > 0) {
524  len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
525  if (len < 0) {
526  fprintf(stderr, "Error while decoding frame %d\n", frame);
527  exit(1);
528  }
529  if (got_picture) {
530  printf("saving frame %3d\n", frame);
531  fflush(stdout);
532 
533  /* the picture is allocated by the decoder. no need to
534  free it */
535  snprintf(buf, sizeof(buf), outfilename, frame);
536  pgm_save(picture->data[0], picture->linesize[0],
537  c->width, c->height, buf);
538  frame++;
539  }
540  avpkt.size -= len;
541  avpkt.data += len;
542  }
543  }
544 
545  /* Some codecs, such as MPEG, transmit the I- and P-frame with a
546  latency of one frame. You must do the following to have a
547  chance to get the last frame of the video. */
548  avpkt.data = NULL;
549  avpkt.size = 0;
550  len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
551  if (got_picture) {
552  printf("saving last frame %3d\n", frame);
553  fflush(stdout);
554 
555  /* the picture is allocated by the decoder. no need to
556  free it */
557  snprintf(buf, sizeof(buf), outfilename, frame);
558  pgm_save(picture->data[0], picture->linesize[0],
559  c->width, c->height, buf);
560  frame++;
561  }
562 
563  fclose(f);
564 
566  av_frame_free(&picture);
567  printf("\n");
568 }
569 
570 int main(int argc, char **argv)
571 {
572  const char *filename;
573 
574  /* register all the codecs */
576 
577  if (argc <= 1) {
578  audio_encode_example("/tmp/test.mp2");
579  audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
580 
581  video_encode_example("/tmp/test.mpg");
582  filename = "/tmp/test.mpg";
583  } else {
584  filename = argv[1];
585  }
586 
587  // audio_decode_example("/tmp/test.sw", filename);
588  video_decode_example("/tmp/test%d.pgm", filename);
589 
590  return 0;
591 }
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:2010
static void video_decode_example(const char *outfilename, const char *filename)
Definition: avcodec.c:452
static void video_encode_example(const char *filename)
Definition: avcodec.c:314
misc image utilities
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:182
attribute_deprecated int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
Definition: utils.c:1624
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:1679
int size
Definition: avcodec.h:1347
attribute_deprecated int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
Definition: utils.c:1270
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
#define AV_CH_LAYOUT_STEREO
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
Definition: allcodecs.c:61
static void audio_decode_example(const char *outfilename, const char *filename)
Definition: avcodec.c:222
int main(int argc, char **argv)
Definition: avcodec.c:570
AVCodec.
Definition: avcodec.h:3120
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1535
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill audio frame data and linesize.
Definition: utils.c:300
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2160
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
#define AUDIO_INBUF_SIZE
Definition: avcodec.c:47
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)
Definition: avcodec.c:439
uint8_t * data
Definition: avcodec.h:1346
static int select_channel_layout(AVCodec *codec)
Definition: avcodec.c:81
const uint64_t * channel_layouts
array of support channel layouts, or NULL if unknown. array is terminated by 0
Definition: avcodec.h:3144
int width
width and height of the video frame
Definition: frame.h:179
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
int capabilities
Codec capabilities.
Definition: avcodec.h:3139
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1503
#define wrap(func)
Definition: neontest.h:62
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
#define FFMAX(a, b)
Definition: common.h:64
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2203
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:294
int bit_rate
the average bitrate
Definition: avcodec.h:1473
audio channel layout utility functions
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:136
int width
picture width / height.
Definition: avcodec.h:1580
static int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt)
Definition: avcodec.c:51
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:191
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2172
NULL
Definition: eval.c:55
Libavcodec external API header.
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:60
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
Definition: options.c:151
int sample_rate
samples per second
Definition: avcodec.h:2152
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
main external API structure.
Definition: avcodec.h:1409
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: utils.c:2029
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:347
#define INBUF_SIZE
Definition: avcodec.c:46
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:108
rational number numerator/denominator
Definition: rational.h:43
attribute_deprecated int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: utils.c:1384
#define AUDIO_REFILL_THRESH
Definition: avcodec.c:48
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:850
#define AV_CODEC_CAP_TRUNCATED
Definition: avcodec.h:839
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1606
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:59
static int select_sample_rate(AVCodec *codec)
Definition: avcodec.c:64
common internal and external API header
signed 16 bits
Definition: samplefmt.h:63
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:31
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
int len
int channels
number of audio channels
Definition: avcodec.h:2153
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0 ...
Definition: avcodec.h:3142
static void audio_encode_example(const char *filename)
Definition: avcodec.c:106
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
Definition: avcodec.h:772
int height
Definition: frame.h:179
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3143
int nb_channels
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
Definition: utils.c:1559
This structure stores compressed data.
Definition: avcodec.h:1323
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:184
FILE * outfile
Definition: audiogen.c:96