muxing.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 
23 /**
24  * @file
25  * libavformat API example.
26  *
27  * Output a media file in any supported libavformat format.
28  * The default codecs are used.
29  * @example doc/examples/muxing.c
30  */
31 
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 200.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 /* Add an output stream. */
58  enum AVCodecID codec_id)
59 {
61  AVStream *st;
62 
63  /* find the encoder */
64  *codec = avcodec_find_encoder(codec_id);
65  if (!(*codec)) {
66  fprintf(stderr, "Could not find encoder for '%s'\n",
67  avcodec_get_name(codec_id));
68  exit(1);
69  }
70 
71  st = avformat_new_stream(oc, *codec);
72  if (!st) {
73  fprintf(stderr, "Could not allocate stream\n");
74  exit(1);
75  }
76  st->id = oc->nb_streams-1;
77  c = st->codec;
78 
79  switch ((*codec)->type) {
80  case AVMEDIA_TYPE_AUDIO:
81  st->id = 1;
83  c->bit_rate = 64000;
84  c->sample_rate = 44100;
85  c->channels = 2;
86  break;
87 
88  case AVMEDIA_TYPE_VIDEO:
89  c->codec_id = codec_id;
90 
91  c->bit_rate = 400000;
92  /* Resolution must be a multiple of two. */
93  c->width = 352;
94  c->height = 288;
95  /* timebase: This is the fundamental unit of time (in seconds) in terms
96  * of which frame timestamps are represented. For fixed-fps content,
97  * timebase should be 1/framerate and timestamp increments should be
98  * identical to 1. */
100  c->time_base.num = 1;
101  c->gop_size = 12; /* emit one intra frame every twelve frames at most */
102  c->pix_fmt = STREAM_PIX_FMT;
103  if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
104  /* just for testing, we also add B frames */
105  c->max_b_frames = 2;
106  }
107  if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
108  /* Needed to avoid using macroblocks in which some coeffs overflow.
109  * This does not happen with normal video, it just happens here as
110  * the motion of the chroma plane does not match the luma plane. */
111  c->mb_decision = 2;
112  }
113  break;
114 
115  default:
116  break;
117  }
118 
119  /* Some formats want stream headers to be separate. */
120  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
122 
123  return st;
124 }
125 
126 /**************************************************************/
127 /* audio output */
128 
129 static float t, tincr, tincr2;
130 static int16_t *samples;
131 static int audio_input_frame_size;
132 
133 static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
134 {
135  AVCodecContext *c;
136  int ret;
137 
138  c = st->codec;
139 
140  /* open it */
141  ret = avcodec_open2(c, codec, NULL);
142  if (ret < 0) {
143  fprintf(stderr, "Could not open audio codec: %s\n", av_err2str(ret));
144  exit(1);
145  }
146 
147  /* init signal generator */
148  t = 0;
149  tincr = 2 * M_PI * 110.0 / c->sample_rate;
150  /* increment frequency by 110 Hz per second */
151  tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;
152 
154  audio_input_frame_size = 10000;
155  else
159  c->channels);
160  if (!samples) {
161  fprintf(stderr, "Could not allocate audio samples buffer\n");
162  exit(1);
163  }
164 }
165 
166 /* Prepare a 16 bit dummy audio frame of 'frame_size' samples and
167  * 'nb_channels' channels. */
168 static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
169 {
170  int j, i, v;
171  int16_t *q;
172 
173  q = samples;
174  for (j = 0; j < frame_size; j++) {
175  v = (int)(sin(t) * 10000);
176  for (i = 0; i < nb_channels; i++)
177  *q++ = v;
178  t += tincr;
179  tincr += tincr2;
180  }
181 }
182 
184 {
185  AVCodecContext *c;
186  AVPacket pkt = { 0 }; // data and size must be 0;
188  int got_packet, ret;
189 
190  av_init_packet(&pkt);
191  c = st->codec;
192 
196  (uint8_t *)samples,
199  c->channels, 1);
200 
201  ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
202  if (ret < 0) {
203  fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
204  exit(1);
205  }
206 
207  if (!got_packet)
208  return;
209 
210  pkt.stream_index = st->index;
211 
212  /* Write the compressed frame to the media file. */
213  ret = av_interleaved_write_frame(oc, &pkt);
214  if (ret != 0) {
215  fprintf(stderr, "Error while writing audio frame: %s\n",
216  av_err2str(ret));
217  exit(1);
218  }
219  avcodec_free_frame(&frame);
220 }
221 
222 static void close_audio(AVFormatContext *oc, AVStream *st)
223 {
224  avcodec_close(st->codec);
225 
226  av_free(samples);
227 }
228 
229 /**************************************************************/
230 /* video output */
231 
232 static AVFrame *frame;
234 static int frame_count;
235 
236 static void open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st)
237 {
238  int ret;
239  AVCodecContext *c = st->codec;
240 
241  /* open the codec */
242  ret = avcodec_open2(c, codec, NULL);
243  if (ret < 0) {
244  fprintf(stderr, "Could not open video codec: %s\n", av_err2str(ret));
245  exit(1);
246  }
247 
248  /* allocate and init a re-usable frame */
249  frame = avcodec_alloc_frame();
250  if (!frame) {
251  fprintf(stderr, "Could not allocate video frame\n");
252  exit(1);
253  }
254 
255  /* Allocate the encoded raw picture. */
256  ret = avpicture_alloc(&dst_picture, c->pix_fmt, c->width, c->height);
257  if (ret < 0) {
258  fprintf(stderr, "Could not allocate picture: %s\n", av_err2str(ret));
259  exit(1);
260  }
261 
262  /* If the output format is not YUV420P, then a temporary YUV420P
263  * picture is needed too. It is then converted to the required
264  * output format. */
265  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
266  ret = avpicture_alloc(&src_picture, AV_PIX_FMT_YUV420P, c->width, c->height);
267  if (ret < 0) {
268  fprintf(stderr, "Could not allocate temporary picture: %s\n",
269  av_err2str(ret));
270  exit(1);
271  }
272  }
273 
274  /* copy data and linesize picture pointers to frame */
275  *((AVPicture *)frame) = dst_picture;
276 }
277 
278 /* Prepare a dummy image. */
279 static void fill_yuv_image(AVPicture *pict, int frame_index,
280  int width, int height)
281 {
282  int x, y, i;
283 
284  i = frame_index;
285 
286  /* Y */
287  for (y = 0; y < height; y++)
288  for (x = 0; x < width; x++)
289  pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3;
290 
291  /* Cb and Cr */
292  for (y = 0; y < height / 2; y++) {
293  for (x = 0; x < width / 2; x++) {
294  pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2;
295  pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5;
296  }
297  }
298 }
299 
301 {
302  int ret;
303  static struct SwsContext *sws_ctx;
304  AVCodecContext *c = st->codec;
305 
306  if (frame_count >= STREAM_NB_FRAMES) {
307  /* No more frames to compress. The codec has a latency of a few
308  * frames if using B-frames, so we get the last frames by
309  * passing the same picture again. */
310  } else {
311  if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
312  /* as we only generate a YUV420P picture, we must convert it
313  * to the codec pixel format if needed */
314  if (!sws_ctx) {
315  sws_ctx = sws_getContext(c->width, c->height, AV_PIX_FMT_YUV420P,
316  c->width, c->height, c->pix_fmt,
317  sws_flags, NULL, NULL, NULL);
318  if (!sws_ctx) {
319  fprintf(stderr,
320  "Could not initialize the conversion context\n");
321  exit(1);
322  }
323  }
324  fill_yuv_image(&src_picture, frame_count, c->width, c->height);
325  sws_scale(sws_ctx,
326  (const uint8_t * const *)src_picture.data, src_picture.linesize,
327  0, c->height, dst_picture.data, dst_picture.linesize);
328  } else {
329  fill_yuv_image(&dst_picture, frame_count, c->width, c->height);
330  }
331  }
332 
333  if (oc->oformat->flags & AVFMT_RAWPICTURE) {
334  /* Raw video case - directly store the picture in the packet */
335  AVPacket pkt;
336  av_init_packet(&pkt);
337 
338  pkt.flags |= AV_PKT_FLAG_KEY;
339  pkt.stream_index = st->index;
340  pkt.data = dst_picture.data[0];
341  pkt.size = sizeof(AVPicture);
342 
343  ret = av_interleaved_write_frame(oc, &pkt);
344  } else {
345  AVPacket pkt = { 0 };
346  int got_packet;
347  av_init_packet(&pkt);
348 
349  /* encode the image */
350  ret = avcodec_encode_video2(c, &pkt, frame, &got_packet);
351  if (ret < 0) {
352  fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
353  exit(1);
354  }
355  /* If size is zero, it means the image was buffered. */
356 
357  if (!ret && got_packet && pkt.size) {
358  pkt.stream_index = st->index;
359 
360  /* Write the compressed frame to the media file. */
361  ret = av_interleaved_write_frame(oc, &pkt);
362  } else {
363  ret = 0;
364  }
365  }
366  if (ret != 0) {
367  fprintf(stderr, "Error while writing video frame: %s\n", av_err2str(ret));
368  exit(1);
369  }
370  frame_count++;
371 }
372 
373 static void close_video(AVFormatContext *oc, AVStream *st)
374 {
375  avcodec_close(st->codec);
376  av_free(src_picture.data[0]);
377  av_free(dst_picture.data[0]);
378  av_free(frame);
379 }
380 
381 /**************************************************************/
382 /* media file output */
383 
384 int main(int argc, char **argv)
385 {
386  const char *filename;
388  AVFormatContext *oc;
389  AVStream *audio_st, *video_st;
390  AVCodec *audio_codec, *video_codec;
391  double audio_pts, video_pts;
392  int ret;
393 
394  /* Initialize libavcodec, and register all codecs and formats. */
395  av_register_all();
396 
397  if (argc != 2) {
398  printf("usage: %s output_file\n"
399  "API example program to output a media file with libavformat.\n"
400  "This program generates a synthetic audio and video stream, encodes and\n"
401  "muxes them into a file named output_file.\n"
402  "The output format is automatically guessed according to the file extension.\n"
403  "Raw images can also be output by using '%%d' in the filename.\n"
404  "\n", argv[0]);
405  return 1;
406  }
407 
408  filename = argv[1];
409 
410  /* allocate the output media context */
411  avformat_alloc_output_context2(&oc, NULL, NULL, filename);
412  if (!oc) {
413  printf("Could not deduce output format from file extension: using MPEG.\n");
414  avformat_alloc_output_context2(&oc, NULL, "mpeg", filename);
415  }
416  if (!oc) {
417  return 1;
418  }
419  fmt = oc->oformat;
420 
421  /* Add the audio and video streams using the default format codecs
422  * and initialize the codecs. */
423  video_st = NULL;
424  audio_st = NULL;
425 
426  if (fmt->video_codec != AV_CODEC_ID_NONE) {
427  video_st = add_stream(oc, &video_codec, fmt->video_codec);
428  }
429  if (fmt->audio_codec != AV_CODEC_ID_NONE) {
430  audio_st = add_stream(oc, &audio_codec, fmt->audio_codec);
431  }
432 
433  /* Now that all the parameters are set, we can open the audio and
434  * video codecs and allocate the necessary encode buffers. */
435  if (video_st)
436  open_video(oc, video_codec, video_st);
437  if (audio_st)
438  open_audio(oc, audio_codec, audio_st);
439 
440  av_dump_format(oc, 0, filename, 1);
441 
442  /* open the output file, if needed */
443  if (!(fmt->flags & AVFMT_NOFILE)) {
444  ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
445  if (ret < 0) {
446  fprintf(stderr, "Could not open '%s': %s\n", filename,
447  av_err2str(ret));
448  return 1;
449  }
450  }
451 
452  /* Write the stream header, if any. */
453  ret = avformat_write_header(oc, NULL);
454  if (ret < 0) {
455  fprintf(stderr, "Error occurred when opening output file: %s\n",
456  av_err2str(ret));
457  return 1;
458  }
459 
460  if (frame)
461  frame->pts = 0;
462  for (;;) {
463  /* Compute current audio and video time. */
464  if (audio_st)
465  audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
466  else
467  audio_pts = 0.0;
468 
469  if (video_st)
470  video_pts = (double)video_st->pts.val * video_st->time_base.num /
471  video_st->time_base.den;
472  else
473  video_pts = 0.0;
474 
475  if ((!audio_st || audio_pts >= STREAM_DURATION) &&
476  (!video_st || video_pts >= STREAM_DURATION))
477  break;
478 
479  /* write interleaved audio and video frames */
480  if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
481  write_audio_frame(oc, audio_st);
482  } else {
483  write_video_frame(oc, video_st);
484  frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);
485  }
486  }
487 
488  /* Write the trailer, if any. The trailer must be written before you
489  * close the CodecContexts open when you wrote the header; otherwise
490  * av_write_trailer() may try to use memory that was freed on
491  * av_codec_close(). */
492  av_write_trailer(oc);
493 
494  /* Close each codec. */
495  if (video_st)
496  close_video(oc, video_st);
497  if (audio_st)
498  close_audio(oc, audio_st);
499 
500  if (!(fmt->flags & AVFMT_NOFILE))
501  /* Close the output file. */
502  avio_close(oc->pb);
503 
504  /* free the stream */
506 
507  return 0;
508 }
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:799
const struct AVCodec * codec
static int sws_flags
Definition: muxing.c:47
static void open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st)
Definition: muxing.c:236
float v
static AVPicture dst_picture
Definition: muxing.c:233
int linesize[AV_NUM_DATA_POINTERS]
number of bytes per line
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
int main(int argc, char **argv)
Definition: muxing.c:384
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:726
#define CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
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:383
const char * fmt
Definition: avisynth_c.h:669
static int audio_input_frame_size
Definition: muxing.c:54
static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
Definition: muxing.c:133
static void fill_yuv_image(AVPicture *pict, int frame_index, int width, int height)
Definition: muxing.c:279
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...
enum AVCodecID video_codec
default video codec
Definition: avformat.h:389
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:644
#define SWS_BICUBIC
Definition: swscale.h:60
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:333
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void close_audio(AVFormatContext *oc, AVStream *st)
Definition: muxing.c:222
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.
int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
signed 16 bits
Definition: samplefmt.h:52
four components are given, that&#39;s all.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
Format I/O context.
Definition: avformat.h:944
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
Fill AVFrame audio data and linesize pointers.
enum AVSampleFormat sample_fmt
audio sample format
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:397
uint8_t
uint8_t * data[AV_NUM_DATA_POINTERS]
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static AVPacket pkt
Definition: demuxing.c:56
int id
Format-specific stream ID.
Definition: avformat.h:650
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don&#39;t need to export the SwsContext.
Definition: swscale.c:798
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
#define STREAM_NB_FRAMES
Definition: muxing.c:44
uint8_t * data
external API header
struct AVOutputFormat * oformat
Definition: avformat.h:958
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:125
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
static const uint8_t frame_size[4]
Definition: g723_1_data.h:58
Discrete Time axis x
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
static AVPicture src_picture
Definition: muxing.c:233
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:821
int capabilities
Codec capabilities.
int flags
CODEC_FLAG_*.
static float tincr2
Definition: muxing.c:52
enum AVCodecID codec_id
Definition: mov_chan.c:433
struct AVPicture AVPicture
four components are given, that&#39;s all.
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels)
Definition: muxing.c:168
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
int bit_rate
the average bitrate
static AVStream * add_stream(AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id)
Definition: muxing.c:57
ret
Definition: avfilter.c:821
int width
picture width / height.
static void close_video(AVFormatContext *oc, AVStream *st)
Definition: muxing.c:373
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:351
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:110
int mb_decision
macroblock decision mode
#define STREAM_PIX_FMT
Definition: muxing.c:45
preferred ID for MPEG-1/2 video decoding
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
Stream structure.
Definition: avformat.h:643
int frame_size
Number of samples per channel in an audio frame.
static float t
Definition: muxing.c:52
NULL
Definition: eval.c:55
static int width
Definition: tests/utils.c:158
#define STREAM_DURATION
Definition: muxing.c:42
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AVFMT_RAWPICTURE
Format wants AVPicture structure for raw picture data.
Definition: avformat.h:348
main external API structure.
static float tincr
Definition: muxing.c:52
static AVFrame * frame
Definition: muxing.c:232
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
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:73
int avpicture_alloc(AVPicture *picture, enum AVPixelFormat pix_fmt, int width, int height)
Allocate memory for a picture.
Definition: avpicture.c:54
synthesis window for stochastic i
static void write_audio_frame(AVFormatContext *oc, AVStream *st)
Definition: muxing.c:183
#define STREAM_FRAME_RATE
Definition: muxing.c:43
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int64_t val
Definition: avformat.h:323
static int16_t * samples
Definition: muxing.c:53
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Main libavformat public API header.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
static int frame_count
Definition: muxing.c:234
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:345
static double c[64]
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:56
int den
denominator
Definition: rational.h:45
function y
Definition: D.m:1
struct AVFrac pts
encoding: pts generation when outputting stream
Definition: avformat.h:668
int channels
number of audio channels
enum AVCodecID audio_codec
default audio codec
Definition: avformat.h:388
printf("static const uint8_t my_array[100] = {\n")
void avcodec_free_frame(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:769
static void write_video_frame(AVFormatContext *oc, AVStream *st)
Definition: muxing.c:300
#define M_PI
Definition: mathematics.h:46
int nb_channels
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
Definition: allformats.c:52
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
for(j=16;j >0;--j)