FFmpeg
Loading...
Searching...
No Matches
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#include "avformat.h"
23#include "avformat_internal.h"
24#include "internal.h"
25#include "mux.h"
26#include "version.h"
27#include "libavcodec/bsf.h"
29#include "libavcodec/internal.h"
30#include "packet_internal.h"
31#include "libavutil/mem.h"
32#include "libavutil/opt.h"
33#include "libavutil/dict.h"
34#include "libavutil/timestamp.h"
35#include "libavutil/avassert.h"
36#include "libavutil/frame.h"
37#include "libavutil/internal.h"
39
40/**
41 * @file
42 * muxing functions for use within libavformat
43 */
44
45/* fraction handling */
46
47/**
48 * f = val + (num / den) + 0.5.
49 *
50 * 'num' is normalized so that it is such as 0 <= num < den.
51 *
52 * @param f fractional number
53 * @param val integer value
54 * @param num must be >= 0
55 * @param den must be >= 1
56 */
58{
59 num += (den >> 1);
60 if (num >= den) {
61 val += num / den;
62 num = num % den;
63 }
64 f->val = val;
65 f->num = num;
66 f->den = den;
67}
68
69/**
70 * Fractional addition to f: f = f + (incr / f->den).
71 *
72 * @param f fractional number
73 * @param incr increment, can be positive or negative
74 */
75static void frac_add(FFFrac *f, int64_t incr)
76{
77 int64_t num, den;
78
79 num = f->num + incr;
80 den = f->den;
81 if (num < 0) {
82 f->val += num / den;
83 num = num % den;
84 if (num < 0) {
85 num += den;
86 f->val--;
87 }
88 } else if (num >= den) {
89 f->val += num / den;
90 num = num % den;
91 }
92 f->num = num;
93}
94
96 const char *format, const char *filename)
97{
99 int ret = 0;
100
101 *avctx = NULL;
102 if (!s)
103 goto nomem;
104
105 if (!oformat) {
106 if (format) {
107 oformat = av_guess_format(format, NULL, NULL);
108 if (!oformat) {
109 av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not known.\n", format);
110 ret = AVERROR(EINVAL);
111 goto error;
112 }
113 } else {
114 oformat = av_guess_format(NULL, filename, NULL);
115 if (!oformat) {
116 ret = AVERROR(EINVAL);
118 "Unable to choose an output format for '%s'; "
119 "use a standard extension for the filename or specify "
120 "the format manually.\n", filename);
121 goto error;
122 }
123 }
124 }
125
126 s->oformat = oformat;
127 if (ffofmt(s->oformat)->priv_data_size > 0) {
128 s->priv_data = av_mallocz(ffofmt(s->oformat)->priv_data_size);
129 if (!s->priv_data)
130 goto nomem;
131 if (s->oformat->priv_class) {
132 *(const AVClass**)s->priv_data= s->oformat->priv_class;
133 av_opt_set_defaults(s->priv_data);
134 }
135 } else
136 s->priv_data = NULL;
137
138 if (filename) {
139 if (!(s->url = av_strdup(filename)))
140 goto nomem;
141
142 }
143 *avctx = s;
144 return 0;
145nomem:
146 av_log(s, AV_LOG_ERROR, "Out of memory\n");
147 ret = AVERROR(ENOMEM);
148error:
150 return ret;
151}
152
153static int validate_codec_tag(const AVFormatContext *s, const AVStream *st)
154{
155 const AVCodecTag *avctag;
156 enum AVCodecID id = AV_CODEC_ID_NONE;
157 unsigned uppercase_tag = ff_toupper4(st->codecpar->codec_tag);
158 int64_t tag = -1;
159
160 /**
161 * Check that tag + id is in the table
162 * If neither is in the table -> OK
163 * If tag is in the table with another id -> FAIL
164 * If id is in the table with another tag -> FAIL unless strict < normal
165 */
166 for (int n = 0; s->oformat->codec_tag[n]; n++) {
167 avctag = s->oformat->codec_tag[n];
168 while (avctag->id != AV_CODEC_ID_NONE) {
169 if (ff_toupper4(avctag->tag) == uppercase_tag) {
170 id = avctag->id;
171 if (id == st->codecpar->codec_id)
172 return 1;
173 }
174 if (avctag->id == st->codecpar->codec_id)
175 tag = avctag->tag;
176 avctag++;
177 }
178 }
179 if (id != AV_CODEC_ID_NONE)
180 return 0;
181 if (tag >= 0 && (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
182 return 0;
183 return 1;
184}
185
186
188{
191 const FFOutputFormat *of = ffofmt(s->oformat);
193 static const unsigned default_codec_offsets[] = {
194 [AVMEDIA_TYPE_VIDEO] = offsetof(AVOutputFormat, video_codec),
195 [AVMEDIA_TYPE_AUDIO] = offsetof(AVOutputFormat, audio_codec),
196 [AVMEDIA_TYPE_SUBTITLE] = offsetof(AVOutputFormat, subtitle_codec),
197 };
198 unsigned nb_type[FF_ARRAY_ELEMS(default_codec_offsets)] = { 0 };
199 int ret = 0;
200
201 if (options)
202 av_dict_copy(&tmp, *options, 0);
203
204 if ((ret = av_opt_set_dict(s, &tmp)) < 0)
205 goto fail;
206 if (s->priv_data && s->oformat->priv_class && *(const AVClass**)s->priv_data==s->oformat->priv_class &&
207 (ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
208 goto fail;
209
210 if (!s->url && !(s->url = av_strdup(""))) {
211 ret = AVERROR(ENOMEM);
212 goto fail;
213 }
214
215 // some sanity checks
216 if (s->nb_streams == 0 && !(of->p.flags & AVFMT_NOSTREAMS)) {
217 av_log(s, AV_LOG_ERROR, "No streams to mux were specified\n");
218 ret = AVERROR(EINVAL);
219 goto fail;
220 }
221
222 for (unsigned i = 0; i < s->nb_streams; i++) {
223 AVStream *const st = s->streams[i];
224 FFStream *const sti = ffstream(st);
225 AVCodecParameters *const par = st->codecpar;
226 const AVCodecDescriptor *desc;
227
228 if (!st->time_base.num) {
229 /* fall back on the default timebase values */
230 if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate)
231 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
232 else
233 avpriv_set_pts_info(st, 33, 1, 90000);
234 }
235
236 switch (par->codec_type) {
238 if (par->sample_rate <= 0) {
239 av_log(s, AV_LOG_ERROR, "sample rate not set\n");
240 ret = AVERROR(EINVAL);
241 goto fail;
242 }
243
244 if (!par->block_align)
245 par->block_align = par->ch_layout.nb_channels *
247 break;
249 if ((par->width <= 0 || par->height <= 0) &&
250 !(of->p.flags & AVFMT_NODIMENSIONS)) {
251 av_log(s, AV_LOG_ERROR, "dimensions not set\n");
252 ret = AVERROR(EINVAL);
253 goto fail;
254 }
257 ) {
258 if (st->sample_aspect_ratio.num != 0 &&
259 st->sample_aspect_ratio.den != 0 &&
260 par->sample_aspect_ratio.num != 0 &&
261 par->sample_aspect_ratio.den != 0) {
262 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
263 "(%d/%d) and encoder layer (%d/%d)\n",
267 ret = AVERROR(EINVAL);
268 goto fail;
269 }
270 }
271 break;
272 }
274 enum AVCodecID default_codec_id = AV_CODEC_ID_NONE;
275 unsigned nb;
276 if ((unsigned)par->codec_type < FF_ARRAY_ELEMS(default_codec_offsets)) {
277 nb = ++nb_type[par->codec_type];
278 if (default_codec_offsets[par->codec_type])
279 default_codec_id = *(const enum AVCodecID*)((const char*)of + default_codec_offsets[par->codec_type]);
280 }
282 default_codec_id != AV_CODEC_ID_NONE && par->codec_id != default_codec_id) {
283 av_log(s, AV_LOG_ERROR, "%s muxer supports only codec %s for type %s\n",
284 of->p.name, avcodec_get_name(default_codec_id), av_get_media_type_string(par->codec_type));
285 ret = AVERROR(EINVAL);
286 goto fail;
287 } else if (default_codec_id == AV_CODEC_ID_NONE ||
289 const char *type = av_get_media_type_string(par->codec_type);
290 av_log(s, AV_LOG_ERROR, "%s muxer does not support %s stream of type %s\n",
291 of->p.name, default_codec_id == AV_CODEC_ID_NONE ? "any" : "more than one",
292 type ? type : "unknown");
293 ret = AVERROR(EINVAL);
294 goto fail;
295 }
296 }
297
299 if (desc && desc->props & AV_CODEC_PROP_REORDER)
300 sti->reorder = 1;
301
303
304 if (of->p.codec_tag) {
305 if ( par->codec_tag
307 && ( av_codec_get_tag(of->p.codec_tag, par->codec_id) == 0
308 || av_codec_get_tag(of->p.codec_tag, par->codec_id) == MKTAG('r', 'a', 'w', ' '))
309 && !validate_codec_tag(s, st)) {
310 // the current rawvideo encoding system ends up setting
311 // the wrong codec_tag for avi/mov, we override it here
312 par->codec_tag = 0;
313 }
314 if (par->codec_tag) {
315 if (!validate_codec_tag(s, st)) {
316 const uint32_t otag = av_codec_get_tag(s->oformat->codec_tag, par->codec_id);
318 "Tag %s incompatible with output codec id '%d' (%s)\n",
319 av_fourcc2str(par->codec_tag), par->codec_id, av_fourcc2str(otag));
321 goto fail;
322 }
323 } else
325 }
326
330 }
331 for (unsigned i = 0; i < s->nb_stream_groups; i++) {
332 AVStreamGroup *const stg = s->stream_groups[i];
333
334 switch (stg->type) {
336#if FF_API_STREAM_GROUP_ENTRIES
338 AVStreamGroupTileGrid *tile_grid = stg->params.tile_grid;
339
340 // If both the global and the deprecated Tile Grid specific
341 // side data arrays are populated, prefer the latter.
342 if (tile_grid->nb_coded_side_data && stg->nb_coded_side_data)
344 &stg->nb_coded_side_data);
345 if (tile_grid->nb_coded_side_data) {
346 for (int j = 0; j < tile_grid->nb_coded_side_data; j++) {
347 const AVPacketSideData *src = &tile_grid->coded_side_data[j];
349
351 &stg->nb_coded_side_data,
352 src->type, src->size, 0);
353 if (!dst) {
354 ret = AVERROR(ENOMEM);
355 goto fail;
356 }
357
358 memcpy(dst->data, src->data, src->size);
359 }
360 }
361 break;
363#endif
364 }
365 default:
366 break;
367 }
368 }
370 if (!fci->interleave_packet)
374
375 if (!s->priv_data && of->priv_data_size > 0) {
376 s->priv_data = av_mallocz(of->priv_data_size);
377 if (!s->priv_data) {
378 ret = AVERROR(ENOMEM);
379 goto fail;
380 }
381 if (of->p.priv_class) {
382 *(const AVClass **)s->priv_data = of->p.priv_class;
383 av_opt_set_defaults(s->priv_data);
384 if ((ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
385 goto fail;
386 }
387 }
388
389 /* set muxer identification string */
390 if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
391 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
392 } else {
393 av_dict_set(&s->metadata, "encoder", NULL, 0);
394 }
395
396 for (e = NULL; e = av_dict_get(s->metadata, "encoder-", e, AV_DICT_IGNORE_SUFFIX); ) {
397 av_dict_set(&s->metadata, e->key, NULL, 0);
398 }
399
400 if (options) {
402 *options = tmp;
403 }
404
405 if (of->init) {
406 if ((ret = of->init(s)) < 0) {
407 if (of->deinit)
408 of->deinit(s);
409 return ret;
410 }
411 return ret == 0;
412 }
413
414 return 0;
415
416fail:
418 return ret;
419}
420
422{
423 FFFormatContext *const si = ffformatcontext(s);
424
425 /* init PTS generation */
426 for (unsigned i = 0; i < s->nb_streams; i++) {
427 AVStream *const st = s->streams[i];
428 FFStream *const sti = ffstream(st);
430
431 switch (st->codecpar->codec_type) {
433 den = (int64_t)st->time_base.num * st->codecpar->sample_rate;
434 break;
436 den = (int64_t)st->time_base.num * st->time_base.den;
437 break;
438 default:
439 break;
440 }
441
442 if (den != AV_NOPTS_VALUE) {
443 if (den <= 0)
444 return AVERROR_INVALIDDATA;
445
446 frac_init(&sti->priv_pts, 0, 0, den);
447 }
448 }
449
450 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_UNKNOWN;
451 if (s->avoid_negative_ts < 0) {
452 av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO);
453 if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
454 s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_DISABLED;
455 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
456 } else
457 s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
458 } else if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_DISABLED)
459 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
460
461 return 0;
462}
463
465{
466 if (s->pb && s->pb->error >= 0) {
467 if (s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS)
468 avio_flush(s->pb);
469 else if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE))
471 }
472}
473
475{
477 const FFOutputFormat *const of = ffofmt(s->oformat);
478 if (of && of->deinit && fci->initialized)
479 of->deinit(s);
480 fci->initialized =
481 fci->streams_initialized = 0;
482}
483
485{
487 int ret = 0;
488
489 if ((ret = init_muxer(s, options)) < 0)
490 return ret;
491
492 fci->initialized = 1;
493 fci->streams_initialized = ret;
494
495 if (ffofmt(s->oformat)->init && ret) {
496 if ((ret = init_pts(s)) < 0)
497 return ret;
498
500 }
501
503}
504
506{
508 int already_initialized = fci->initialized;
509 int streams_already_initialized = fci->streams_initialized;
510 int ret = 0;
511
512 if (!already_initialized)
513 if ((ret = avformat_init_output(s, options)) < 0)
514 return ret;
515
516 if (ffofmt(s->oformat)->write_header) {
517 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
519 ret = ffofmt(s->oformat)->write_header(s);
520 if (ret >= 0 && s->pb && s->pb->error < 0)
521 ret = s->pb->error;
522 if (ret < 0)
523 goto fail;
525 }
526 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
528
529 if (!fci->streams_initialized) {
530 if ((ret = init_pts(s)) < 0)
531 goto fail;
532 }
533
534 return streams_already_initialized;
535
536fail:
538 return ret;
539}
540
541#define AV_PKT_FLAG_UNCODED_FRAME 0x2000
542
543
544#if FF_API_COMPUTE_PKT_FIELDS2
546//FIXME merge with compute_pkt_fields
547static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt)
548{
550 FFStream *const sti = ffstream(st);
551 int delay = st->codecpar->video_delay;
552 int frame_size;
553
554 if (!fci->missing_ts_warning &&
555 !(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
557 (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
559 "Timestamps are unset in a packet for stream %d. "
560 "This is deprecated and will stop working in the future. "
561 "Fix your code to set the timestamps properly\n", st->index);
562 fci->missing_ts_warning = 1;
563 }
564
565 if (s->debug & AV_FDEBUG_TS)
566 av_log(s, AV_LOG_DEBUG, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
567 av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), delay, pkt->size, pkt->stream_index);
568
569 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
570 pkt->pts = pkt->dts;
571
572 //XXX/FIXME this is a temporary hack until all encoders output pts
573 if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
574 static int warned;
575 if (!warned) {
576 av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
577 warned = 1;
578 }
579 pkt->dts =
580// pkt->pts= st->cur_dts;
581 pkt->pts = sti->priv_pts.val;
582 }
583
584 //calculate dts from pts
585 if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
586 sti->pts_buffer[0] = pkt->pts;
587 for (int i = 1; i < delay + 1 && sti->pts_buffer[i] == AV_NOPTS_VALUE; i++)
588 sti->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
589 for (int i = 0; i<delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++)
590 FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]);
591
592 pkt->dts = sti->pts_buffer[0];
593 }
594
595 if (sti->cur_dts && sti->cur_dts != AV_NOPTS_VALUE &&
596 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
599 sti->cur_dts >= pkt->dts) || sti->cur_dts > pkt->dts)) {
601 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
602 st->index, av_ts2str(sti->cur_dts), av_ts2str(pkt->dts));
603 return AVERROR(EINVAL);
604 }
605 if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
607 "pts (%s) < dts (%s) in stream %d\n",
608 av_ts2str(pkt->pts), av_ts2str(pkt->dts),
609 st->index);
610 return AVERROR(EINVAL);
611 }
612
613 if (s->debug & AV_FDEBUG_TS)
614 av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%s dts2:%s\n",
615 av_ts2str(pkt->pts), av_ts2str(pkt->dts));
616
617 sti->cur_dts = pkt->dts;
618 sti->priv_pts.val = pkt->dts;
619
620 /* update pts */
621 switch (st->codecpar->codec_type) {
624 (*(AVFrame **)pkt->data)->nb_samples :
626
627 /* HACK/FIXME, we skip the initial 0 size packets as they are most
628 * likely equal to the encoder delay, but it would be better if we
629 * had the real timestamps from the encoder */
630 if (frame_size >= 0 && (pkt->size || sti->priv_pts.num != sti->priv_pts.den >> 1 || sti->priv_pts.val)) {
632 }
633 break;
636 break;
637 }
638 return 0;
639}
641#endif
642
644{
645 if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
646 av_log(s, AV_LOG_WARNING, "Packet with invalid duration %"PRId64" in stream %d\n",
647 pkt->duration, pkt->stream_index);
648 pkt->duration = 0;
649 }
650
651 if (pkt->duration)
652 return;
653
654 switch (st->codecpar->codec_type) {
656 if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) {
657 pkt->duration = av_rescale_q(1, av_inv_q(st->avg_frame_rate),
658 st->time_base);
659 } else if (st->time_base.num * 1000LL > st->time_base.den)
660 pkt->duration = 1;
661 break;
662 case AVMEDIA_TYPE_AUDIO: {
664 if (frame_size && st->codecpar->sample_rate) {
665 pkt->duration = av_rescale_q(frame_size,
667 st->time_base);
668 }
669 break;
670 }
671 }
672}
673
675 AVPacket *pkt)
676{
677 AVFormatContext *const s = &si->pub;
679
681 return;
682
683 if (si->avoid_negative_ts_status == AVOID_NEGATIVE_TS_UNKNOWN) {
684 int use_pts = si->avoid_negative_ts_use_pts;
685 int64_t ts = use_pts ? pkt->pts : pkt->dts;
686 AVRational tb = sti->pub.time_base;
687
688 if (ts == AV_NOPTS_VALUE)
689 return;
690
691 ts -= sti->lowest_ts_allowed;
692
693 /* Peek into the muxing queue to improve our estimate
694 * of the lowest timestamp if av_interleaved_write_frame() is used. */
695 for (const PacketListEntry *pktl = si->packet_buffer.head;
696 pktl; pktl = pktl->next) {
697 AVRational cmp_tb = s->streams[pktl->pkt.stream_index]->time_base;
698 int64_t cmp_ts = use_pts ? pktl->pkt.pts : pktl->pkt.dts;
699 if (cmp_ts == AV_NOPTS_VALUE)
700 continue;
701 cmp_ts -= ffstream(s->streams[pktl->pkt.stream_index])->lowest_ts_allowed;
702 if (s->output_ts_offset)
703 cmp_ts += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, cmp_tb);
704 if (av_compare_ts(cmp_ts, cmp_tb, ts, tb) < 0) {
705 ts = cmp_ts;
706 tb = cmp_tb;
707 }
708 }
709
710 if (ts < 0 ||
711 ts > 0 && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
712 for (unsigned i = 0; i < s->nb_streams; i++) {
713 AVStream *const st2 = s->streams[i];
714 FFStream *const sti2 = ffstream(st2);
715 sti2->mux_ts_offset = av_rescale_q_rnd(-ts, tb,
716 st2->time_base,
718 }
719 }
720 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_KNOWN;
721 }
722
723 offset = sti->mux_ts_offset;
724
725 if (pkt->dts != AV_NOPTS_VALUE)
726 pkt->dts += offset;
727 if (pkt->pts != AV_NOPTS_VALUE)
728 pkt->pts += offset;
729
731 if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < sti->lowest_ts_allowed) {
732 av_log(s, AV_LOG_WARNING, "failed to avoid negative "
733 "pts %s in stream %d.\n"
734 "Try -avoid_negative_ts 1 as a possible workaround.\n",
735 av_ts2str(pkt->pts),
736 pkt->stream_index
737 );
738 }
739 } else {
740 if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < sti->lowest_ts_allowed) {
742 "Packets poorly interleaved, failed to avoid negative "
743 "timestamp %s in stream %d.\n"
744 "Try -max_interleave_delta 0 as a possible workaround.\n",
745 av_ts2str(pkt->dts),
746 pkt->stream_index
747 );
748 }
749 }
750}
751
752/**
753 * Shift timestamps and call muxer; the original pts/dts are not kept.
754 *
755 * FIXME: this function should NEVER get undefined pts/dts beside when the
756 * AVFMT_NOTIMESTAMPS is set.
757 * Those additional safety checks should be dropped once the correct checks
758 * are set in the callers.
759 */
761{
762 FFFormatContext *const si = ffformatcontext(s);
763 AVStream *const st = s->streams[pkt->stream_index];
764 FFStream *const sti = ffstream(st);
765 int ret;
766
767 // If the timestamp offsetting below is adjusted, adjust
768 // ff_interleaved_peek similarly.
769 if (s->output_ts_offset) {
770 int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
771
772 if (pkt->dts != AV_NOPTS_VALUE)
773 pkt->dts += offset;
774 if (pkt->pts != AV_NOPTS_VALUE)
775 pkt->pts += offset;
776 }
778
779 if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
780 AVFrame **frame = (AVFrame **)pkt->data;
781 av_assert0(pkt->size == sizeof(*frame));
782 ret = ffofmt(s->oformat)->write_uncoded_frame(s, pkt->stream_index, frame, 0);
783 } else {
784 ret = ffofmt(s->oformat)->write_packet(s, pkt);
785 }
786
787 if (s->pb && ret >= 0) {
789 if (s->pb->error < 0)
790 ret = s->pb->error;
791 }
792
793 if (ret >= 0)
794 st->nb_frames++;
795
796 return ret;
797}
798
800{
801 if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
802 av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
803 pkt->stream_index);
804 return AVERROR(EINVAL);
805 }
806
807 if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
808 av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n");
809 return AVERROR(EINVAL);
810 }
811
812 return 0;
813}
814
816{
817 FFStream *const sti = ffstream(st);
818#if !FF_API_COMPUTE_PKT_FIELDS2
819 /* sanitize the timestamps */
820 if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
821
822 /* when there is no reordering (so dts is equal to pts), but
823 * only one of them is set, set the other as well */
824 if (!sti->reorder) {
825 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE)
826 pkt->pts = pkt->dts;
827 if (pkt->dts == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE)
828 pkt->dts = pkt->pts;
829 }
830
831 /* check that the timestamps are set */
832 if (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE) {
834 "Timestamps are unset in a packet for stream %d\n", st->index);
835 return AVERROR(EINVAL);
836 }
837
838 /* check that the dts are increasing (or at least non-decreasing,
839 * if the format allows it */
840 if (sti->cur_dts != AV_NOPTS_VALUE &&
841 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && sti->cur_dts >= pkt->dts) ||
842 sti->cur_dts > pkt->dts)) {
844 "Application provided invalid, non monotonically increasing "
845 "dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
846 st->index, sti->cur_dts, pkt->dts);
847 return AVERROR(EINVAL);
848 }
849
850 if (pkt->pts < pkt->dts) {
851 av_log(s, AV_LOG_ERROR, "pts %" PRId64 " < dts %" PRId64 " in stream %d\n",
852 pkt->pts, pkt->dts, st->index);
853 return AVERROR(EINVAL);
854 }
855 }
856#endif
857 /* update flags */
858 if (sti->is_intra_only)
859 pkt->flags |= AV_PKT_FLAG_KEY;
860
861 if (!pkt->data && !pkt->side_data_elems) {
862 /* Such empty packets signal EOS for the BSF API; so sanitize
863 * the packet by allocating data of size 0 (+ padding). */
864 av_buffer_unref(&pkt->buf);
866 }
867
868 return 0;
869}
870
871#define CHUNK_START 0x1000
872
874 int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
875{
876 int ret;
877 FFFormatContext *const si = ffformatcontext(s);
878 PacketListEntry **next_point, *this_pktl;
879 AVStream *st = s->streams[pkt->stream_index];
880 FFStream *const sti = ffstream(st);
881 int chunked = s->max_chunk_size || s->max_chunk_duration;
882
883 this_pktl = av_malloc(sizeof(*this_pktl));
884 if (!this_pktl) {
886 return AVERROR(ENOMEM);
887 }
888 if ((ret = av_packet_make_refcounted(pkt)) < 0) {
889 av_free(this_pktl);
891 return ret;
892 }
893
894 av_packet_move_ref(&this_pktl->pkt, pkt);
895 pkt = &this_pktl->pkt;
896
897 if (sti->last_in_packet_buffer) {
898 next_point = &(sti->last_in_packet_buffer->next);
899 } else {
900 next_point = &si->packet_buffer.head;
901 }
902
903 if (chunked) {
904 uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);
905 sti->interleaver_chunk_size += pkt->size;
906 sti->interleaver_chunk_duration += pkt->duration;
907 if ( (s->max_chunk_size && sti->interleaver_chunk_size > s->max_chunk_size)
908 || (max && sti->interleaver_chunk_duration > max)) {
909 sti->interleaver_chunk_size = 0;
910 pkt->flags |= CHUNK_START;
911 if (max && sti->interleaver_chunk_duration > max) {
912 int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
913 int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
914
915 sti->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
916 } else
918 }
919 }
920 if (*next_point) {
921 if (chunked && !(pkt->flags & CHUNK_START))
922 goto next_non_null;
923
924 if (compare(s, &si->packet_buffer.tail->pkt, pkt)) {
925 while ( *next_point
926 && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
927 || !compare(s, &(*next_point)->pkt, pkt)))
928 next_point = &(*next_point)->next;
929 if (*next_point)
930 goto next_non_null;
931 } else {
932 next_point = &(si->packet_buffer.tail->next);
933 }
934 }
935 av_assert1(!*next_point);
936
937 si->packet_buffer.tail = this_pktl;
938next_non_null:
939
940 this_pktl->next = *next_point;
941
942 sti->last_in_packet_buffer = *next_point = this_pktl;
943
944 return 0;
945}
946
948 const AVPacket *pkt)
949{
950 AVStream *st = s->streams[pkt->stream_index];
951 AVStream *st2 = s->streams[next->stream_index];
952 int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
953 st->time_base);
954 if (s->audio_preload) {
955 int preload = st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
956 int preload2 = st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
957 if (preload != preload2) {
958 int64_t ts, ts2;
959 preload *= s->audio_preload;
960 preload2 *= s->audio_preload;
961 ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - preload;
962 ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - preload2;
963 if (ts == ts2) {
964 ts = ((uint64_t)pkt ->dts*st ->time_base.num*AV_TIME_BASE - (uint64_t)preload *st ->time_base.den)*st2->time_base.den
965 - ((uint64_t)next->dts*st2->time_base.num*AV_TIME_BASE - (uint64_t)preload2*st2->time_base.den)*st ->time_base.den;
966 ts2 = 0;
967 }
968 comp = (ts2 > ts) - (ts2 < ts);
969 }
970 }
971
972 if (comp == 0)
973 return pkt->stream_index < next->stream_index;
974 return comp > 0;
975}
976
978 int flush, int has_packet)
979{
981 FFFormatContext *const si = &fci->fc;
982 int stream_count = 0;
983 int noninterleaved_count = 0;
984 int ret;
985
986 if (has_packet) {
988 return ret;
989 }
990
991 for (unsigned i = 0; i < s->nb_streams; i++) {
992 const AVStream *const st = s->streams[i];
993 const FFStream *const sti = cffstream(st);
994 const AVCodecParameters *const par = st->codecpar;
995 if (sti->last_in_packet_buffer) {
996 ++stream_count;
997 } else if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT &&
998 par->codec_id != AV_CODEC_ID_VP8 &&
999 par->codec_id != AV_CODEC_ID_VP9 &&
1001 ++noninterleaved_count;
1002 }
1003 }
1004
1005 if (fci->nb_interleaved_streams == stream_count)
1006 flush = 1;
1007
1008 if (s->max_interleave_delta > 0 &&
1009 si->packet_buffer.head &&
1011 !flush &&
1012 fci->nb_interleaved_streams == stream_count+noninterleaved_count
1013 ) {
1014 AVPacket *const top_pkt = &si->packet_buffer.head->pkt;
1015 int64_t delta_dts = INT64_MIN;
1016 int64_t top_dts = av_rescale_q(top_pkt->dts,
1017 s->streams[top_pkt->stream_index]->time_base,
1019
1020 for (unsigned i = 0; i < s->nb_streams; i++) {
1021 const AVStream *const st = s->streams[i];
1022 const FFStream *const sti = cffstream(st);
1023 const PacketListEntry *const last = sti->last_in_packet_buffer;
1024 int64_t last_dts;
1025
1026 if (!last || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1027 continue;
1028
1029 last_dts = av_rescale_q(last->pkt.dts,
1030 st->time_base,
1032 delta_dts = FFMAX(delta_dts, last_dts - top_dts);
1033 }
1034
1035 if (delta_dts > s->max_interleave_delta) {
1037 "Delay between the first packet and last packet in the "
1038 "muxing queue is %"PRId64" > %"PRId64": forcing output\n",
1039 delta_dts, s->max_interleave_delta);
1040 flush = 1;
1041 }
1042 }
1043
1044 if (stream_count && flush) {
1046 AVStream *const st = s->streams[pktl->pkt.stream_index];
1047 FFStream *const sti = ffstream(st);
1048
1049 if (sti->last_in_packet_buffer == pktl)
1052
1053 return 1;
1054 } else {
1055 return 0;
1056 }
1057}
1058
1060 int flush, int has_packet)
1061{
1062 return has_packet;
1063}
1064
1066{
1067 AVStream *st;
1068
1069 if (stream_index < 0 || stream_index >= s->nb_streams)
1070 return AVERROR(EINVAL);
1071
1072 st = s->streams[stream_index];
1074
1075 if (s->output_ts_offset)
1076 *offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
1077
1078 return 0;
1079}
1080
1082{
1083 FFFormatContext *const si = ffformatcontext(s);
1085 while (pktl) {
1086 if (pktl->pkt.stream_index == stream) {
1087 return &pktl->pkt;
1088 }
1089 pktl = pktl->next;
1090 }
1091 return NULL;
1092}
1093
1095{
1096 int ret;
1097
1098 if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
1099 return 1;
1100
1101 if (ffofmt(s->oformat)->check_bitstream) {
1102 if (!sti->bitstream_checked) {
1103 if ((ret = ffofmt(s->oformat)->check_bitstream(s, &sti->pub, pkt)) < 0)
1104 return ret;
1105 else if (ret == 1)
1106 sti->bitstream_checked = 1;
1107 }
1108 }
1109
1110 return 1;
1111}
1112
1114 int flush, int has_packet)
1115{
1117
1118 for (;; ) {
1119 int ret = fci->interleave_packet(s, pkt, flush, has_packet);
1120 if (ret <= 0)
1121 return ret;
1122
1123 has_packet = 0;
1124
1125 ret = write_packet(s, pkt);
1127 if (ret < 0)
1128 return ret;
1129 }
1130}
1131
1132static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
1133{
1134 int ret;
1135
1136 if (s->debug & AV_FDEBUG_TS)
1137 av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __func__,
1138 pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
1139
1140 guess_pkt_duration(s, st, pkt);
1141
1142#if FF_API_COMPUTE_PKT_FIELDS2
1143 if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
1144 return ret;
1145#endif
1146
1147 if (interleaved) {
1148 if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
1149 return AVERROR(EINVAL);
1150 return interleaved_write_packet(s, pkt, 0, 1);
1151 } else {
1152 return write_packet(s, pkt);
1153 }
1154}
1155
1156static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
1157{
1158 FFStream *const sti = ffstream(st);
1159 AVBSFContext *const bsfc = sti->bsfc;
1160 int ret;
1161
1162 if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) {
1164 "Failed to send packet to filter %s for stream %d\n",
1165 bsfc->filter->name, st->index);
1166 return ret;
1167 }
1168
1169 do {
1170 ret = av_bsf_receive_packet(bsfc, pkt);
1171 if (ret < 0) {
1172 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
1173 return 0;
1174 av_log(s, AV_LOG_ERROR, "Error applying bitstream filters to an output "
1175 "packet for stream #%d: %s\n", st->index, av_err2str(ret));
1176 if (!(s->error_recognition & AV_EF_EXPLODE) && ret != AVERROR(ENOMEM))
1177 continue;
1178 return ret;
1179 }
1181 ret = write_packet_common(s, st, pkt, interleaved);
1182 if (ret >= 0 && !interleaved) // a successful write_packet_common already unrefed pkt for interleaved
1184 } while (ret >= 0);
1185
1186 return ret;
1187}
1188
1189static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved)
1190{
1191 AVStream *st;
1192 FFStream *sti;
1193 int ret = check_packet(s, pkt);
1194 if (ret < 0)
1195 return ret;
1196 st = s->streams[pkt->stream_index];
1197 sti = ffstream(st);
1198
1199 ret = prepare_input_packet(s, st, pkt);
1200 if (ret < 0)
1201 return ret;
1202
1203 ret = check_bitstream(s, sti, pkt);
1204 if (ret < 0)
1205 return ret;
1206
1207 if (sti->bsfc) {
1208 return write_packets_from_bsfs(s, st, pkt, interleaved);
1209 } else {
1210 return write_packet_common(s, st, pkt, interleaved);
1211 }
1212}
1213
1215{
1216 FFFormatContext *const si = ffformatcontext(s);
1217 AVPacket *pkt = si->parse_pkt;
1218 int ret;
1219
1220 if (!in) {
1222 ret = ffofmt(s->oformat)->write_packet(s, NULL);
1224 if (ret >= 0 && s->pb && s->pb->error < 0)
1225 ret = s->pb->error;
1226 return ret;
1227 }
1228 return 1;
1229 }
1230
1231 if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) {
1232 pkt = in;
1233 } else {
1234 /* We don't own in, so we have to make sure not to modify it.
1235 * (ff_write_chained() relies on this fact.)
1236 * The following avoids copying in's data unnecessarily.
1237 * Copying side data is unavoidable as a bitstream filter
1238 * may change it, e.g. free it on errors. */
1239 pkt->data = in->data;
1240 pkt->size = in->size;
1241 ret = av_packet_copy_props(pkt, in);
1242 if (ret < 0)
1243 return ret;
1244 if (in->buf) {
1245 pkt->buf = av_buffer_ref(in->buf);
1246 if (!pkt->buf) {
1247 ret = AVERROR(ENOMEM);
1248 goto fail;
1249 }
1250 }
1251 }
1252
1253 ret = write_packets_common(s, pkt, 0/*non-interleaved*/);
1254
1255fail:
1256 // Uncoded frames using the noninterleaved codepath are also freed here
1258 return ret;
1259}
1260
1262{
1263 int ret;
1264
1265 if (pkt) {
1266 ret = write_packets_common(s, pkt, 1/*interleaved*/);
1267 if (ret < 0)
1269 return ret;
1270 } else {
1271 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
1272 return interleaved_write_packet(s, ffformatcontext(s)->parse_pkt, 1/*flush*/, 0);
1273 }
1274}
1275
1277{
1278 FFFormatContext *const si = ffformatcontext(s);
1279 AVPacket *const pkt = si->parse_pkt;
1280 int ret1, ret = 0;
1281
1282 for (unsigned i = 0; i < s->nb_streams; i++) {
1283 AVStream *const st = s->streams[i];
1284 FFStream *const sti = ffstream(st);
1285 if (sti->bsfc) {
1286 ret1 = write_packets_from_bsfs(s, st, pkt, 1/*interleaved*/);
1287 if (ret1 < 0)
1289 if (ret >= 0)
1290 ret = ret1;
1291 }
1292 }
1293 ret1 = interleaved_write_packet(s, pkt, 1, 0);
1294 if (ret >= 0)
1295 ret = ret1;
1296
1297 if (ffofmt(s->oformat)->write_trailer) {
1298 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
1300 ret1 = ffofmt(s->oformat)->write_trailer(s);
1301 if (ret >= 0)
1302 ret = ret1;
1303 }
1304
1305 deinit_muxer(s);
1306
1307 if (s->pb)
1308 avio_flush(s->pb);
1309 if (ret >= 0 && s->pb && s->pb->error < 0)
1310 ret = s->pb->error;
1311 for (unsigned i = 0; i < s->nb_streams; i++) {
1312 av_freep(&s->streams[i]->priv_data);
1313 av_freep(&ffstream(s->streams[i])->index_entries);
1314 }
1315 if (s->oformat->priv_class)
1316 av_opt_free(s->priv_data);
1317 av_freep(&s->priv_data);
1318 av_packet_unref(si->pkt);
1319 return ret;
1320}
1321
1323 int64_t *dts, int64_t *wall)
1324{
1325 const FFOutputFormat *const of = ffofmt(s->oformat);
1326 if (!of || !of->get_output_timestamp)
1327 return AVERROR(ENOSYS);
1328 of->get_output_timestamp(s, stream, dts, wall);
1329 return 0;
1330}
1331
1332int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
1333{
1334 int ret;
1335 const AVBitStreamFilter *bsf;
1336 FFStream *const sti = ffstream(st);
1337 AVBSFContext *bsfc;
1338
1339 av_assert0(!sti->bsfc);
1340
1341 if (!(bsf = av_bsf_get_by_name(name))) {
1342 av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
1343 return AVERROR_BSF_NOT_FOUND;
1344 }
1345
1346 if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
1347 return ret;
1348
1349 bsfc->time_base_in = st->time_base;
1350 if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
1351 av_bsf_free(&bsfc);
1352 return ret;
1353 }
1354
1355 if (args && bsfc->filter->priv_class) {
1356 if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
1357 av_bsf_free(&bsfc);
1358 return ret;
1359 }
1360 }
1361
1362 if ((ret = av_bsf_init(bsfc)) < 0) {
1363 av_bsf_free(&bsfc);
1364 return ret;
1365 }
1366
1367 sti->bsfc = bsfc;
1368
1370 "Automatically inserted bitstream filter '%s'; args='%s'\n",
1371 name, args ? args : "");
1372 return 1;
1373}
1374
1377{
1378 int64_t pts = pkt->pts, dts = pkt->dts, duration = pkt->duration;
1379 int stream_index = pkt->stream_index;
1380 AVRational time_base = pkt->time_base;
1381 int ret;
1382
1383 pkt->stream_index = dst_stream;
1384
1386 src->streams[stream_index]->time_base,
1387 dst->streams[dst_stream]->time_base);
1388
1389 if (!interleave) {
1390 ret = av_write_frame(dst, pkt);
1391 /* We only have to backup and restore the fields that
1392 * we changed ourselves, because av_write_frame() does not
1393 * modify the packet given to it. */
1394 pkt->pts = pts;
1395 pkt->dts = dts;
1396 pkt->duration = duration;
1397 pkt->stream_index = stream_index;
1398 pkt->time_base = time_base;
1399 } else
1401
1402 return ret;
1403}
1404
1405static void uncoded_frame_free(void *unused, uint8_t *data)
1406{
1408 av_free(data);
1409}
1410
1411static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
1412 AVFrame *frame, int interleaved)
1413{
1414 FFFormatContext *const si = ffformatcontext(s);
1415 AVPacket *pkt = si->parse_pkt;
1416
1417 av_assert0(s->oformat);
1418 if (!ffofmt(s->oformat)->write_uncoded_frame) {
1420 return AVERROR(ENOSYS);
1421 }
1422
1423 if (!frame) {
1424 pkt = NULL;
1425 } else {
1426 size_t bufsize = sizeof(frame) + AV_INPUT_BUFFER_PADDING_SIZE;
1427 AVFrame **framep = av_mallocz(bufsize);
1428
1429 if (!framep)
1430 goto fail;
1431 pkt->buf = av_buffer_create((void *)framep, bufsize,
1433 if (!pkt->buf) {
1434 av_free(framep);
1435 fail:
1437 return AVERROR(ENOMEM);
1438 }
1439 *framep = frame;
1440
1441 pkt->data = (void *)framep;
1442 pkt->size = sizeof(frame);
1443 pkt->pts =
1444 pkt->dts = frame->pts;
1445 pkt->duration = frame->duration;
1446 pkt->stream_index = stream_index;
1448 }
1449
1450 return interleaved ? av_interleaved_write_frame(s, pkt) :
1452}
1453
1455 AVFrame *frame)
1456{
1457 return write_uncoded_frame_internal(s, stream_index, frame, 0);
1458}
1459
1461 AVFrame *frame)
1462{
1463 return write_uncoded_frame_internal(s, stream_index, frame, 1);
1464}
1465
1467{
1468 const FFOutputFormat *const of = ffofmt(s->oformat);
1469 av_assert0(of);
1470 if (!of->write_uncoded_frame)
1471 return AVERROR(ENOSYS);
1472 return of->write_uncoded_frame(s, stream_index, NULL,
1474}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static const char *const format[]
Definition af_aiir.c:445
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
int ff_is_intra_only(enum AVCodecID id)
Definition avformat.c:934
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:856
Main libavformat public API header.
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition avformat.h:505
#define AVFMT_FLAG_FLUSH_PACKETS
Flush the AVIOContext every packet.
Definition avformat.h:1562
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition avformat.h:504
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition avformat.h:1569
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition avformat.h:1161
#define AV_FDEBUG_TS
Definition avformat.h:1692
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:490
#define AVFMT_AVOID_NEG_TS_DISABLED
Do not shift timestamps even when they are negative.
Definition avformat.h:1807
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition avformat.h:512
#define AVFMT_AVOID_NEG_TS_AUTO
Enabled when required by target format.
Definition avformat.h:1806
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition avformat.h:509
#define AVFMT_FLAG_AUTO_BSF
Add bitstream filters as requested by the muxer.
Definition avformat.h:1572
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition avformat.h:694
#define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE
Shift timestamps so they are non negative.
Definition avformat.h:1808
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition avformat.h:500
#define AVFMT_AVOID_NEG_TS_MAKE_ZERO
Shift timestamps so that they start at 0.
Definition avformat.h:1809
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition mux.c:95
#define AV_DISPOSITION_TIMED_THUMBNAILS
The stream is sparse, and contains thumbnail images, often corresponding to chapter markers.
Definition avformat.h:699
static av_always_inline FormatContextInternal * ff_fc_internal(AVFormatContext *s)
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition aviobuf.c:464
@ AVIO_DATA_MARKER_TRAILER
Trailer data, which doesn't contain actual content, but only for finalizing the output file.
Definition avio.h:139
@ AVIO_DATA_MARKER_HEADER
Header data; this needs to be present for the stream to be decodeable.
Definition avio.h:114
@ AVIO_DATA_MARKER_UNKNOWN
This is any, unlabelled data.
Definition avio.h:134
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition avio.h:145
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition aviobuf.c:228
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Definition codec_par.c:107
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float fabs(float a)
#define max(a, b)
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
#define FF_COMPLIANCE_NORMAL
Definition defs.h:60
static AVPacket * pkt
static AVFrame * frame
Public dictionary API.
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:610
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition eamad.c:79
static int64_t duration
Definition ffplay.c:411
reference-counted frame API
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define fail
Definition test.h:479
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition bsf.c:47
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition bsf.c:147
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition bsf.c:99
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition bsf.c:228
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition bsf.c:200
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition utils.c:557
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
#define AV_CODEC_PROP_REORDER
Codec supports frame reordering.
Definition codec_desc.h:92
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
@ AV_CODEC_ID_SMPTE_2038
Definition codec_id.h:612
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
void av_packet_side_data_free(AVPacketSideData **psd, int *pnb_sd)
Convenience function to free all the side data stored in an array, and the array itself.
Definition packet.c:659
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition packet.c:621
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:435
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition packet.c:498
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition packet.c:492
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
Definition packet.c:398
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
Convert valid timing fields (timestamps / durations) in a packet from one timebase to another.
Definition packet.c:539
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:164
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and initialize the codec, but do not write the header.
Definition mux.c:484
av_warn_unused_result 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:505
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition mux.c:1261
int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write an uncoded frame to an output media file.
Definition mux.c:1460
#define AVSTREAM_INIT_IN_INIT_OUTPUT
stream parameters initialized in avformat_init_output
Definition avformat.h:2722
#define AVSTREAM_INIT_IN_WRITE_HEADER
stream parameters initialized in avformat_write_header
Definition avformat.h:2721
int av_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write an uncoded frame to an output media file.
Definition mux.c:1454
int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index)
Test whether a muxer supports uncoded frame.
Definition mux.c:1466
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:1322
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition mux.c:1276
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition format.c:79
int av_write_frame(AVFormatContext *s, AVPacket *in)
Write a packet to an output media file.
Definition mux.c:1214
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition buffer.c:56
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:61
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition dict.h:75
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
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:87
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
Definition error.h:51
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_UP
Round toward +infinity.
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition utils.c:28
#define av_fourcc2str(fourcc)
Definition avutil.h:323
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition avutil.h:204
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition avutil.h:202
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE
Internal time base represented as integer.
Definition avutil.h:253
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition opt.h:604
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition opt.c:2029
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1758
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition opt.c:2042
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition opt.c:1897
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition opt.c:2066
#define MAX_REORDER_DELAY
uint32_t type
Definition jpegmpfenc.c:80
unsigned offset
Definition libaomenc.c:763
common internal api header.
unsigned int ff_toupper4(unsigned int x)
Definition to_upper4.h:29
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
Definition utils.c:830
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
#define AVOID_NEGATIVE_TS_ENABLED(status)
Definition internal.h:79
static av_always_inline const FFStream * cffstream(const AVStream *st)
Definition internal.h:370
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition internal.h:130
#define AV_PKT_FLAG_UNCODED_FRAME
Definition mux.c:541
static void deinit_muxer(AVFormatContext *s)
Definition mux.c:474
const AVPacket * ff_interleaved_peek(AVFormatContext *s, int stream)
Find the next packet in the interleaving queue for the given stream.
Definition mux.c:1081
static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Definition mux.c:1113
static int init_pts(AVFormatContext *s)
Definition mux.c:421
static void uncoded_frame_free(void *unused, uint8_t *data)
Definition mux.c:1405
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Shift timestamps and call muxer; the original pts/dts are not kept.
Definition mux.c:760
int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Interleave packets directly in the order in which they arrive without any sort of buffering.
Definition mux.c:1059
static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved)
Definition mux.c:1189
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src, int interleave)
Write a packet to another muxer than the one the user originally intended.
Definition mux.c:1375
int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int(*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
Add packet to an AVFormatContext's packet_buffer list, determining its interleaved position using com...
Definition mux.c:873
static void frac_add(FFFrac *f, int64_t incr)
Fractional addition to f: f = f + (incr / f->den).
Definition mux.c:75
static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
Definition mux.c:1156
static void flush_if_needed(AVFormatContext *s)
Definition mux.c:464
static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
Definition mux.c:1132
static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
Definition mux.c:1094
#define CHUNK_START
Definition mux.c:871
static int check_packet(AVFormatContext *s, AVPacket *pkt)
Definition mux.c:799
static void handle_avoid_negative_ts(FFFormatContext *si, FFStream *sti, AVPacket *pkt)
Definition mux.c:674
static int validate_codec_tag(const AVFormatContext *s, const AVStream *st)
Definition mux.c:153
static int interleave_compare_dts(AVFormatContext *s, const AVPacket *next, const AVPacket *pkt)
Definition mux.c:947
static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mux.c:643
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition mux.c:1332
int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
Definition mux.c:1065
static int init_muxer(AVFormatContext *s, AVDictionary **options)
Definition mux.c:187
static int prepare_input_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mux.c:815
static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved)
Definition mux.c:1411
static void frac_init(FFFrac *f, int64_t val, int64_t num, int64_t den)
f = val + (num / den) + 0.5.
Definition mux.c:57
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Interleave an AVPacket per dts so it can be muxed.
Definition mux.c:977
int ff_packet_list_get(PacketList *list, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Definition packet_list.c:89
Libavformat version macros.
#define LIBAVFORMAT_IDENT
Definition version.h:45
common internal API header
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition internal.h:71
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition internal.h:72
const char * desc
Definition libsvtav1.c:83
#define FFSWAP(type, a, b)
Definition macros.h:52
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
uint32_t tag
Definition movenc.c:2128
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
Definition mux.h:38
#define FF_OFMT_FLAG_MAX_ONE_OF_EACH
If this flag is set, it indicates that for each codec type whose corresponding default codec (i....
Definition mux.h:50
@ AV_WRITE_UNCODED_FRAME_QUERY
Query whether the feature is possible on this stream.
Definition mux.h:239
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
Definition mux.h:59
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition mux.h:167
const char data[16]
Definition mxf.c:149
#define av_strdup(s)
Definition ops_static.c:55
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
Definition bsf.h:68
AVRational time_base_out
The timebase used for the timestamps of the output packets.
Definition bsf.h:108
void * priv_data
Opaque filter-specific private data.
Definition bsf.h:83
AVCodecParameters * par_in
Parameters of the input stream.
Definition bsf.h:90
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition bsf.h:102
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
Definition bsf.h:77
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions.
Definition bsf.h:130
const char * name
Definition bsf.h:112
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
This struct describes the properties of a single codec described by an AVCodecID.
Definition codec_desc.h:38
This struct describes the properties of an encoded stream.
Definition codec_par.h:49
int height
The height of the video frame in pixels.
Definition codec_par.h:150
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition codec_par.h:161
int video_delay
Number of delayed frames.
Definition codec_par.h:200
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
enum AVCodecID id
Definition internal.h:43
unsigned int tag
Definition internal.h:44
char * key
Definition dict.h:91
Format I/O context.
Definition avformat.h:1400
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_EXPERIMENTAL, AVFMT_GLOBALHEADER,...
Definition avformat.h:548
const char * name
Definition avformat.h:529
const struct AVCodecTag *const * codec_tag
List of supported codec_id-codec_tag pairs, ordered by "betterchoice first".
Definition avformat.h:554
const AVClass * priv_class
AVClass for the private context.
Definition avformat.h:557
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition packet.h:431
This structure stores compressed data.
Definition packet.h:587
int stream_index
Definition packet.h:612
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition packet.h:593
int flags
A combination of AV_PKT_FLAG values.
Definition packet.h:616
int size
Definition packet.h:611
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:609
uint8_t * data
Definition packet.h:610
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AVStreamGroupTileGrid holds information on how to combine several independent images on a single canv...
Definition avformat.h:975
enum AVStreamGroupParamsType type
Group type.
Definition avformat.h:1211
struct AVStreamGroupTileGrid * tile_grid
Definition avformat.h:1219
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition avformat.h:1311
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
AVPacketSideData * coded_side_data
Additional data associated with the group.
Definition avformat.h:1306
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition avformat.h:846
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:829
int index
stream index in AVFormatContext
Definition avformat.h:774
AVRational avg_frame_rate
Average framerate.
Definition avformat.h:857
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition avformat.h:837
enum FFFormatContext::@117142222231113272376067204111240071266247245201 avoid_negative_ts_status
Whether the timestamp shift offset has already been determined.
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition internal.h:86
AVFormatContext pub
The public context.
Definition internal.h:68
int avoid_negative_ts_use_pts
Definition internal.h:113
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
Definition internal.h:104
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition internal.h:111
The exact value of the fractional number is: 'val + num / den'.
Definition internal.h:59
int64_t num
Definition internal.h:60
int64_t val
Definition internal.h:60
int64_t den
Definition internal.h:60
int(* write_packet)(AVFormatContext *, AVPacket *pkt)
Write a packet.
Definition mux.h:84
AVOutputFormat p
The public AVOutputFormat.
Definition mux.h:65
int(* write_header)(AVFormatContext *)
Definition mux.h:76
int flags_internal
Internal flags.
Definition mux.h:74
int(* write_trailer)(AVFormatContext *)
Definition mux.h:85
int(* init)(AVFormatContext *)
Initialize format.
Definition mux.h:145
int(* write_uncoded_frame)(AVFormatContext *, int stream_index, struct AVFrame **frame, unsigned flags)
Write an uncoded AVFrame.
Definition mux.h:129
int(* check_bitstream)(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Set up any necessary bitstream filtering and extract any extra data needed for the global header.
Definition mux.h:163
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition mux.h:154
void(* get_output_timestamp)(AVFormatContext *s, int stream, int64_t *dts, int64_t *wall)
Definition mux.h:113
int priv_data_size
size of private data so that it can be allocated in the wrapper
Definition mux.h:69
int(* interleave_packet)(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
A format-specific function for interleavement.
Definition mux.h:102
int64_t lowest_ts_allowed
This is the lowest ts allowed in this track; it may be set by the muxer during init or write_header a...
Definition internal.h:257
int64_t mux_ts_offset
Timestamp offset added to timestamps before muxing.
Definition internal.h:250
int64_t cur_dts
Definition internal.h:360
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition internal.h:153
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition internal.h:289
PacketListEntry * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
Definition internal.h:310
AVStream pub
The public context.
Definition internal.h:139
int64_t interleaver_chunk_size
Definition internal.h:196
int64_t interleaver_chunk_duration
Definition internal.h:197
int bitstream_checked
Whether or not check_bitstream should still be run on each packet.
Definition internal.h:158
int reorder
Set to 1 if the codec allows reordering, so pts can be different from dts.
Definition internal.h:146
int is_intra_only
Definition internal.h:182
FFFrac priv_pts
Definition internal.h:184
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:191
int(* interleave_packet)(struct AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
The interleavement function in use.
int nb_interleaved_streams
Number of streams relevant for interleaving.
int initialized
Whether or not avformat_init_output has already been called.
int streams_initialized
Whether or not avformat_init_output fully initialized streams.
struct PacketListEntry * next
PacketListEntry * tail
PacketListEntry * head
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
int num
Definition error.c:23
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition timestamp.h:54
static int64_t pts
static float compare(const AVFrame *haystack, const AVFrame *obj, int offx, int offy)
static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dst_linesize, int src_linesize, enum FilterMode mode, int swap)
Definition vf_il.c:113