mux.c
Go to the documentation of this file.
1 /*
2  * muxing functions for use within Libav
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /* #define DEBUG */
23 
24 #include "avformat.h"
25 #include "avio_internal.h"
26 #include "internal.h"
27 #include "libavcodec/internal.h"
28 #include "libavcodec/bytestream.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/dict.h"
31 #include "libavutil/pixdesc.h"
32 #include "metadata.h"
33 #include "id3v2.h"
34 #include "libavutil/avassert.h"
35 #include "libavutil/avstring.h"
36 #include "libavutil/mathematics.h"
37 #include "libavutil/parseutils.h"
38 #include "libavutil/time.h"
39 #include "riff.h"
40 #include "audiointerleave.h"
41 #include "url.h"
42 #include <stdarg.h>
43 #if CONFIG_NETWORK
44 #include "network.h"
45 #endif
46 
47 #undef NDEBUG
48 #include <assert.h>
49 
55 /* fraction handling */
56 
67 static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
68 {
69  num += (den >> 1);
70  if (num >= den) {
71  val += num / den;
72  num = num % den;
73  }
74  f->val = val;
75  f->num = num;
76  f->den = den;
77 }
78 
85 static void frac_add(AVFrac *f, int64_t incr)
86 {
87  int64_t num, den;
88 
89  num = f->num + incr;
90  den = f->den;
91  if (num < 0) {
92  f->val += num / den;
93  num = num % den;
94  if (num < 0) {
95  num += den;
96  f->val--;
97  }
98  } else if (num >= den) {
99  f->val += num / den;
100  num = num % den;
101  }
102  f->num = num;
103 }
104 
106 {
107  const AVCodecTag *avctag;
108  int n;
109  enum AVCodecID id = AV_CODEC_ID_NONE;
110  unsigned int tag = 0;
111 
118  for (n = 0; s->oformat->codec_tag[n]; n++) {
119  avctag = s->oformat->codec_tag[n];
120  while (avctag->id != AV_CODEC_ID_NONE) {
121  if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) {
122  id = avctag->id;
123  if (id == st->codec->codec_id)
124  return 1;
125  }
126  if (avctag->id == st->codec->codec_id)
127  tag = avctag->tag;
128  avctag++;
129  }
130  }
131  if (id != AV_CODEC_ID_NONE)
132  return 0;
133  if (tag && (st->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
134  return 0;
135  return 1;
136 }
137 
138 
140 {
141  int ret = 0, i;
142  AVStream *st;
143  AVDictionary *tmp = NULL;
144  AVCodecContext *codec = NULL;
145  AVOutputFormat *of = s->oformat;
146 
147  if (options)
148  av_dict_copy(&tmp, *options, 0);
149 
150  if ((ret = av_opt_set_dict(s, &tmp)) < 0)
151  goto fail;
152 
153  // some sanity checks
154  if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
155  av_log(s, AV_LOG_ERROR, "no streams\n");
156  ret = AVERROR(EINVAL);
157  goto fail;
158  }
159 
160  for (i = 0; i < s->nb_streams; i++) {
161  st = s->streams[i];
162  codec = st->codec;
163 
164  switch (codec->codec_type) {
165  case AVMEDIA_TYPE_AUDIO:
166  if (codec->sample_rate <= 0) {
167  av_log(s, AV_LOG_ERROR, "sample rate not set\n");
168  ret = AVERROR(EINVAL);
169  goto fail;
170  }
171  if (!codec->block_align)
172  codec->block_align = codec->channels *
173  av_get_bits_per_sample(codec->codec_id) >> 3;
174  break;
175  case AVMEDIA_TYPE_VIDEO:
176  if (codec->time_base.num <= 0 ||
177  codec->time_base.den <= 0) { //FIXME audio too?
178  av_log(s, AV_LOG_ERROR, "time base not set\n");
179  ret = AVERROR(EINVAL);
180  goto fail;
181  }
182 
183  if ((codec->width <= 0 || codec->height <= 0) &&
184  !(of->flags & AVFMT_NODIMENSIONS)) {
185  av_log(s, AV_LOG_ERROR, "dimensions not set\n");
186  ret = AVERROR(EINVAL);
187  goto fail;
188  }
189 
191  codec->sample_aspect_ratio)) {
192  av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
193  "(%d/%d) and encoder layer (%d/%d)\n",
195  codec->sample_aspect_ratio.num,
196  codec->sample_aspect_ratio.den);
197  ret = AVERROR(EINVAL);
198  goto fail;
199  }
200  break;
201  }
202 
203  if (of->codec_tag) {
204  if (codec->codec_tag &&
205  codec->codec_id == AV_CODEC_ID_RAWVIDEO &&
206  !av_codec_get_tag(of->codec_tag, codec->codec_id) &&
207  !validate_codec_tag(s, st)) {
208  // the current rawvideo encoding system ends up setting
209  // the wrong codec_tag for avi, we override it here
210  codec->codec_tag = 0;
211  }
212  if (codec->codec_tag) {
213  if (!validate_codec_tag(s, st)) {
214  char tagbuf[32];
215  av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag);
216  av_log(s, AV_LOG_ERROR,
217  "Tag %s/0x%08x incompatible with output codec id '%d'\n",
218  tagbuf, codec->codec_tag, codec->codec_id);
219  ret = AVERROR_INVALIDDATA;
220  goto fail;
221  }
222  } else
223  codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id);
224  }
225 
226  if (of->flags & AVFMT_GLOBALHEADER &&
227  !(codec->flags & CODEC_FLAG_GLOBAL_HEADER))
229  "Codec for stream %d does not use global headers "
230  "but container format requires global headers\n", i);
231  }
232 
233  if (!s->priv_data && of->priv_data_size > 0) {
235  if (!s->priv_data) {
236  ret = AVERROR(ENOMEM);
237  goto fail;
238  }
239  if (of->priv_class) {
240  *(const AVClass **)s->priv_data = of->priv_class;
242  if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
243  goto fail;
244  }
245  }
246 
247  /* set muxer identification string */
248  if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
249  av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
250  }
251 
252  if (options) {
253  av_dict_free(options);
254  *options = tmp;
255  }
256 
257  return 0;
258 
259 fail:
260  av_dict_free(&tmp);
261  return ret;
262 }
263 
264 static int init_pts(AVFormatContext *s)
265 {
266  int i;
267  AVStream *st;
268 
269  /* init PTS generation */
270  for (i = 0; i < s->nb_streams; i++) {
271  int64_t den = AV_NOPTS_VALUE;
272  st = s->streams[i];
273 
274  switch (st->codec->codec_type) {
275  case AVMEDIA_TYPE_AUDIO:
276  den = (int64_t)st->time_base.num * st->codec->sample_rate;
277  break;
278  case AVMEDIA_TYPE_VIDEO:
279  den = (int64_t)st->time_base.num * st->codec->time_base.den;
280  break;
281  default:
282  break;
283  }
284  if (den != AV_NOPTS_VALUE) {
285  if (den <= 0)
286  return AVERROR_INVALIDDATA;
287 
288  frac_init(&st->pts, 0, 0, den);
289  }
290  }
291 
292  return 0;
293 }
294 
296 {
297  int ret = 0;
298 
299  if (ret = init_muxer(s, options))
300  return ret;
301 
302  if (s->oformat->write_header) {
303  ret = s->oformat->write_header(s);
304  if (ret < 0)
305  return ret;
306  }
307 
308  if ((ret = init_pts(s) < 0))
309  return ret;
310 
311  return 0;
312 }
313 
314 //FIXME merge with compute_pkt_fields
316 {
317  int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);
318  int num, den, frame_size, i;
319 
320  av_dlog(s, "compute_pkt_fields2: pts:%" PRId64 " dts:%" PRId64 " cur_dts:%" PRId64 " b:%d size:%d st:%d\n",
321  pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index);
322 
323 /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)
324  * return AVERROR(EINVAL);*/
325 
326  /* duration field */
327  if (pkt->duration == 0) {
328  ff_compute_frame_duration(&num, &den, st, NULL, pkt);
329  if (den && num) {
330  pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
331  }
332  }
333 
334  if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
335  pkt->pts = pkt->dts;
336 
337  //XXX/FIXME this is a temporary hack until all encoders output pts
338  if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
339  pkt->dts =
340 // pkt->pts= st->cur_dts;
341  pkt->pts = st->pts.val;
342  }
343 
344  //calculate dts from pts
345  if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
346  st->pts_buffer[0] = pkt->pts;
347  for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
348  st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
349  for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
350  FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
351 
352  pkt->dts = st->pts_buffer[0];
353  }
354 
355  if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
356  ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
357  st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
358  av_log(s, AV_LOG_ERROR,
359  "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
360  st->index, st->cur_dts, pkt->dts);
361  return AVERROR(EINVAL);
362  }
363  if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
364  av_log(s, AV_LOG_ERROR, "pts < dts in stream %d\n", st->index);
365  return AVERROR(EINVAL);
366  }
367 
368  av_dlog(s, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n",
369  pkt->pts, pkt->dts);
370  st->cur_dts = pkt->dts;
371  st->pts.val = pkt->dts;
372 
373  /* update pts */
374  switch (st->codec->codec_type) {
375  case AVMEDIA_TYPE_AUDIO:
376  frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 1);
377 
378  /* HACK/FIXME, we skip the initial 0 size packets as they are most
379  * likely equal to the encoder delay, but it would be better if we
380  * had the real timestamps from the encoder */
381  if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
382  frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
383  }
384  break;
385  case AVMEDIA_TYPE_VIDEO:
386  frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
387  break;
388  default:
389  break;
390  }
391  return 0;
392 }
393 
395 {
396  int ret;
397 
398  if (!pkt) {
399  if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
400  return s->oformat->write_packet(s, pkt);
401  return 1;
402  }
403 
404  ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
405 
406  if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
407  return ret;
408 
409  ret = s->oformat->write_packet(s, pkt);
410 
411  if (ret >= 0)
412  s->streams[pkt->stream_index]->nb_frames++;
413  return ret;
414 }
415 
417  int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
418 {
419  AVPacketList **next_point, *this_pktl;
420 
421  this_pktl = av_mallocz(sizeof(AVPacketList));
422  this_pktl->pkt = *pkt;
423  pkt->destruct = NULL; // do not free original but only the copy
424  av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory
425 
427  next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
428  } else
429  next_point = &s->packet_buffer;
430 
431  if (*next_point) {
432  if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
433  while (!compare(s, &(*next_point)->pkt, pkt))
434  next_point = &(*next_point)->next;
435  goto next_non_null;
436  } else {
437  next_point = &(s->packet_buffer_end->next);
438  }
439  }
440  assert(!*next_point);
441 
442  s->packet_buffer_end = this_pktl;
443 next_non_null:
444 
445  this_pktl->next = *next_point;
446 
448  *next_point = this_pktl;
449 }
450 
452 {
453  AVStream *st = s->streams[pkt->stream_index];
454  AVStream *st2 = s->streams[next->stream_index];
455  int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
456  st->time_base);
457 
458  if (comp == 0)
459  return pkt->stream_index < next->stream_index;
460  return comp > 0;
461 }
462 
464  AVPacket *pkt, int flush)
465 {
466  AVPacketList *pktl;
467  int stream_count = 0;
468  int i;
469 
470  if (pkt) {
472  }
473 
474  for (i = 0; i < s->nb_streams; i++)
475  stream_count += !!s->streams[i]->last_in_packet_buffer;
476 
477  if (stream_count && (s->nb_streams == stream_count || flush)) {
478  pktl = s->packet_buffer;
479  *out = pktl->pkt;
480 
481  s->packet_buffer = pktl->next;
482  if (!s->packet_buffer)
483  s->packet_buffer_end = NULL;
484 
485  if (s->streams[out->stream_index]->last_in_packet_buffer == pktl)
487  av_freep(&pktl);
488  return 1;
489  } else {
490  av_init_packet(out);
491  return 0;
492  }
493 }
494 
495 #if FF_API_INTERLEAVE_PACKET
496 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
497  AVPacket *pkt, int flush)
498 {
499  return ff_interleave_packet_per_dts(s, out, pkt, flush);
500 }
501 
502 #endif
503 
514 {
515  if (s->oformat->interleave_packet) {
516  int ret = s->oformat->interleave_packet(s, out, in, flush);
517  if (in)
518  av_free_packet(in);
519  return ret;
520  } else
521  return ff_interleave_packet_per_dts(s, out, in, flush);
522 }
523 
525 {
526  int ret, flush = 0;
527 
528  if (pkt) {
529  AVStream *st = s->streams[pkt->stream_index];
530 
531  //FIXME/XXX/HACK drop zero sized packets
532  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0)
533  return 0;
534 
535  av_dlog(s, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",
536  pkt->size, pkt->dts, pkt->pts);
537  if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
538  return ret;
539 
540  if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
541  return AVERROR(EINVAL);
542  } else {
543  av_dlog(s, "av_interleaved_write_frame FLUSH\n");
544  flush = 1;
545  }
546 
547  for (;; ) {
548  AVPacket opkt;
549  int ret = interleave_packet(s, &opkt, pkt, flush);
550  if (ret <= 0) //FIXME cleanup needed for ret<0 ?
551  return ret;
552 
553  ret = s->oformat->write_packet(s, &opkt);
554  if (ret >= 0)
555  s->streams[opkt.stream_index]->nb_frames++;
556 
557  av_free_packet(&opkt);
558  pkt = NULL;
559 
560  if (ret < 0)
561  return ret;
562  }
563 }
564 
566 {
567  int ret, i;
568 
569  for (;; ) {
570  AVPacket pkt;
571  ret = interleave_packet(s, &pkt, NULL, 1);
572  if (ret < 0) //FIXME cleanup needed for ret<0 ?
573  goto fail;
574  if (!ret)
575  break;
576 
577  ret = s->oformat->write_packet(s, &pkt);
578  if (ret >= 0)
579  s->streams[pkt.stream_index]->nb_frames++;
580 
581  av_free_packet(&pkt);
582 
583  if (ret < 0)
584  goto fail;
585  }
586 
587  if (s->oformat->write_trailer)
588  ret = s->oformat->write_trailer(s);
589 
590  if (!(s->oformat->flags & AVFMT_NOFILE))
591  avio_flush(s->pb);
592 
593 fail:
594  for (i = 0; i < s->nb_streams; i++) {
595  av_freep(&s->streams[i]->priv_data);
596  av_freep(&s->streams[i]->index_entries);
597  }
598  if (s->oformat->priv_class)
600  av_freep(&s->priv_data);
601  return ret;
602 }
enum AVCodecID id
Definition: internal.h:36
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:153
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:524
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:295
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Definition: mux.c:394
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition: avformat.h:784
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:1588
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:505
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:697
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:623
int size
Definition: avcodec.h:916
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
Interleave a packet per dts in an output media file.
Definition: mux.c:463
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:786
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1724
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:55
void * priv_data
Definition: avformat.h:653
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
Put a string representing the codec tag codec_tag in buf.
Definition: utils.c:1557
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int(* write_packet)(struct AVFormatContext *, AVPacket *pkt)
Write a packet.
Definition: avformat.h:427
int av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:122
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2141
int ff_get_audio_frame_size(AVCodecContext *enc, int size, int mux)
Get the number of samples of an audio frame.
Definition: utils.c:684
struct AVPacketList * packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition: avformat.h:1025
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1465
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:151
Format I/O context.
Definition: avformat.h:828
int64_t cur_dts
Definition: avformat.h:759
internal metadata API header see avformat.h or the public API!
Public dictionary API.
static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
f = val + (num / den) + 0.5.
Definition: mux.c:67
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:395
AVOptions.
AVPacket pkt
Definition: avformat.h:1052
int priv_data_size
size of private data so that it can be allocated in the wrapper
Definition: avformat.h:417
AVStream ** streams
Definition: avformat.h:876
uint32_t tag
Definition: movenc.c:802
static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
Interleave an AVPacket correctly so it can be muxed.
Definition: mux.c:513
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:937
struct AVOutputFormat * oformat
Definition: avformat.h:842
void(* destruct)(struct AVPacket *)
Definition: avcodec.h:938
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:127
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:95
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1634
AVDictionary * metadata
Definition: avformat.h:972
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1813
static int validate_codec_tag(AVFormatContext *s, AVStream *st)
Definition: mux.c:105
int(* write_header)(struct AVFormatContext *)
Definition: avformat.h:419
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:113
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
The exact value of the fractional number is: 'val + num / den'.
Definition: avformat.h:326
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
Definition: mathematics.c:127
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:875
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:110
int width
picture width / height.
Definition: avcodec.h:1508
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1474
static int init_muxer(AVFormatContext *s, AVDictionary **options)
Definition: mux.c:139
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:404
Stream structure.
Definition: avformat.h:622
NULL
Definition: eval.c:52
enum AVMediaType codec_type
Definition: avcodec.h:1347
enum AVCodecID codec_id
Definition: avcodec.h:1350
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:615
int sample_rate
samples per second
Definition: avcodec.h:2104
AVIOContext * pb
I/O context.
Definition: avformat.h:861
void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
Definition: utils.c:706
const struct AVCodecTag *const * codec_tag
List of supported codec_id-codec_tag pairs, ordered by "better choice first".
Definition: avformat.h:401
main external API structure.
Definition: avcodec.h:1339
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1365
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:63
Describe the class of an AVClass context structure.
Definition: log.h:33
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:2097
void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, AVPacket *, AVPacket *))
Add packet to AVFormatContext->packet_buffer list, determining its interleaved position using compare...
Definition: mux.c:416
struct AVPacketList * packet_buffer_end
Definition: avformat.h:1026
int(* interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush)
Currently only used to set pixel format if not YUV420P.
Definition: avformat.h:432
static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
Definition: mux.c:451
misc parsing utilities
int64_t val
Definition: avformat.h:327
int64_t num
Definition: avformat.h:327
unsigned int tag
Definition: internal.h:37
int64_t den
Definition: avformat.h:327
const OptionDef options[]
Definition: avserver.c:4665
Main libavformat public API header.
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:607
common internal api header.
struct AVPacketList * next
Definition: avformat.h:1053
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1772
static int init_pts(AVFormatContext *s)
Definition: mux.c:264
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:42
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:686
int den
denominator
Definition: rational.h:45
static void frac_add(AVFrac *f, int64_t incr)
Fractional addition to f: f = f + (incr / f->den).
Definition: mux.c:85
struct AVFrac pts
encoding: pts generation when outputting stream
Definition: avformat.h:658
int channels
number of audio channels
Definition: avcodec.h:2105
void * priv_data
Format private data.
Definition: avformat.h:848
static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: mux.c:315
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:914
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:565
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:74
unbuffered private I/O API
int stream_index
Definition: avcodec.h:917
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:669
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
This structure stores compressed data.
Definition: avcodec.h:898
int(* write_trailer)(struct AVFormatContext *)
Definition: avformat.h:428
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:158
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2547
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:908
struct AVPacketList * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
Definition: avformat.h:781
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)