mux.c
Go to the documentation of this file.
1 /*
2  * muxing functions for use within FFmpeg
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 "libavutil/timestamp.h"
33 #include "metadata.h"
34 #include "id3v2.h"
35 #include "libavutil/avassert.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/time.h"
40 #include "riff.h"
41 #include "audiointerleave.h"
42 #include "url.h"
43 #include <stdarg.h>
44 #if CONFIG_NETWORK
45 #include "network.h"
46 #endif
47 
48 #undef NDEBUG
49 #include <assert.h>
50 
51 /**
52  * @file
53  * muxing functions for use within libavformat
54  */
55 
56 /* fraction handling */
57 
58 /**
59  * f = val + (num / den) + 0.5.
60  *
61  * 'num' is normalized so that it is such as 0 <= num < den.
62  *
63  * @param f fractional number
64  * @param val integer value
65  * @param num must be >= 0
66  * @param den must be >= 1
67  */
68 static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
69 {
70  num += (den >> 1);
71  if (num >= den) {
72  val += num / den;
73  num = num % den;
74  }
75  f->val = val;
76  f->num = num;
77  f->den = den;
78 }
79 
80 /**
81  * Fractional addition to f: f = f + (incr / f->den).
82  *
83  * @param f fractional number
84  * @param incr increment, can be positive or negative
85  */
86 static void frac_add(AVFrac *f, int64_t incr)
87 {
88  int64_t num, den;
89 
90  num = f->num + incr;
91  den = f->den;
92  if (num < 0) {
93  f->val += num / den;
94  num = num % den;
95  if (num < 0) {
96  num += den;
97  f->val--;
98  }
99  } else if (num >= den) {
100  f->val += num / den;
101  num = num % den;
102  }
103  f->num = num;
104 }
105 
107 {
108  AVRational q;
109  int j;
110 
111  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
112  q = (AVRational){1, st->codec->sample_rate};
113  } else {
114  q = st->codec->time_base;
115  }
116  for (j=2; j<14; j+= 1+(j>2))
117  while (q.den / q.num < min_precission && q.num % j == 0)
118  q.num /= j;
119  while (q.den / q.num < min_precission && q.den < (1<<24))
120  q.den <<= 1;
121 
122  return q;
123 }
124 
126  const char *format, const char *filename)
127 {
129  int ret = 0;
130 
131  *avctx = NULL;
132  if (!s)
133  goto nomem;
134 
135  if (!oformat) {
136  if (format) {
137  oformat = av_guess_format(format, NULL, NULL);
138  if (!oformat) {
139  av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
140  ret = AVERROR(EINVAL);
141  goto error;
142  }
143  } else {
144  oformat = av_guess_format(NULL, filename, NULL);
145  if (!oformat) {
146  ret = AVERROR(EINVAL);
147  av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
148  filename);
149  goto error;
150  }
151  }
152  }
153 
154  s->oformat = oformat;
155  if (s->oformat->priv_data_size > 0) {
157  if (!s->priv_data)
158  goto nomem;
159  if (s->oformat->priv_class) {
160  *(const AVClass**)s->priv_data= s->oformat->priv_class;
162  }
163  } else
164  s->priv_data = NULL;
165 
166  if (filename)
167  av_strlcpy(s->filename, filename, sizeof(s->filename));
168  *avctx = s;
169  return 0;
170 nomem:
171  av_log(s, AV_LOG_ERROR, "Out of memory\n");
172  ret = AVERROR(ENOMEM);
173 error:
175  return ret;
176 }
177 
178 #if FF_API_ALLOC_OUTPUT_CONTEXT
179 AVFormatContext *avformat_alloc_output_context(const char *format,
180  AVOutputFormat *oformat, const char *filename)
181 {
182  AVFormatContext *avctx;
183  int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename);
184  return ret < 0 ? NULL : avctx;
185 }
186 #endif
187 
189 {
190  const AVCodecTag *avctag;
191  int n;
192  enum AVCodecID id = AV_CODEC_ID_NONE;
193  unsigned int tag = 0;
194 
195  /**
196  * Check that tag + id is in the table
197  * If neither is in the table -> OK
198  * If tag is in the table with another id -> FAIL
199  * If id is in the table with another tag -> FAIL unless strict < normal
200  */
201  for (n = 0; s->oformat->codec_tag[n]; n++) {
202  avctag = s->oformat->codec_tag[n];
203  while (avctag->id != AV_CODEC_ID_NONE) {
204  if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) {
205  id = avctag->id;
206  if (id == st->codec->codec_id)
207  return 1;
208  }
209  if (avctag->id == st->codec->codec_id)
210  tag = avctag->tag;
211  avctag++;
212  }
213  }
214  if (id != AV_CODEC_ID_NONE)
215  return 0;
216  if (tag && (st->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
217  return 0;
218  return 1;
219 }
220 
221 
223 {
224  int ret = 0, i;
225  AVStream *st;
226  AVDictionary *tmp = NULL;
227  AVCodecContext *codec = NULL;
228  AVOutputFormat *of = s->oformat;
229 
230  if (options)
231  av_dict_copy(&tmp, *options, 0);
232 
233  if ((ret = av_opt_set_dict(s, &tmp)) < 0)
234  goto fail;
235  if (s->priv_data && s->oformat->priv_class && *(const AVClass**)s->priv_data==s->oformat->priv_class &&
236  (ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
237  goto fail;
238 
239  // some sanity checks
240  if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
241  av_log(s, AV_LOG_ERROR, "no streams\n");
242  ret = AVERROR(EINVAL);
243  goto fail;
244  }
245 
246  for (i = 0; i < s->nb_streams; i++) {
247  st = s->streams[i];
248  codec = st->codec;
249 
250  switch (codec->codec_type) {
251  case AVMEDIA_TYPE_AUDIO:
252  if (codec->sample_rate <= 0) {
253  av_log(s, AV_LOG_ERROR, "sample rate not set\n");
254  ret = AVERROR(EINVAL);
255  goto fail;
256  }
257  if (!codec->block_align)
258  codec->block_align = codec->channels *
259  av_get_bits_per_sample(codec->codec_id) >> 3;
260  break;
261  case AVMEDIA_TYPE_VIDEO:
262  if (codec->time_base.num <= 0 ||
263  codec->time_base.den <= 0) { //FIXME audio too?
264  av_log(s, AV_LOG_ERROR, "time base not set\n");
265  ret = AVERROR(EINVAL);
266  goto fail;
267  }
268 
269  if ((codec->width <= 0 || codec->height <= 0) &&
270  !(of->flags & AVFMT_NODIMENSIONS)) {
271  av_log(s, AV_LOG_ERROR, "dimensions not set\n");
272  ret = AVERROR(EINVAL);
273  goto fail;
274  }
277  ) {
278  av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
279  "(%d/%d) and encoder layer (%d/%d)\n",
281  codec->sample_aspect_ratio.num,
282  codec->sample_aspect_ratio.den);
283  ret = AVERROR(EINVAL);
284  goto fail;
285  }
286  break;
287  }
288 
289  if (of->codec_tag) {
290  if ( codec->codec_tag
291  && codec->codec_id == AV_CODEC_ID_RAWVIDEO
292  && ( av_codec_get_tag(of->codec_tag, codec->codec_id) == 0
293  || av_codec_get_tag(of->codec_tag, codec->codec_id) == MKTAG('r', 'a', 'w', ' '))
294  && !validate_codec_tag(s, st)) {
295  // the current rawvideo encoding system ends up setting
296  // the wrong codec_tag for avi/mov, we override it here
297  codec->codec_tag = 0;
298  }
299  if (codec->codec_tag) {
300  if (!validate_codec_tag(s, st)) {
301  char tagbuf[32], cortag[32];
302  av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag);
303  av_get_codec_tag_string(cortag, sizeof(cortag), av_codec_get_tag(s->oformat->codec_tag, codec->codec_id));
304  av_log(s, AV_LOG_ERROR,
305  "Tag %s/0x%08x incompatible with output codec id '%d' (%s)\n",
306  tagbuf, codec->codec_tag, codec->codec_id, cortag);
307  ret = AVERROR_INVALIDDATA;
308  goto fail;
309  }
310  } else
311  codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id);
312  }
313 
314  if (of->flags & AVFMT_GLOBALHEADER &&
315  !(codec->flags & CODEC_FLAG_GLOBAL_HEADER))
317  "Codec for stream %d does not use global headers "
318  "but container format requires global headers\n", i);
319  }
320 
321  if (!s->priv_data && of->priv_data_size > 0) {
323  if (!s->priv_data) {
324  ret = AVERROR(ENOMEM);
325  goto fail;
326  }
327  if (of->priv_class) {
328  *(const AVClass **)s->priv_data = of->priv_class;
330  if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
331  goto fail;
332  }
333  }
334 
335  /* set muxer identification string */
336  if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
337  av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
338  }
339 
340  if (options) {
341  av_dict_free(options);
342  *options = tmp;
343  }
344 
345  return 0;
346 
347 fail:
348  av_dict_free(&tmp);
349  return ret;
350 }
351 
353 {
354  int i;
355  AVStream *st;
356 
357  /* init PTS generation */
358  for (i = 0; i < s->nb_streams; i++) {
359  int64_t den = AV_NOPTS_VALUE;
360  st = s->streams[i];
361 
362  switch (st->codec->codec_type) {
363  case AVMEDIA_TYPE_AUDIO:
364  den = (int64_t)st->time_base.num * st->codec->sample_rate;
365  break;
366  case AVMEDIA_TYPE_VIDEO:
367  den = (int64_t)st->time_base.num * st->codec->time_base.den;
368  break;
369  default:
370  break;
371  }
372  if (den != AV_NOPTS_VALUE) {
373  if (den <= 0)
374  return AVERROR_INVALIDDATA;
375 
376  frac_init(&st->pts, 0, 0, den);
377  }
378  }
379 
380  return 0;
381 }
382 
384 {
385  int ret = 0;
386 
387  if (ret = init_muxer(s, options))
388  return ret;
389 
390  if (s->oformat->write_header) {
391  ret = s->oformat->write_header(s);
392  if (ret >= 0 && s->pb && s->pb->error < 0)
393  ret = s->pb->error;
394  if (ret < 0)
395  return ret;
396  }
397 
398  if ((ret = init_pts(s)) < 0)
399  return ret;
400 
401  return 0;
402 }
403 
404 //FIXME merge with compute_pkt_fields
406 {
407  int delay = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames > 0);
408  int num, den, frame_size, i;
409 
410  av_dlog(s, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
411  av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
412 
413  /* duration field */
414  if (pkt->duration == 0) {
415  ff_compute_frame_duration(&num, &den, st, NULL, pkt);
416  if (den && num) {
417  pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
418  }
419  }
420 
421  if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
422  pkt->pts = pkt->dts;
423 
424  //XXX/FIXME this is a temporary hack until all encoders output pts
425  if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
426  static int warned;
427  if (!warned) {
428  av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
429  warned = 1;
430  }
431  pkt->dts =
432 // pkt->pts= st->cur_dts;
433  pkt->pts = st->pts.val;
434  }
435 
436  //calculate dts from pts
437  if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
438  st->pts_buffer[0] = pkt->pts;
439  for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
440  st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
441  for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
442  FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
443 
444  pkt->dts = st->pts_buffer[0];
445  }
446 
447  if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
448  ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
449  st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
450  av_log(s, AV_LOG_ERROR,
451  "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
452  st->index, av_ts2str(st->cur_dts), av_ts2str(pkt->dts));
453  return AVERROR(EINVAL);
454  }
455  if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
456  av_log(s, AV_LOG_ERROR, "pts (%s) < dts (%s) in stream %d\n",
457  av_ts2str(pkt->pts), av_ts2str(pkt->dts), st->index);
458  return AVERROR(EINVAL);
459  }
460 
461  av_dlog(s, "av_write_frame: pts2:%s dts2:%s\n",
462  av_ts2str(pkt->pts), av_ts2str(pkt->dts));
463  st->cur_dts = pkt->dts;
464  st->pts.val = pkt->dts;
465 
466  /* update pts */
467  switch (st->codec->codec_type) {
468  case AVMEDIA_TYPE_AUDIO:
469  frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 1);
470 
471  /* HACK/FIXME, we skip the initial 0 size packets as they are most
472  * likely equal to the encoder delay, but it would be better if we
473  * had the real timestamps from the encoder */
474  if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
475  frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
476  }
477  break;
478  case AVMEDIA_TYPE_VIDEO:
479  frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
480  break;
481  default:
482  break;
483  }
484  return 0;
485 }
486 
487 /**
488  * Move side data from payload to internal struct, call muxer, and restore
489  * original packet.
490  */
492 {
493  int ret, did_split;
494 
495  did_split = av_packet_split_side_data(pkt);
496  ret = s->oformat->write_packet(s, pkt);
497  if (s->flush_packets && s->pb && s->pb->error >= 0)
498  avio_flush(s->pb);
499  if (did_split)
501  return ret;
502 }
503 
505 {
506  int ret;
507 
508  if (!pkt) {
509  if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
510  ret = s->oformat->write_packet(s, NULL);
511  if (s->flush_packets && s->pb && s->pb->error >= 0)
512  avio_flush(s->pb);
513  if (ret >= 0 && s->pb && s->pb->error < 0)
514  ret = s->pb->error;
515  return ret;
516  }
517  return 1;
518  }
519 
520  ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
521 
522  if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
523  return ret;
524 
525  ret = split_write_packet(s, pkt);
526  if (ret >= 0 && s->pb && s->pb->error < 0)
527  ret = s->pb->error;
528 
529  if (ret >= 0)
530  s->streams[pkt->stream_index]->nb_frames++;
531  return ret;
532 }
533 
534 #define CHUNK_START 0x1000
535 
537  int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
538 {
539  AVPacketList **next_point, *this_pktl;
540  AVStream *st = s->streams[pkt->stream_index];
541  int chunked = s->max_chunk_size || s->max_chunk_duration;
542 
543  this_pktl = av_mallocz(sizeof(AVPacketList));
544  if (!this_pktl)
545  return AVERROR(ENOMEM);
546  this_pktl->pkt = *pkt;
547 #if FF_API_DESTRUCT_PACKET
548  pkt->destruct = NULL; // do not free original but only the copy
549 #endif
550  pkt->buf = NULL;
551  av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-allocated memory
552 
554  next_point = &(st->last_in_packet_buffer->next);
555  } else {
556  next_point = &s->packet_buffer;
557  }
558 
559  if (chunked) {
561  st->interleaver_chunk_size += pkt->size;
564  || (max && st->interleaver_chunk_duration > max)) {
565  st->interleaver_chunk_size = 0;
566  this_pktl->pkt.flags |= CHUNK_START;
567  if (max && st->interleaver_chunk_duration > max) {
568  int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
569  int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
570 
571  st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
572  } else
574  }
575  }
576  if (*next_point) {
577  if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
578  goto next_non_null;
579 
580  if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
581  while ( *next_point
582  && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
583  || !compare(s, &(*next_point)->pkt, pkt)))
584  next_point = &(*next_point)->next;
585  if (*next_point)
586  goto next_non_null;
587  } else {
588  next_point = &(s->packet_buffer_end->next);
589  }
590  }
591  av_assert1(!*next_point);
592 
593  s->packet_buffer_end = this_pktl;
594 next_non_null:
595 
596  this_pktl->next = *next_point;
597 
599  *next_point = this_pktl;
600  return 0;
601 }
602 
604 {
605  AVStream *st = s->streams[pkt->stream_index];
606  AVStream *st2 = s->streams[next->stream_index];
607  int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
608  st->time_base);
610  int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO);
611  int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO);
612  if (ts == ts2) {
613  ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den
614  -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den;
615  ts2=0;
616  }
617  comp= (ts>ts2) - (ts<ts2);
618  }
619 
620  if (comp == 0)
621  return pkt->stream_index < next->stream_index;
622  return comp > 0;
623 }
624 
626  AVPacket *pkt, int flush)
627 {
628  AVPacketList *pktl;
629  int stream_count = 0, noninterleaved_count = 0;
630  int64_t delta_dts_max = 0;
631  int i, ret;
632 
633  if (pkt) {
635  if (ret < 0)
636  return ret;
637  }
638 
639  for (i = 0; i < s->nb_streams; i++) {
640  if (s->streams[i]->last_in_packet_buffer) {
641  ++stream_count;
642  } else if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
643  ++noninterleaved_count;
644  }
645  }
646 
647  if (s->nb_streams == stream_count) {
648  flush = 1;
649  } else if (!flush) {
650  for (i=0; i < s->nb_streams; i++) {
651  if (s->streams[i]->last_in_packet_buffer) {
652  int64_t delta_dts =
654  s->streams[i]->time_base,
655  AV_TIME_BASE_Q) -
659  delta_dts_max= FFMAX(delta_dts_max, delta_dts);
660  }
661  }
662  if (s->nb_streams == stream_count+noninterleaved_count &&
663  delta_dts_max > 20*AV_TIME_BASE) {
664  av_log(s, AV_LOG_DEBUG, "flushing with %d noninterleaved\n", noninterleaved_count);
665  flush = 1;
666  }
667  }
668  if (stream_count && flush) {
669  AVStream *st;
670  pktl = s->packet_buffer;
671  *out = pktl->pkt;
672  st = s->streams[out->stream_index];
673 
674  s->packet_buffer = pktl->next;
675  if (!s->packet_buffer)
676  s->packet_buffer_end = NULL;
677 
678  if (st->last_in_packet_buffer == pktl)
680  av_freep(&pktl);
681 
682  if (s->avoid_negative_ts > 0) {
683  if (out->dts != AV_NOPTS_VALUE) {
684  if (!st->mux_ts_offset && out->dts < 0) {
685  for (i = 0; i < s->nb_streams; i++) {
686  s->streams[i]->mux_ts_offset =
687  av_rescale_q_rnd(-out->dts,
688  st->time_base,
689  s->streams[i]->time_base,
690  AV_ROUND_UP);
691  }
692  }
693  out->dts += st->mux_ts_offset;
694  }
695  if (out->pts != AV_NOPTS_VALUE)
696  out->pts += st->mux_ts_offset;
697  }
698 
699  return 1;
700  } else {
701  av_init_packet(out);
702  return 0;
703  }
704 }
705 
706 /**
707  * Interleave an AVPacket correctly so it can be muxed.
708  * @param out the interleaved packet will be output here
709  * @param in the input packet
710  * @param flush 1 if no further packets are available as input and all
711  * remaining packets should be output
712  * @return 1 if a packet was output, 0 if no packet could be output,
713  * < 0 if an error occurred
714  */
716 {
717  if (s->oformat->interleave_packet) {
718  int ret = s->oformat->interleave_packet(s, out, in, flush);
719  if (in)
720  av_free_packet(in);
721  return ret;
722  } else
723  return ff_interleave_packet_per_dts(s, out, in, flush);
724 }
725 
727 {
728  int ret, flush = 0;
729 
730  if (pkt) {
731  AVStream *st = s->streams[pkt->stream_index];
732 
733  //FIXME/XXX/HACK drop zero sized packets
734  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0)
735  return 0;
736 
737  av_dlog(s, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",
738  pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
739  if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
740  return ret;
741 
742  if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
743  return AVERROR(EINVAL);
744  } else {
745  av_dlog(s, "av_interleaved_write_frame FLUSH\n");
746  flush = 1;
747  }
748 
749  for (;; ) {
750  AVPacket opkt;
751  int ret = interleave_packet(s, &opkt, pkt, flush);
752  if (ret <= 0) //FIXME cleanup needed for ret<0 ?
753  return ret;
754 
755  ret = split_write_packet(s, &opkt);
756  if (ret >= 0)
757  s->streams[opkt.stream_index]->nb_frames++;
758 
759  av_free_packet(&opkt);
760  pkt = NULL;
761 
762  if (ret < 0)
763  return ret;
764  if(s->pb && s->pb->error)
765  return s->pb->error;
766  }
767 }
768 
770 {
771  int ret, i;
772 
773  for (;; ) {
774  AVPacket pkt;
775  ret = interleave_packet(s, &pkt, NULL, 1);
776  if (ret < 0) //FIXME cleanup needed for ret<0 ?
777  goto fail;
778  if (!ret)
779  break;
780 
781  ret = split_write_packet(s, &pkt);
782  if (ret >= 0)
783  s->streams[pkt.stream_index]->nb_frames++;
784 
785  av_free_packet(&pkt);
786 
787  if (ret < 0)
788  goto fail;
789  if(s->pb && s->pb->error)
790  goto fail;
791  }
792 
793  if (s->oformat->write_trailer)
794  ret = s->oformat->write_trailer(s);
795 
796 fail:
797  if (s->pb)
798  avio_flush(s->pb);
799  if (ret == 0)
800  ret = s->pb ? s->pb->error : 0;
801  for (i = 0; i < s->nb_streams; i++) {
802  av_freep(&s->streams[i]->priv_data);
803  av_freep(&s->streams[i]->index_entries);
804  }
805  if (s->oformat->priv_class)
807  av_freep(&s->priv_data);
808  return ret;
809 }
810 
811 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
812  int64_t *dts, int64_t *wall)
813 {
814  if (!s->oformat || !s->oformat->get_output_timestamp)
815  return AVERROR(ENOSYS);
816  s->oformat->get_output_timestamp(s, stream, dts, wall);
817  return 0;
818 }
int64_t interleaver_chunk_size
Definition: avformat.h:807
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:205
int audio_preload
Audio preload in microseconds.
Definition: avformat.h:1145
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
enum AVCodecID id
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition: mux.c:726
int flush_packets
Flush the I/O context after each packet.
Definition: avformat.h:1223
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
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Definition: mux.c:504
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition: avformat.h:820
if max(w)>1 w=0.9 *w/max(w)
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...
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:942
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:644
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:625
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:822
Sinusoidal phase f
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:55
int av_get_output_timestamp(struct AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Get timing information for the data currently output.
Definition: mux.c:811
void * priv_data
Definition: avformat.h:663
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.
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 av_dup_packet(AVPacket *pkt)
Definition: avpacket.c:221
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:361
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:363
int ff_get_audio_frame_size(AVCodecContext *enc, int size, int mux)
Get the number of samples of an audio frame.
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:1238
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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
int(* interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush)
Currently only used to set pixel format if not YUV420P.
Definition: avformat.h:434
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
int64_t cur_dts
Definition: avformat.h:785
internal metadata API header see avformat.h or the public API!
#define CHUNK_START
Definition: mux.c:534
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:68
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
Round toward +infinity.
Definition: mathematics.h:71
AVOptions.
static int split_write_packet(AVFormatContext *s, AVPacket *pkt)
Move side data from payload to internal struct, call muxer, and restore original packet.
Definition: mux.c:491
timestamp utils, mostly useful for debugging/logging purposes
AVPacket pkt
Definition: avformat.h:1280
int priv_data_size
size of private data so that it can be allocated in the wrapper
Definition: avformat.h:419
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
static AVPacket pkt
Definition: demuxing.c:56
AVStream ** streams
Definition: avformat.h:992
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
#define MAX_REORDER_DELAY
Definition: avformat.h:819
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
uint32_t tag
Definition: movenc.c:894
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
Interleave an AVPacket correctly so it can be muxed.
Definition: mux.c:715
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
const OptionDef options[]
Definition: ffserver.c:4697
int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:125
struct AVOutputFormat * oformat
Definition: avformat.h:958
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
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
AVCodecID
Identify the syntax and semantics of the bitstream.
int has_b_frames
Size of the frame reordering buffer in the decoder.
AVDictionary * metadata
Definition: avformat.h:1092
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
static int validate_codec_tag(AVFormatContext *s, AVStream *st)
Definition: mux.c:188
#define FF_COMPLIANCE_NORMAL
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
CODEC_FLAG_*.
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:246
#define FFMAX(a, b)
Definition: common.h:56
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:82
The exact value of the fractional number is: &#39;val + num / den&#39;.
Definition: avformat.h:322
int flags
A combination of AV_PKT_FLAG values.
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:135
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
int av_packet_merge_side_data(AVPacket *pkt)
Definition: avpacket.c:306
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
struct AVRational AVRational
rational number numerator/denominator
#define LIBAVFORMAT_IDENT
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:122
int void avio_flush(AVIOContext *s)
Force flushing of buffered data to the output s.
Definition: aviobuf.c:193
int(* write_header)(struct AVFormatContext *)
Definition: avformat.h:421
char filename[1024]
input or output filename
Definition: avformat.h:994
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
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:118
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:196
ret
Definition: avfilter.c:821
int width
picture width / height.
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:351
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
#define FFABS(a)
Definition: common.h:53
int avoid_negative_ts
Avoid negative timestamps during muxing.
Definition: avformat.h:1180
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...
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static int init_muxer(AVFormatContext *s, AVDictionary **options)
Definition: mux.c:222
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:406
static void flush(AVCodecContext *avctx)
int av_packet_split_side_data(AVPacket *pkt)
Definition: avpacket.c:344
Stream structure.
Definition: avformat.h:643
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:352
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:202
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1202
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
const struct AVCodecTag *const * codec_tag
List of supported codec_id-codec_tag pairs, ordered by "better choice first".
Definition: avformat.h:403
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
int(* write_trailer)(struct AVFormatContext *)
Definition: avformat.h:430
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:62
Describe the class of an AVClass context structure.
Definition: log.h:50
synthesis window for stochastic i
unsigned int avpriv_toupper4(unsigned int x)
rational number numerator/denominator
Definition: rational.h:43
struct AVPacketList * packet_buffer_end
Definition: avformat.h:1239
void(* get_output_timestamp)(struct AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Definition: avformat.h:445
AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission)
Chooses a timebase for muxing the specified stream.
Definition: mux.c:106
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int error
contains the error code or 0 if no error happened
Definition: avio.h:102
static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt)
Definition: mux.c:603
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
misc parsing utilities
int64_t val
Definition: avformat.h:323
int64_t num
Definition: avformat.h:323
unsigned int tag
int64_t den
Definition: avformat.h:323
int64_t interleaver_chunk_duration
Definition: avformat.h:808
Main libavformat public API header.
int 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:536
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:1194
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
struct AVPacketList * next
Definition: avformat.h:1281
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition: avformat.h:357
int max_chunk_size
Max chunk size in bytes Note, not all formats support this and unpredictable things may happen if it ...
Definition: avformat.h:1161
static int init_pts(AVFormatContext *s)
Definition: mux.c:352
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:56
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:698
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:86
int64_t mux_ts_offset
Timestamp offset added to timestamps before muxing NOT PART OF PUBLIC API.
Definition: avformat.h:856
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:50
struct AVFrac pts
encoding: pts generation when outputting stream
Definition: avformat.h:668
int channels
number of audio channels
int max_chunk_duration
Max chunk time in microseconds.
Definition: avformat.h:1153
void * priv_data
Format private data.
Definition: avformat.h:964
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition: avformat.h:356
static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: mux.c:405
int(* write_packet)(struct AVFormatContext *, AVPacket *pkt)
Write a packet.
Definition: avformat.h:429
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
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 comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71
unbuffered private I/O API
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
#define FFSWAP(type, a, b)
Definition: common.h:61
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
#define MKTAG(a, b, c, d)
Definition: common.h:282
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.
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
struct AVPacketList * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
Definition: avformat.h:817
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190