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 int64_t block_align = (int64_t)par->ch_layout.nb_channels *
247 if (block_align < 0 || block_align > INT_MAX) {
248 av_log(s, AV_LOG_ERROR, "invalid channel count\n");
249 ret = AVERROR(EINVAL);
250 goto fail;
251 }
252 par->block_align = block_align;
253 }
254 break;
256 if ((par->width <= 0 || par->height <= 0) &&
257 !(of->p.flags & AVFMT_NODIMENSIONS)) {
258 av_log(s, AV_LOG_ERROR, "dimensions not set\n");
259 ret = AVERROR(EINVAL);
260 goto fail;
261 }
264 ) {
265 if (st->sample_aspect_ratio.num != 0 &&
266 st->sample_aspect_ratio.den != 0 &&
267 par->sample_aspect_ratio.num != 0 &&
268 par->sample_aspect_ratio.den != 0) {
269 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
270 "(%d/%d) and encoder layer (%d/%d)\n",
274 ret = AVERROR(EINVAL);
275 goto fail;
276 }
277 }
278 break;
279 }
281 enum AVCodecID default_codec_id = AV_CODEC_ID_NONE;
282 unsigned nb;
283 if ((unsigned)par->codec_type < FF_ARRAY_ELEMS(default_codec_offsets)) {
284 nb = ++nb_type[par->codec_type];
285 if (default_codec_offsets[par->codec_type])
286 default_codec_id = *(const enum AVCodecID*)((const char*)of + default_codec_offsets[par->codec_type]);
287 }
289 default_codec_id != AV_CODEC_ID_NONE && par->codec_id != default_codec_id) {
290 av_log(s, AV_LOG_ERROR, "%s muxer supports only codec %s for type %s\n",
291 of->p.name, avcodec_get_name(default_codec_id), av_get_media_type_string(par->codec_type));
292 ret = AVERROR(EINVAL);
293 goto fail;
294 } else if (default_codec_id == AV_CODEC_ID_NONE ||
296 const char *type = av_get_media_type_string(par->codec_type);
297 av_log(s, AV_LOG_ERROR, "%s muxer does not support %s stream of type %s\n",
298 of->p.name, default_codec_id == AV_CODEC_ID_NONE ? "any" : "more than one",
299 type ? type : "unknown");
300 ret = AVERROR(EINVAL);
301 goto fail;
302 }
303 }
304
306 if (desc && desc->props & AV_CODEC_PROP_REORDER)
307 sti->reorder = 1;
308
310
311 if (of->p.codec_tag) {
312 if ( par->codec_tag
314 && ( av_codec_get_tag(of->p.codec_tag, par->codec_id) == 0
315 || av_codec_get_tag(of->p.codec_tag, par->codec_id) == MKTAG('r', 'a', 'w', ' '))
316 && !validate_codec_tag(s, st)) {
317 // the current rawvideo encoding system ends up setting
318 // the wrong codec_tag for avi/mov, we override it here
319 par->codec_tag = 0;
320 }
321 if (par->codec_tag) {
322 if (!validate_codec_tag(s, st)) {
323 const uint32_t otag = av_codec_get_tag(s->oformat->codec_tag, par->codec_id);
325 "Tag %s incompatible with output codec id '%d' (%s)\n",
326 av_fourcc2str(par->codec_tag), par->codec_id, av_fourcc2str(otag));
328 goto fail;
329 }
330 } else
332 }
333
337 }
338 for (unsigned i = 0; i < s->nb_stream_groups; i++) {
339 AVStreamGroup *const stg = s->stream_groups[i];
340
341 switch (stg->type) {
343#if FF_API_STREAM_GROUP_ENTRIES
345 AVStreamGroupTileGrid *tile_grid = stg->params.tile_grid;
346
347 // If both the global and the deprecated Tile Grid specific
348 // side data arrays are populated, prefer the latter.
349 if (tile_grid->nb_coded_side_data && stg->nb_coded_side_data)
351 &stg->nb_coded_side_data);
352 if (tile_grid->nb_coded_side_data) {
353 for (int j = 0; j < tile_grid->nb_coded_side_data; j++) {
354 const AVPacketSideData *src = &tile_grid->coded_side_data[j];
356
358 &stg->nb_coded_side_data,
359 src->type, src->size, 0);
360 if (!dst) {
361 ret = AVERROR(ENOMEM);
362 goto fail;
363 }
364
365 memcpy(dst->data, src->data, src->size);
366 }
367 }
368 break;
370#endif
371 }
372 default:
373 break;
374 }
375 }
377 if (!fci->interleave_packet)
381
382 if (!s->priv_data && of->priv_data_size > 0) {
383 s->priv_data = av_mallocz(of->priv_data_size);
384 if (!s->priv_data) {
385 ret = AVERROR(ENOMEM);
386 goto fail;
387 }
388 if (of->p.priv_class) {
389 *(const AVClass **)s->priv_data = of->p.priv_class;
390 av_opt_set_defaults(s->priv_data);
391 if ((ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
392 goto fail;
393 }
394 }
395
396 /* set muxer identification string */
397 if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
398 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
399 } else {
400 av_dict_set(&s->metadata, "encoder", NULL, 0);
401 }
402
403 for (e = NULL; e = av_dict_get(s->metadata, "encoder-", e, AV_DICT_IGNORE_SUFFIX); ) {
404 av_dict_set(&s->metadata, e->key, NULL, 0);
405 }
406
407 if (options) {
409 *options = tmp;
410 }
411
412 if (of->init) {
413 if ((ret = of->init(s)) < 0) {
414 if (of->deinit)
415 of->deinit(s);
416 return ret;
417 }
418 return ret == 0;
419 }
420
421 return 0;
422
423fail:
425 return ret;
426}
427
429{
430 FFFormatContext *const si = ffformatcontext(s);
431
432 /* init PTS generation */
433 for (unsigned i = 0; i < s->nb_streams; i++) {
434 AVStream *const st = s->streams[i];
435 FFStream *const sti = ffstream(st);
437
438 switch (st->codecpar->codec_type) {
440 den = (int64_t)st->time_base.num * st->codecpar->sample_rate;
441 break;
443 den = (int64_t)st->time_base.num * st->time_base.den;
444 break;
445 default:
446 break;
447 }
448
449 if (den != AV_NOPTS_VALUE) {
450 if (den <= 0)
451 return AVERROR_INVALIDDATA;
452
453 frac_init(&sti->priv_pts, 0, 0, den);
454 }
455 }
456
457 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_UNKNOWN;
458 if (s->avoid_negative_ts < 0) {
459 av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO);
460 if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
461 s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_DISABLED;
462 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
463 } else
464 s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
465 } else if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_DISABLED)
466 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
467
468 return 0;
469}
470
472{
473 if (s->pb && s->pb->error >= 0) {
474 if (s->flush_packets == 1 || s->flags & AVFMT_FLAG_FLUSH_PACKETS)
475 avio_flush(s->pb);
476 else if (s->flush_packets && !(s->oformat->flags & AVFMT_NOFILE))
478 }
479}
480
482{
484 const FFOutputFormat *const of = ffofmt(s->oformat);
485 if (of && of->deinit && fci->initialized)
486 of->deinit(s);
487 fci->initialized =
488 fci->streams_initialized = 0;
489}
490
492{
494 int ret = 0;
495
496 if ((ret = init_muxer(s, options)) < 0)
497 return ret;
498
499 fci->initialized = 1;
501
502 if (ffofmt(s->oformat)->init && ret) {
503 if ((ret = init_pts(s)) < 0)
504 return ret;
505
507 }
508
510}
511
513{
515 int already_initialized = fci->initialized;
516 int streams_already_initialized = fci->streams_initialized;
517 int ret = 0;
518
519 if (!already_initialized)
520 if ((ret = avformat_init_output(s, options)) < 0)
521 return ret;
522
523 if (ffofmt(s->oformat)->write_header) {
524 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
526 ret = ffofmt(s->oformat)->write_header(s);
527 if (ret >= 0 && s->pb && s->pb->error < 0)
528 ret = s->pb->error;
529 if (ret < 0)
530 goto fail;
532 }
533 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
535
536 if (!fci->streams_initialized) {
537 if ((ret = init_pts(s)) < 0)
538 goto fail;
539 }
540
541 return streams_already_initialized;
542
543fail:
545 return ret;
546}
547
548#define AV_PKT_FLAG_UNCODED_FRAME 0x2000
549
550
551#if FF_API_COMPUTE_PKT_FIELDS2
553//FIXME merge with compute_pkt_fields
554static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt)
555{
557 FFStream *const sti = ffstream(st);
558 int delay = st->codecpar->video_delay;
559 int frame_size;
560
561 if (!fci->missing_ts_warning &&
562 !(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
564 (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
566 "Timestamps are unset in a packet for stream %d. "
567 "This is deprecated and will stop working in the future. "
568 "Fix your code to set the timestamps properly\n", st->index);
569 fci->missing_ts_warning = 1;
570 }
571
572 if (s->debug & AV_FDEBUG_TS)
573 av_log(s, AV_LOG_DEBUG, "compute_muxer_pkt_fields: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
574 av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), delay, pkt->size, pkt->stream_index);
575
576 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
577 pkt->pts = pkt->dts;
578
579 //XXX/FIXME this is a temporary hack until all encoders output pts
580 if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
581 static int warned;
582 if (!warned) {
583 av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
584 warned = 1;
585 }
586 pkt->dts =
587// pkt->pts= st->cur_dts;
588 pkt->pts = sti->priv_pts.val;
589 }
590
591 //calculate dts from pts
592 if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
593 sti->pts_buffer[0] = pkt->pts;
594 for (int i = 1; i < delay + 1 && sti->pts_buffer[i] == AV_NOPTS_VALUE; i++)
595 sti->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
596 for (int i = 0; i<delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++)
597 FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]);
598
599 pkt->dts = sti->pts_buffer[0];
600 }
601
602 if (sti->cur_dts && sti->cur_dts != AV_NOPTS_VALUE &&
603 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
606 sti->cur_dts >= pkt->dts) || sti->cur_dts > pkt->dts)) {
608 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
609 st->index, av_ts2str(sti->cur_dts), av_ts2str(pkt->dts));
610 return AVERROR(EINVAL);
611 }
612 if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
614 "pts (%s) < dts (%s) in stream %d\n",
615 av_ts2str(pkt->pts), av_ts2str(pkt->dts),
616 st->index);
617 return AVERROR(EINVAL);
618 }
619
620 if (s->debug & AV_FDEBUG_TS)
621 av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%s dts2:%s\n",
622 av_ts2str(pkt->pts), av_ts2str(pkt->dts));
623
624 sti->cur_dts = pkt->dts;
625 sti->priv_pts.val = pkt->dts;
626
627 /* update pts */
628 switch (st->codecpar->codec_type) {
631 (*(AVFrame **)pkt->data)->nb_samples :
633
634 /* HACK/FIXME, we skip the initial 0 size packets as they are most
635 * likely equal to the encoder delay, but it would be better if we
636 * had the real timestamps from the encoder */
637 if (frame_size >= 0 && (pkt->size || sti->priv_pts.num != sti->priv_pts.den >> 1 || sti->priv_pts.val)) {
639 }
640 break;
643 break;
644 }
645 return 0;
646}
648#endif
649
651{
652 if (pkt->duration < 0 && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
653 av_log(s, AV_LOG_WARNING, "Packet with invalid duration %"PRId64" in stream %d\n",
654 pkt->duration, pkt->stream_index);
655 pkt->duration = 0;
656 }
657
658 if (pkt->duration)
659 return;
660
661 switch (st->codecpar->codec_type) {
663 if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0) {
664 pkt->duration = av_rescale_q(1, av_inv_q(st->avg_frame_rate),
665 st->time_base);
666 } else if (st->time_base.num * 1000LL > st->time_base.den)
667 pkt->duration = 1;
668 break;
669 case AVMEDIA_TYPE_AUDIO: {
671 if (frame_size && st->codecpar->sample_rate) {
672 pkt->duration = av_rescale_q(frame_size,
674 st->time_base);
675 }
676 break;
677 }
678 }
679}
680
682 AVPacket *pkt)
683{
684 AVFormatContext *const s = &si->pub;
686
688 return;
689
690 if (si->avoid_negative_ts_status == AVOID_NEGATIVE_TS_UNKNOWN) {
691 int use_pts = si->avoid_negative_ts_use_pts;
692 int64_t ts = use_pts ? pkt->pts : pkt->dts;
693 AVRational tb = sti->pub.time_base;
694
695 if (ts == AV_NOPTS_VALUE)
696 return;
697
698 ts -= sti->lowest_ts_allowed;
699
700 /* Peek into the muxing queue to improve our estimate
701 * of the lowest timestamp if av_interleaved_write_frame() is used. */
702 for (const PacketListEntry *pktl = si->packet_buffer.head;
703 pktl; pktl = pktl->next) {
704 AVRational cmp_tb = s->streams[pktl->pkt.stream_index]->time_base;
705 int64_t cmp_ts = use_pts ? pktl->pkt.pts : pktl->pkt.dts;
706 if (cmp_ts == AV_NOPTS_VALUE)
707 continue;
708 cmp_ts -= ffstream(s->streams[pktl->pkt.stream_index])->lowest_ts_allowed;
709 if (s->output_ts_offset)
710 cmp_ts += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, cmp_tb);
711 if (av_compare_ts(cmp_ts, cmp_tb, ts, tb) < 0) {
712 ts = cmp_ts;
713 tb = cmp_tb;
714 }
715 }
716
717 if (ts < 0 ||
718 ts > 0 && s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO) {
719 for (unsigned i = 0; i < s->nb_streams; i++) {
720 AVStream *const st2 = s->streams[i];
721 FFStream *const sti2 = ffstream(st2);
722 sti2->mux_ts_offset = av_rescale_q_rnd(-ts, tb,
723 st2->time_base,
725 }
726 }
727 si->avoid_negative_ts_status = AVOID_NEGATIVE_TS_KNOWN;
728 }
729
730 offset = sti->mux_ts_offset;
731
732 if (pkt->dts != AV_NOPTS_VALUE)
733 pkt->dts += offset;
734 if (pkt->pts != AV_NOPTS_VALUE)
735 pkt->pts += offset;
736
738 if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < sti->lowest_ts_allowed) {
739 av_log(s, AV_LOG_WARNING, "failed to avoid negative "
740 "pts %s in stream %d.\n"
741 "Try -avoid_negative_ts 1 as a possible workaround.\n",
742 av_ts2str(pkt->pts),
743 pkt->stream_index
744 );
745 }
746 } else {
747 if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < sti->lowest_ts_allowed) {
749 "Packets poorly interleaved, failed to avoid negative "
750 "timestamp %s in stream %d.\n"
751 "Try -max_interleave_delta 0 as a possible workaround.\n",
752 av_ts2str(pkt->dts),
753 pkt->stream_index
754 );
755 }
756 }
757}
758
759/**
760 * Shift timestamps and call muxer; the original pts/dts are not kept.
761 *
762 * FIXME: this function should NEVER get undefined pts/dts beside when the
763 * AVFMT_NOTIMESTAMPS is set.
764 * Those additional safety checks should be dropped once the correct checks
765 * are set in the callers.
766 */
768{
769 FFFormatContext *const si = ffformatcontext(s);
770 AVStream *const st = s->streams[pkt->stream_index];
771 FFStream *const sti = ffstream(st);
772 int ret;
773
774 // If the timestamp offsetting below is adjusted, adjust
775 // ff_interleaved_peek similarly.
776 if (s->output_ts_offset) {
777 int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
778
779 if (pkt->dts != AV_NOPTS_VALUE)
780 pkt->dts += offset;
781 if (pkt->pts != AV_NOPTS_VALUE)
782 pkt->pts += offset;
783 }
785
786 if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
787 AVFrame **frame = (AVFrame **)pkt->data;
788 av_assert0(pkt->size == sizeof(*frame));
789 ret = ffofmt(s->oformat)->write_uncoded_frame(s, pkt->stream_index, frame, 0);
790 } else {
791 ret = ffofmt(s->oformat)->write_packet(s, pkt);
792 }
793
794 if (s->pb && ret >= 0) {
796 if (s->pb->error < 0)
797 ret = s->pb->error;
798 }
799
800 if (ret >= 0)
801 st->nb_frames++;
802
803 return ret;
804}
805
807{
808 if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
809 av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
810 pkt->stream_index);
811 return AVERROR(EINVAL);
812 }
813
814 if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
815 av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n");
816 return AVERROR(EINVAL);
817 }
818
819 return 0;
820}
821
823{
824 FFStream *const sti = ffstream(st);
825#if !FF_API_COMPUTE_PKT_FIELDS2
826 /* sanitize the timestamps */
827 if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
828
829 /* when there is no reordering (so dts is equal to pts), but
830 * only one of them is set, set the other as well */
831 if (!sti->reorder) {
832 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE)
833 pkt->pts = pkt->dts;
834 if (pkt->dts == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE)
835 pkt->dts = pkt->pts;
836 }
837
838 /* check that the timestamps are set */
839 if (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE) {
841 "Timestamps are unset in a packet for stream %d\n", st->index);
842 return AVERROR(EINVAL);
843 }
844
845 /* check that the dts are increasing (or at least non-decreasing,
846 * if the format allows it */
847 if (sti->cur_dts != AV_NOPTS_VALUE &&
848 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && sti->cur_dts >= pkt->dts) ||
849 sti->cur_dts > pkt->dts)) {
851 "Application provided invalid, non monotonically increasing "
852 "dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
853 st->index, sti->cur_dts, pkt->dts);
854 return AVERROR(EINVAL);
855 }
856
857 if (pkt->pts < pkt->dts) {
858 av_log(s, AV_LOG_ERROR, "pts %" PRId64 " < dts %" PRId64 " in stream %d\n",
859 pkt->pts, pkt->dts, st->index);
860 return AVERROR(EINVAL);
861 }
862 }
863#endif
864 /* update flags */
865 if (sti->is_intra_only)
866 pkt->flags |= AV_PKT_FLAG_KEY;
867
868 if (!pkt->data && !pkt->side_data_elems) {
869 /* Such empty packets signal EOS for the BSF API; so sanitize
870 * the packet by allocating data of size 0 (+ padding). */
871 av_buffer_unref(&pkt->buf);
873 }
874
875 return 0;
876}
877
878#define CHUNK_START 0x1000
879
881 int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *))
882{
883 int ret;
884 FFFormatContext *const si = ffformatcontext(s);
885 PacketListEntry **next_point, *this_pktl;
886 AVStream *st = s->streams[pkt->stream_index];
887 FFStream *const sti = ffstream(st);
888 int chunked = s->max_chunk_size || s->max_chunk_duration;
889
890 this_pktl = av_malloc(sizeof(*this_pktl));
891 if (!this_pktl) {
893 return AVERROR(ENOMEM);
894 }
895 if ((ret = av_packet_make_refcounted(pkt)) < 0) {
896 av_free(this_pktl);
898 return ret;
899 }
900
901 av_packet_move_ref(&this_pktl->pkt, pkt);
902 pkt = &this_pktl->pkt;
903
904 if (sti->last_in_packet_buffer) {
905 next_point = &(sti->last_in_packet_buffer->next);
906 } else {
907 next_point = &si->packet_buffer.head;
908 }
909
910 if (chunked) {
911 uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);
912 sti->interleaver_chunk_size += pkt->size;
913 sti->interleaver_chunk_duration += pkt->duration;
914 if ( (s->max_chunk_size && sti->interleaver_chunk_size > s->max_chunk_size)
915 || (max && sti->interleaver_chunk_duration > max)) {
916 sti->interleaver_chunk_size = 0;
917 pkt->flags |= CHUNK_START;
918 if (max && sti->interleaver_chunk_duration > max) {
919 int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
920 int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
921
922 sti->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
923 } else
925 }
926 }
927 if (*next_point) {
928 if (chunked && !(pkt->flags & CHUNK_START))
929 goto next_non_null;
930
931 if (compare(s, &si->packet_buffer.tail->pkt, pkt)) {
932 while ( *next_point
933 && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
934 || !compare(s, &(*next_point)->pkt, pkt)))
935 next_point = &(*next_point)->next;
936 if (*next_point)
937 goto next_non_null;
938 } else {
939 next_point = &(si->packet_buffer.tail->next);
940 }
941 }
942 av_assert1(!*next_point);
943
944 si->packet_buffer.tail = this_pktl;
945next_non_null:
946
947 this_pktl->next = *next_point;
948
949 sti->last_in_packet_buffer = *next_point = this_pktl;
950
951 return 0;
952}
953
955 const AVPacket *pkt)
956{
957 AVStream *st = s->streams[pkt->stream_index];
958 AVStream *st2 = s->streams[next->stream_index];
959 int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
960 st->time_base);
961 if (s->audio_preload) {
962 int preload = st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
963 int preload2 = st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
964 if (preload != preload2) {
965 int64_t ts, ts2;
966 preload *= s->audio_preload;
967 preload2 *= s->audio_preload;
968 ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - preload;
969 ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - preload2;
970 if (ts == ts2) {
971 ts = ((uint64_t)pkt ->dts*st ->time_base.num*AV_TIME_BASE - (uint64_t)preload *st ->time_base.den)*st2->time_base.den
972 - ((uint64_t)next->dts*st2->time_base.num*AV_TIME_BASE - (uint64_t)preload2*st2->time_base.den)*st ->time_base.den;
973 ts2 = 0;
974 }
975 comp = (ts2 > ts) - (ts2 < ts);
976 }
977 }
978
979 if (comp == 0)
980 return pkt->stream_index < next->stream_index;
981 return comp > 0;
982}
983
985 int flush, int has_packet)
986{
988 FFFormatContext *const si = &fci->fc;
989 int stream_count = 0;
990 int noninterleaved_count = 0;
991 int ret;
992
993 if (has_packet) {
995 return ret;
996 }
997
998 for (unsigned i = 0; i < s->nb_streams; i++) {
999 const AVStream *const st = s->streams[i];
1000 const FFStream *const sti = cffstream(st);
1001 const AVCodecParameters *const par = st->codecpar;
1002 if (sti->last_in_packet_buffer) {
1003 ++stream_count;
1004 } else if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT &&
1005 par->codec_id != AV_CODEC_ID_VP8 &&
1006 par->codec_id != AV_CODEC_ID_VP9 &&
1008 ++noninterleaved_count;
1009 }
1010 }
1011
1012 if (fci->nb_interleaved_streams == stream_count)
1013 flush = 1;
1014
1015 if (s->max_interleave_delta > 0 &&
1016 si->packet_buffer.head &&
1018 !flush &&
1019 fci->nb_interleaved_streams == stream_count+noninterleaved_count
1020 ) {
1021 AVPacket *const top_pkt = &si->packet_buffer.head->pkt;
1022 int64_t delta_dts = INT64_MIN;
1023 int64_t top_dts = av_rescale_q(top_pkt->dts,
1024 s->streams[top_pkt->stream_index]->time_base,
1026
1027 for (unsigned i = 0; i < s->nb_streams; i++) {
1028 const AVStream *const st = s->streams[i];
1029 const FFStream *const sti = cffstream(st);
1030 const PacketListEntry *const last = sti->last_in_packet_buffer;
1031 int64_t last_dts;
1032
1033 if (!last || st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1034 continue;
1035
1036 last_dts = av_rescale_q(last->pkt.dts,
1037 st->time_base,
1039 delta_dts = FFMAX(delta_dts, last_dts - top_dts);
1040 }
1041
1042 if (delta_dts > s->max_interleave_delta) {
1044 "Delay between the first packet and last packet in the "
1045 "muxing queue is %"PRId64" > %"PRId64": forcing output\n",
1046 delta_dts, s->max_interleave_delta);
1047 flush = 1;
1048 }
1049 }
1050
1051 if (stream_count && flush) {
1053 AVStream *const st = s->streams[pktl->pkt.stream_index];
1054 FFStream *const sti = ffstream(st);
1055
1056 if (sti->last_in_packet_buffer == pktl)
1059
1060 return 1;
1061 } else {
1062 return 0;
1063 }
1064}
1065
1067 int flush, int has_packet)
1068{
1069 return has_packet;
1070}
1071
1073{
1074 AVStream *st;
1075
1076 if (stream_index < 0 || stream_index >= s->nb_streams)
1077 return AVERROR(EINVAL);
1078
1079 st = s->streams[stream_index];
1081
1082 if (s->output_ts_offset)
1083 *offset += av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
1084
1085 return 0;
1086}
1087
1089{
1090 FFFormatContext *const si = ffformatcontext(s);
1092 while (pktl) {
1093 if (pktl->pkt.stream_index == stream) {
1094 return &pktl->pkt;
1095 }
1096 pktl = pktl->next;
1097 }
1098 return NULL;
1099}
1100
1102{
1103 int ret;
1104
1105 if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
1106 return 1;
1107
1108 if (ffofmt(s->oformat)->check_bitstream) {
1109 if (!sti->bitstream_checked) {
1110 if ((ret = ffofmt(s->oformat)->check_bitstream(s, &sti->pub, pkt)) < 0)
1111 return ret;
1112 else if (ret == 1)
1113 sti->bitstream_checked = 1;
1114 }
1115 }
1116
1117 return 1;
1118}
1119
1121 int flush, int has_packet)
1122{
1124
1125 for (;; ) {
1126 int ret = fci->interleave_packet(s, pkt, flush, has_packet);
1127 if (ret <= 0)
1128 return ret;
1129
1130 has_packet = 0;
1131
1132 ret = write_packet(s, pkt);
1134 if (ret < 0)
1135 return ret;
1136 }
1137}
1138
1139static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
1140{
1141 int ret;
1142
1143 if (s->debug & AV_FDEBUG_TS)
1144 av_log(s, AV_LOG_DEBUG, "%s size:%d dts:%s pts:%s\n", __func__,
1145 pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
1146
1147 guess_pkt_duration(s, st, pkt);
1148
1149#if FF_API_COMPUTE_PKT_FIELDS2
1150 if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
1151 return ret;
1152#endif
1153
1154 if (interleaved) {
1155 if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
1156 return AVERROR(EINVAL);
1157 return interleaved_write_packet(s, pkt, 0, 1);
1158 } else {
1159 return write_packet(s, pkt);
1160 }
1161}
1162
1163static int write_packets_from_bsfs(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
1164{
1165 FFStream *const sti = ffstream(st);
1166 AVBSFContext *const bsfc = sti->bsfc;
1167 int ret;
1168
1169 if ((ret = av_bsf_send_packet(bsfc, pkt)) < 0) {
1171 "Failed to send packet to filter %s for stream %d\n",
1172 bsfc->filter->name, st->index);
1173 return ret;
1174 }
1175
1176 do {
1177 ret = av_bsf_receive_packet(bsfc, pkt);
1178 if (ret < 0) {
1179 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
1180 return 0;
1181 av_log(s, AV_LOG_ERROR, "Error applying bitstream filters to an output "
1182 "packet for stream #%d: %s\n", st->index, av_err2str(ret));
1183 if (!(s->error_recognition & AV_EF_EXPLODE) && ret != AVERROR(ENOMEM))
1184 continue;
1185 return ret;
1186 }
1188 ret = write_packet_common(s, st, pkt, interleaved);
1189 if (ret >= 0 && !interleaved) // a successful write_packet_common already unrefed pkt for interleaved
1191 } while (ret >= 0);
1192
1193 return ret;
1194}
1195
1196static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved)
1197{
1198 AVStream *st;
1199 FFStream *sti;
1200 int ret = check_packet(s, pkt);
1201 if (ret < 0)
1202 return ret;
1203 st = s->streams[pkt->stream_index];
1204 sti = ffstream(st);
1205
1206 ret = prepare_input_packet(s, st, pkt);
1207 if (ret < 0)
1208 return ret;
1209
1210 ret = check_bitstream(s, sti, pkt);
1211 if (ret < 0)
1212 return ret;
1213
1214 if (sti->bsfc) {
1215 return write_packets_from_bsfs(s, st, pkt, interleaved);
1216 } else {
1217 return write_packet_common(s, st, pkt, interleaved);
1218 }
1219}
1220
1222{
1223 FFFormatContext *const si = ffformatcontext(s);
1224 AVPacket *pkt = si->parse_pkt;
1225 int ret;
1226
1227 if (!in) {
1229 ret = ffofmt(s->oformat)->write_packet(s, NULL);
1231 if (ret >= 0 && s->pb && s->pb->error < 0)
1232 ret = s->pb->error;
1233 return ret;
1234 }
1235 return 1;
1236 }
1237
1238 if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) {
1239 pkt = in;
1240 } else {
1241 /* We don't own in, so we have to make sure not to modify it.
1242 * (ff_write_chained() relies on this fact.)
1243 * The following avoids copying in's data unnecessarily.
1244 * Copying side data is unavoidable as a bitstream filter
1245 * may change it, e.g. free it on errors. */
1246 pkt->data = in->data;
1247 pkt->size = in->size;
1249 if (ret < 0)
1250 return ret;
1251 if (in->buf) {
1252 pkt->buf = av_buffer_ref(in->buf);
1253 if (!pkt->buf) {
1254 ret = AVERROR(ENOMEM);
1255 goto fail;
1256 }
1257 }
1258 }
1259
1260 ret = write_packets_common(s, pkt, 0/*non-interleaved*/);
1261
1262fail:
1263 // Uncoded frames using the noninterleaved codepath are also freed here
1265 return ret;
1266}
1267
1269{
1270 int ret;
1271
1272 if (pkt) {
1273 ret = write_packets_common(s, pkt, 1/*interleaved*/);
1274 if (ret < 0)
1276 return ret;
1277 } else {
1278 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
1279 return interleaved_write_packet(s, ffformatcontext(s)->parse_pkt, 1/*flush*/, 0);
1280 }
1281}
1282
1284{
1285 FFFormatContext *const si = ffformatcontext(s);
1286 AVPacket *const pkt = si->parse_pkt;
1287 int ret1, ret = 0;
1288
1289 for (unsigned i = 0; i < s->nb_streams; i++) {
1290 AVStream *const st = s->streams[i];
1291 FFStream *const sti = ffstream(st);
1292 if (sti->bsfc) {
1293 ret1 = write_packets_from_bsfs(s, st, pkt, 1/*interleaved*/);
1294 if (ret1 < 0)
1296 if (ret >= 0)
1297 ret = ret1;
1298 }
1299 }
1300 ret1 = interleaved_write_packet(s, pkt, 1, 0);
1301 if (ret >= 0)
1302 ret = ret1;
1303
1304 if (ffofmt(s->oformat)->write_trailer) {
1305 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
1307 ret1 = ffofmt(s->oformat)->write_trailer(s);
1308 if (ret >= 0)
1309 ret = ret1;
1310 }
1311
1312 deinit_muxer(s);
1313
1314 if (s->pb)
1315 avio_flush(s->pb);
1316 if (ret >= 0 && s->pb && s->pb->error < 0)
1317 ret = s->pb->error;
1318 for (unsigned i = 0; i < s->nb_streams; i++) {
1319 av_freep(&s->streams[i]->priv_data);
1320 av_freep(&ffstream(s->streams[i])->index_entries);
1321 }
1322 if (s->oformat->priv_class)
1323 av_opt_free(s->priv_data);
1324 av_freep(&s->priv_data);
1325 av_packet_unref(si->pkt);
1326 return ret;
1327}
1328
1330 int64_t *dts, int64_t *wall)
1331{
1332 const FFOutputFormat *const of = ffofmt(s->oformat);
1333 if (!of || !of->get_output_timestamp)
1334 return AVERROR(ENOSYS);
1335 of->get_output_timestamp(s, stream, dts, wall);
1336 return 0;
1337}
1338
1339int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
1340{
1341 int ret;
1342 const AVBitStreamFilter *bsf;
1343 FFStream *const sti = ffstream(st);
1344 AVBSFContext *bsfc;
1345
1346 av_assert0(!sti->bsfc);
1347
1348 if (!(bsf = av_bsf_get_by_name(name))) {
1349 av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
1350 return AVERROR_BSF_NOT_FOUND;
1351 }
1352
1353 if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
1354 return ret;
1355
1356 bsfc->time_base_in = st->time_base;
1357 if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
1358 av_bsf_free(&bsfc);
1359 return ret;
1360 }
1361
1362 if (args && bsfc->filter->priv_class) {
1363 if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
1364 av_bsf_free(&bsfc);
1365 return ret;
1366 }
1367 }
1368
1369 if ((ret = av_bsf_init(bsfc)) < 0) {
1370 av_bsf_free(&bsfc);
1371 return ret;
1372 }
1373
1374 sti->bsfc = bsfc;
1375
1377 "Automatically inserted bitstream filter '%s'; args='%s'\n",
1378 name, args ? args : "");
1379 return 1;
1380}
1381
1384{
1385 int64_t pts = pkt->pts, dts = pkt->dts, duration = pkt->duration;
1386 int stream_index = pkt->stream_index;
1387 AVRational time_base = pkt->time_base;
1388 int ret;
1389
1390 pkt->stream_index = dst_stream;
1391
1393 src->streams[stream_index]->time_base,
1394 dst->streams[dst_stream]->time_base);
1395
1396 if (!interleave) {
1398 /* We only have to backup and restore the fields that
1399 * we changed ourselves, because av_write_frame() does not
1400 * modify the packet given to it. */
1401 pkt->pts = pts;
1402 pkt->dts = dts;
1403 pkt->duration = duration;
1404 pkt->stream_index = stream_index;
1405 pkt->time_base = time_base;
1406 } else
1408
1409 return ret;
1410}
1411
1412static void uncoded_frame_free(void *unused, uint8_t *data)
1413{
1415 av_free(data);
1416}
1417
1418static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
1419 AVFrame *frame, int interleaved)
1420{
1421 FFFormatContext *const si = ffformatcontext(s);
1422 AVPacket *pkt = si->parse_pkt;
1423
1424 av_assert0(s->oformat);
1425 if (!ffofmt(s->oformat)->write_uncoded_frame) {
1427 return AVERROR(ENOSYS);
1428 }
1429
1430 if (!frame) {
1431 pkt = NULL;
1432 } else {
1433 size_t bufsize = sizeof(frame) + AV_INPUT_BUFFER_PADDING_SIZE;
1434 AVFrame **framep = av_mallocz(bufsize);
1435
1436 if (!framep)
1437 goto fail;
1438 pkt->buf = av_buffer_create((void *)framep, bufsize,
1440 if (!pkt->buf) {
1441 av_free(framep);
1442 fail:
1444 return AVERROR(ENOMEM);
1445 }
1446 *framep = frame;
1447
1448 pkt->data = (void *)framep;
1449 pkt->size = sizeof(frame);
1450 pkt->pts =
1451 pkt->dts = frame->pts;
1452 pkt->duration = frame->duration;
1453 pkt->stream_index = stream_index;
1455 }
1456
1457 return interleaved ? av_interleaved_write_frame(s, pkt) :
1459}
1460
1462 AVFrame *frame)
1463{
1464 return write_uncoded_frame_internal(s, stream_index, frame, 0);
1465}
1466
1468 AVFrame *frame)
1469{
1470 return write_uncoded_frame_internal(s, stream_index, frame, 1);
1471}
1472
1474{
1475 const FFOutputFormat *const of = ffofmt(s->oformat);
1476 av_assert0(of);
1477 if (!of->write_uncoded_frame)
1478 return AVERROR(ENOSYS);
1479 return of->write_uncoded_frame(s, stream_index, NULL,
1481}
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:943
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:865
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:1563
#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:1570
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition avformat.h:1161
#define AV_FDEBUG_TS
Definition avformat.h:1693
#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:1808
#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:1807
#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:1573
#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:1809
#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:1810
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:615
static int64_t duration
Definition ffplay.c:359
int ret
Definition ffplay.c:391
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:614
@ 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:165
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:491
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:512
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file ensuring correct interleaving.
Definition mux.c:1268
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:1467
#define AVSTREAM_INIT_IN_INIT_OUTPUT
stream parameters initialized in avformat_init_output
Definition avformat.h:2759
#define AVSTREAM_INIT_IN_WRITE_HEADER
stream parameters initialized in avformat_write_header
Definition avformat.h:2758
int av_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame)
Write an uncoded frame to an output media file.
Definition mux.c:1461
int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index)
Test whether a muxer supports uncoded frame.
Definition mux.c:1473
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:1329
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition mux.c:1283
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:1221
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:65
#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:2042
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1771
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:2055
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:1910
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition opt.c:2079
#define MAX_REORDER_DELAY
enum MPFType type
Definition jpegmpfenc.c:55
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:834
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:390
#define AVOID_NEGATIVE_TS_ENABLED(status)
Definition internal.h:79
static av_always_inline const FFStream * cffstream(const AVStream *st)
Definition internal.h:395
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition internal.h:135
#define AV_PKT_FLAG_UNCODED_FRAME
Definition mux.c:548
static void deinit_muxer(AVFormatContext *s)
Definition mux.c:481
const AVPacket * ff_interleaved_peek(AVFormatContext *s, int stream)
Find the next packet in the interleaving queue for the given stream.
Definition mux.c:1088
static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
Definition mux.c:1120
static int init_pts(AVFormatContext *s)
Definition mux.c:428
static void uncoded_frame_free(void *unused, uint8_t *data)
Definition mux.c:1412
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Shift timestamps and call muxer; the original pts/dts are not kept.
Definition mux.c:767
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:1066
static int write_packets_common(AVFormatContext *s, AVPacket *pkt, int interleaved)
Definition mux.c:1196
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:1382
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:880
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:1163
static void flush_if_needed(AVFormatContext *s)
Definition mux.c:471
static int write_packet_common(AVFormatContext *s, AVStream *st, AVPacket *pkt, int interleaved)
Definition mux.c:1139
static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
Definition mux.c:1101
#define CHUNK_START
Definition mux.c:878
static int check_packet(AVFormatContext *s, AVPacket *pkt)
Definition mux.c:806
static void handle_avoid_negative_ts(FFFormatContext *si, FFStream *sti, AVPacket *pkt)
Definition mux.c:681
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:954
static void guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition mux.c:650
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition mux.c:1339
int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
Definition mux.c:1072
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:822
static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved)
Definition mux.c:1418
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:984
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:2144
#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:1401
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:1212
struct AVStreamGroupTileGrid * tile_grid
Definition avformat.h:1220
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition avformat.h:1312
union AVStreamGroup::@313244315204024013007202273061153315146016101155 params
Group type-specific parameters.
AVPacketSideData * coded_side_data
Additional data associated with the group.
Definition avformat.h:1307
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:282
int64_t mux_ts_offset
Timestamp offset added to timestamps before muxing.
Definition internal.h:275
int64_t cur_dts
Definition internal.h:385
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition internal.h:158
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition internal.h:314
PacketListEntry * last_in_packet_buffer
last packet in packet_buffer for this stream when muxing.
Definition internal.h:335
AVStream pub
The public context.
Definition internal.h:144
int64_t interleaver_chunk_size
Definition internal.h:201
int64_t interleaver_chunk_duration
Definition internal.h:202
int bitstream_checked
Whether or not check_bitstream should still be run on each packet.
Definition internal.h:163
int reorder
Set to 1 if the codec allows reordering, so pts can be different from dts.
Definition internal.h:151
int is_intra_only
Definition internal.h:187
FFFrac priv_pts
Definition internal.h:189
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition internal.h:196
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
Definition format.c:917
#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