Libav
output.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Fabrice Bellard
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <math.h>
36 
37 #include "libavutil/mathematics.h"
38 #include "libavformat/avformat.h"
39 #include "libswscale/swscale.h"
40 
41 /* 5 seconds stream duration */
42 #define STREAM_DURATION 5.0
43 #define STREAM_FRAME_RATE 25 /* 25 images/s */
44 #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
45 #define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
46 
47 static int sws_flags = SWS_BICUBIC;
48 
49 /**************************************************************/
50 /* audio output */
51 
52 static float t, tincr, tincr2;
53 static int16_t *samples;
55 
56 /*
57  * add an audio output stream
58  */
60 {
61  AVCodecContext *c;
62  AVStream *st;
63  AVCodec *codec;
64 
65  /* find the audio encoder */
66  codec = avcodec_find_encoder(codec_id);
67  if (!codec) {
68  fprintf(stderr, "codec not found\n");
69  exit(1);
70  }
71 
72  st = avformat_new_stream(oc, codec);
73  if (!st) {
74  fprintf(stderr, "Could not alloc stream\n");
75  exit(1);
76  }
77 
78  c = st->codec;
79 
80  /* put sample parameters */
82  c->bit_rate = 64000;
83  c->sample_rate = 44100;
84  c->channels = 2;
85 
86  // some formats want stream headers to be separate
87  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
89 
90  return st;
91 }
92 
93 static void open_audio(AVFormatContext *oc, AVStream *st)
94 {
95  AVCodecContext *c;
96 
97  c = st->codec;
98 
99  /* open it */
100  if (avcodec_open2(c, NULL, NULL) < 0) {
101  fprintf(stderr, "could not open codec\n");
102  exit(1);
103  }
104 
105  /* init signal generator */
106  t = 0;
107  tincr = 2 * M_PI * 110.0 / c->sample_rate;
108  /* increment frequency by 110 Hz per second */
109  tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;
110 
112  audio_input_frame_size = 10000;
113  else
117  c->channels);
118 }
119 
120 /* Prepare a 16 bit dummy audio frame of 'frame_size' samples and
121  * 'nb_channels' channels. */
122 static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
123 {
124  int j, i, v;
125  int16_t *q;
126 
127  q = samples;
128  for (j = 0; j < frame_size; j++) {
129  v = (int)(sin(t) * 10000);
130  for (i = 0; i < nb_channels; i++)
131  *q++ = v;
132  t += tincr;
133  tincr += tincr2;
134  }
135 }
136 
138 {
139  AVCodecContext *c;
140  AVPacket pkt = { 0 }; // data and size must be 0;
141  AVFrame *frame = av_frame_alloc();
142  int got_packet;
143 
144  av_init_packet(&pkt);
145  c = st->codec;
146 
150  (uint8_t *)samples,
153  c->channels, 1);
154 
155  avcodec_encode_audio2(c, &pkt, frame, &got_packet);
156  if (!got_packet)
157  return;
158 
159  pkt.stream_index = st->index;
160 
161  /* Write the compressed frame to the media file. */
162  if (av_interleaved_write_frame(oc, &pkt) != 0) {
163  fprintf(stderr, "Error while writing audio frame\n");
164  exit(1);
165  }
166  av_frame_free(&frame);
167 }
168 
169 static void close_audio(AVFormatContext *oc, AVStream *st)
170 {
171  avcodec_close(st->codec);
172 
173  av_free(samples);
174 }
175 
176 /**************************************************************/
177 /* video output */
178 
180 static int frame_count;
181 
182 /* Add a video output stream. */
184 {
185  AVCodecContext *c;
186  AVStream *st;
187  AVCodec *codec;
188 
189  /* find the video encoder */
190  codec = avcodec_find_encoder(codec_id);
191  if (!codec) {
192  fprintf(stderr, "codec not found\n");
193  exit(1);
194  }
195 
196  st = avformat_new_stream(oc, codec);
197  if (!st) {
198  fprintf(stderr, "Could not alloc stream\n");
199  exit(1);
200  }
201 
202  c = st->codec;
203 
204  /* Put sample parameters. */
205  c->bit_rate = 400000;
206  /* Resolution must be a multiple of two. */
207  c->width = 352;
208  c->height = 288;
209  /* timebase: This is the fundamental unit of time (in seconds) in terms
210  * of which frame timestamps are represented. For fixed-fps content,
211  * timebase should be 1/framerate and timestamp increments should be
212  * identical to 1. */
214  c->time_base.num = 1;
215  c->gop_size = 12; /* emit one intra frame every twelve frames at most */
216  c->pix_fmt = STREAM_PIX_FMT;
217  if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
218  /* just for testing, we also add B frames */
219  c->max_b_frames = 2;
220  }
221  if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
222  /* Needed to avoid using macroblocks in which some coeffs overflow.
223  * This does not happen with normal video, it just happens here as
224  * the motion of the chroma plane does not match the luma plane. */
225  c->mb_decision = 2;
226  }
227  /* Some formats want stream headers to be separate. */
228  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
230 
231  return st;
232 }
233 
235 {
236  AVFrame *picture;
237  uint8_t *picture_buf;
238  int size;
239 
240  picture = av_frame_alloc();
241  if (!picture)
242  return NULL;
243  size = avpicture_get_size(pix_fmt, width, height);
244  picture_buf = av_malloc(size);
245  if (!picture_buf) {
246  av_free(picture);
247  return NULL;
248  }
249  avpicture_fill((AVPicture *)picture, picture_buf,
250  pix_fmt, width, height);
251  return picture;
252 }
253 
254 static void open_video(AVFormatContext *oc, AVStream *st)
255 {
256  AVCodecContext *c;
257 
258  c = st->codec;
259 
260  /* open the codec */
261  if (avcodec_open2(c, NULL, NULL) < 0) {
262  fprintf(stderr, "could not open codec\n");
263  exit(1);
264  }
265 
266  /* Allocate the encoded raw picture. */
267  picture = alloc_picture(c->pix_fmt, c->width, c->height);
268  if (!picture) {
269  fprintf(stderr, "Could not allocate picture\n");
270  exit(1);
271  }
272 
273  /* If the output format is not YUV420P, then a temporary YUV420P
274  * picture is needed too. It is then converted to the required
275  * output format. */
276  tmp_picture = NULL;
277  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
278  tmp_picture = alloc_picture(AV_PIX_FMT_YUV420P, c->width, c->height);
279  if (!tmp_picture) {
280  fprintf(stderr, "Could not allocate temporary picture\n");
281  exit(1);
282  }
283  }
284 }
285 
286 /* Prepare a dummy image. */
287 static void fill_yuv_image(AVFrame *pict, int frame_index,
288  int width, int height)
289 {
290  int x, y, i;
291 
292  i = frame_index;
293 
294  /* Y */
295  for (y = 0; y < height; y++)
296  for (x = 0; x < width; x++)
297  pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3;
298 
299  /* Cb and Cr */
300  for (y = 0; y < height / 2; y++) {
301  for (x = 0; x < width / 2; x++) {
302  pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2;
303  pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5;
304  }
305  }
306 }
307 
309 {
310  int ret;
311  AVCodecContext *c;
312  static struct SwsContext *img_convert_ctx;
313 
314  c = st->codec;
315 
316  if (frame_count >= STREAM_NB_FRAMES) {
317  /* No more frames to compress. The codec has a latency of a few
318  * frames if using B-frames, so we get the last frames by
319  * passing the same picture again. */
320  } else {
321  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
322  /* as we only generate a YUV420P picture, we must convert it
323  * to the codec pixel format if needed */
324  if (img_convert_ctx == NULL) {
325  img_convert_ctx = sws_getContext(c->width, c->height,
327  c->width, c->height,
328  c->pix_fmt,
329  sws_flags, NULL, NULL, NULL);
330  if (img_convert_ctx == NULL) {
331  fprintf(stderr,
332  "Cannot initialize the conversion context\n");
333  exit(1);
334  }
335  }
336  fill_yuv_image(tmp_picture, frame_count, c->width, c->height);
337  sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize,
338  0, c->height, picture->data, picture->linesize);
339  } else {
340  fill_yuv_image(picture, frame_count, c->width, c->height);
341  }
342  }
343 
344  if (oc->oformat->flags & AVFMT_RAWPICTURE) {
345  /* Raw video case - the API will change slightly in the near
346  * future for that. */
347  AVPacket pkt;
348  av_init_packet(&pkt);
349 
350  pkt.flags |= AV_PKT_FLAG_KEY;
351  pkt.stream_index = st->index;
352  pkt.data = (uint8_t *)picture;
353  pkt.size = sizeof(AVPicture);
354 
355  ret = av_interleaved_write_frame(oc, &pkt);
356  } else {
357  AVPacket pkt = { 0 };
358  int got_packet;
359  av_init_packet(&pkt);
360 
361  /* encode the image */
362  ret = avcodec_encode_video2(c, &pkt, picture, &got_packet);
363  /* If size is zero, it means the image was buffered. */
364  if (!ret && got_packet && pkt.size) {
365  if (pkt.pts != AV_NOPTS_VALUE) {
366  pkt.pts = av_rescale_q(pkt.pts,
367  c->time_base, st->time_base);
368  }
369  if (pkt.dts != AV_NOPTS_VALUE) {
370  pkt.dts = av_rescale_q(pkt.dts,
371  c->time_base, st->time_base);
372  }
373  pkt.stream_index = st->index;
374 
375  /* Write the compressed frame to the media file. */
376  ret = av_interleaved_write_frame(oc, &pkt);
377  } else {
378  ret = 0;
379  }
380  }
381  if (ret != 0) {
382  fprintf(stderr, "Error while writing video frame\n");
383  exit(1);
384  }
385  frame_count++;
386 }
387 
388 static void close_video(AVFormatContext *oc, AVStream *st)
389 {
390  avcodec_close(st->codec);
391  av_free(picture->data[0]);
392  av_free(picture);
393  if (tmp_picture) {
394  av_free(tmp_picture->data[0]);
395  av_free(tmp_picture);
396  }
397 }
398 
399 /**************************************************************/
400 /* media file output */
401 
402 int main(int argc, char **argv)
403 {
404  const char *filename;
405  AVOutputFormat *fmt;
406  AVFormatContext *oc;
407  AVStream *audio_st, *video_st;
408  double audio_pts, video_pts;
409  int i;
410 
411  /* Initialize libavcodec, and register all codecs and formats. */
412  av_register_all();
413 
414  if (argc != 2) {
415  printf("usage: %s output_file\n"
416  "API example program to output a media file with libavformat.\n"
417  "The output format is automatically guessed according to the file extension.\n"
418  "Raw images can also be output by using '%%d' in the filename\n"
419  "\n", argv[0]);
420  return 1;
421  }
422 
423  filename = argv[1];
424 
425  /* Autodetect the output format from the name. default is MPEG. */
426  fmt = av_guess_format(NULL, filename, NULL);
427  if (!fmt) {
428  printf("Could not deduce output format from file extension: using MPEG.\n");
429  fmt = av_guess_format("mpeg", NULL, NULL);
430  }
431  if (!fmt) {
432  fprintf(stderr, "Could not find suitable output format\n");
433  return 1;
434  }
435 
436  /* Allocate the output media context. */
437  oc = avformat_alloc_context();
438  if (!oc) {
439  fprintf(stderr, "Memory error\n");
440  return 1;
441  }
442  oc->oformat = fmt;
443  snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
444 
445  /* Add the audio and video streams using the default format codecs
446  * and initialize the codecs. */
447  video_st = NULL;
448  audio_st = NULL;
449  if (fmt->video_codec != AV_CODEC_ID_NONE) {
450  video_st = add_video_stream(oc, fmt->video_codec);
451  }
452  if (fmt->audio_codec != AV_CODEC_ID_NONE) {
453  audio_st = add_audio_stream(oc, fmt->audio_codec);
454  }
455 
456  /* Now that all the parameters are set, we can open the audio and
457  * video codecs and allocate the necessary encode buffers. */
458  if (video_st)
459  open_video(oc, video_st);
460  if (audio_st)
461  open_audio(oc, audio_st);
462 
463  av_dump_format(oc, 0, filename, 1);
464 
465  /* open the output file, if needed */
466  if (!(fmt->flags & AVFMT_NOFILE)) {
467  if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) {
468  fprintf(stderr, "Could not open '%s'\n", filename);
469  return 1;
470  }
471  }
472 
473  /* Write the stream header, if any. */
475 
476  for (;;) {
477  /* Compute current audio and video time. */
478  if (audio_st)
479  audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
480  else
481  audio_pts = 0.0;
482 
483  if (video_st)
484  video_pts = (double)video_st->pts.val * video_st->time_base.num /
485  video_st->time_base.den;
486  else
487  video_pts = 0.0;
488 
489  if ((!audio_st || audio_pts >= STREAM_DURATION) &&
490  (!video_st || video_pts >= STREAM_DURATION))
491  break;
492 
493  /* write interleaved audio and video frames */
494  if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
495  write_audio_frame(oc, audio_st);
496  } else {
497  write_video_frame(oc, video_st);
498  }
499  }
500 
501  /* Write the trailer, if any. The trailer must be written before you
502  * close the CodecContexts open when you wrote the header; otherwise
503  * av_write_trailer() may try to use memory that was freed on
504  * av_codec_close(). */
505  av_write_trailer(oc);
506 
507  /* Close each codec. */
508  if (video_st)
509  close_video(oc, video_st);
510  if (audio_st)
511  close_audio(oc, audio_st);
512 
513  /* Free the streams. */
514  for (i = 0; i < oc->nb_streams; i++) {
515  av_freep(&oc->streams[i]->codec);
516  av_freep(&oc->streams[i]);
517  }
518 
519  if (!(fmt->flags & AVFMT_NOFILE))
520  /* Close the output file. */
521  avio_close(oc->pb);
522 
523  /* free the stream */
524  av_free(oc);
525 
526  return 0;
527 }
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:772
const struct AVCodec * codec
Definition: avcodec.h:1063
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
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: utils.c:1654
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:616
#define SWS_BICUBIC
Definition: swscale.h:59
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:798
int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
Definition: mux.c:302
int avpicture_fill(AVPicture *picture, uint8_t *ptr, enum AVPixelFormat pix_fmt, int width, int height)
Fill in the AVPicture fields.
Definition: avpicture.c:34
static AVFrame * picture
Definition: output.c:179
static AVStream * add_video_stream(AVFormatContext *oc, enum AVCodecID codec_id)
Definition: output.c:183
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:1302
enum AVCodecID video_codec
default video codec
Definition: avformat.h:448
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:684
int size
Definition: avcodec.h:974
static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
Definition: output.c:122
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:293
static float tincr2
Definition: output.c:52
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
static int16_t * samples
Definition: output.c:53
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
Definition: utils.c:1194
signed 16 bits
Definition: samplefmt.h:52
four components are given, that's all.
Definition: avcodec.h:2950
AVCodec.
Definition: avcodec.h:2755
static void write_video_frame(AVFormatContext *oc, AVStream *st)
Definition: output.c:308
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1173
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:198
Format I/O context.
Definition: avformat.h:871
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:291
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1787
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH, AVFMT_TS_NONSTRICT
Definition: avformat.h:456
uint8_t
#define STREAM_DURATION
Definition: output.c:42
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:43
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:684
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:935
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: utils.c:1292
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:98
uint8_t * data
Definition: avcodec.h:973
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Allocate and return an SwsContext.
Definition: utils.c:1315
external api for the swscale stuff
static float t
Definition: output.c:52
static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height)
Definition: output.c:287
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:890
static void open_audio(AVFormatContext *oc, AVStream *st)
Definition: output.c:93
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1023
static void close_audio(AVFormatContext *oc, AVStream *st)
Definition: output.c:169
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:122
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Definition: utils.c:2875
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
Definition: utils.c:1590
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:105
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
static AVStream * add_audio_stream(AVFormatContext *oc, enum AVCodecID codec_id)
Definition: output.c:59
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:55
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:794
int capabilities
Codec capabilities.
Definition: avcodec.h:2774
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1142
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:2662
enum AVCodecID codec_id
Definition: mov_chan.c:432
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:702
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:923
int bit_rate
the average bitrate
Definition: avcodec.h:1112
char filename[1024]
input or output filename
Definition: avformat.h:943
static AVFrame * tmp_picture
Definition: output.c:179
int width
picture width / height.
Definition: avcodec.h:1217
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:406
int main(int argc, char **argv)
Definition: output.c:402
static void close_video(AVFormatContext *oc, AVStream *st)
Definition: output.c:388
static void write_audio_frame(AVFormatContext *oc, AVStream *st)
Definition: output.c:137
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition: format.c:118
int mb_decision
macroblock decision mode
Definition: avcodec.h:1571
enum AVPixelFormat pix_fmt
Definition: movenc.c:821
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
static int frame_count
Definition: output.c:180
if(ac->has_optimized_func)
static int sws_flags
Definition: output.c:47
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:95
Stream structure.
Definition: avformat.h:683
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1799
NULL
Definition: eval.c:55
static int width
Definition: utils.c:156
#define STREAM_PIX_FMT
Definition: output.c:45
enum AVCodecID codec_id
Definition: avcodec.h:1065
int sample_rate
samples per second
Definition: avcodec.h:1779
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
AVIOContext * pb
I/O context.
Definition: avformat.h:913
#define AVFMT_RAWPICTURE
Format wants AVPicture structure for raw picture data.
Definition: avformat.h:403
main external API structure.
Definition: avcodec.h:1054
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst...
static AVFrame * alloc_picture(enum AVPixelFormat pix_fmt, int width, int height)
Definition: output.c:234
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: utils.c:872
int64_t val
Definition: avformat.h:377
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:113
static void open_video(AVFormatContext *oc, AVStream *st)
Definition: output.c:254
int height
Definition: gxfenc.c:72
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1238
Main libavformat public API header.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:400
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:46
int den
denominator
Definition: rational.h:45
static int audio_input_frame_size
Definition: output.c:54
struct AVFrac pts
encoding: pts generation when outputting stream
Definition: avformat.h:708
int channels
number of audio channels
Definition: avcodec.h:1780
enum AVCodecID audio_codec
default audio codec
Definition: avformat.h:447
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
Calculate the size in bytes that a picture of the given width and height would occupy if stored in th...
Definition: avpicture.c:85
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:672
static float tincr
Definition: output.c:52
int nb_channels
int stream_index
Definition: avcodec.h:975
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:719
#define STREAM_FRAME_RATE
Definition: output.c:43
#define STREAM_NB_FRAMES
Definition: output.c:44
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
This structure stores compressed data.
Definition: avcodec.h:950
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:51
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:151
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228