2 * muxing functions for use within FFmpeg
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
25 #include "avio_internal.h"
27 #include "libavcodec/internal.h"
28 #include "libavcodec/bytestream.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/dict.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/timestamp.h"
35 #include "libavutil/avassert.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/time.h"
41 #include "audiointerleave.h"
53 * muxing functions for use within libavformat
56 /* fraction handling */
59 * f = val + (num / den) + 0.5.
61 * 'num' is normalized so that it is such as 0 <= num < den.
63 * @param f fractional number
64 * @param val integer value
65 * @param num must be >= 0
66 * @param den must be >= 1
68 static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
81 * Fractional addition to f: f = f + (incr / f->den).
83 * @param f fractional number
84 * @param incr increment, can be positive or negative
86 static void frac_add(AVFrac *f, int64_t incr)
99 } else if (num >= den) {
106 AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission)
111 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
112 q = (AVRational){1, st->codec->sample_rate};
114 q = st->codec->time_base;
116 for (j=2; j<14; j+= 1+(j>2))
117 while (q.den / q.num < min_precission && q.num % j == 0)
119 while (q.den / q.num < min_precission && q.den < (1<<24))
125 int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
126 const char *format, const char *filename)
128 AVFormatContext *s = avformat_alloc_context();
137 oformat = av_guess_format(format, NULL, NULL);
139 av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format);
140 ret = AVERROR(EINVAL);
144 oformat = av_guess_format(NULL, filename, NULL);
146 ret = AVERROR(EINVAL);
147 av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n",
154 s->oformat = oformat;
155 if (s->oformat->priv_data_size > 0) {
156 s->priv_data = av_mallocz(s->oformat->priv_data_size);
159 if (s->oformat->priv_class) {
160 *(const AVClass**)s->priv_data= s->oformat->priv_class;
161 av_opt_set_defaults(s->priv_data);
167 av_strlcpy(s->filename, filename, sizeof(s->filename));
171 av_log(s, AV_LOG_ERROR, "Out of memory\n");
172 ret = AVERROR(ENOMEM);
174 avformat_free_context(s);
178 #if FF_API_ALLOC_OUTPUT_CONTEXT
179 AVFormatContext *avformat_alloc_output_context(const char *format,
180 AVOutputFormat *oformat, const char *filename)
182 AVFormatContext *avctx;
183 int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename);
184 return ret < 0 ? NULL : avctx;
188 static int validate_codec_tag(AVFormatContext *s, AVStream *st)
190 const AVCodecTag *avctag;
192 enum AVCodecID id = AV_CODEC_ID_NONE;
193 unsigned int tag = 0;
196 * Check that tag + id is in the table
197 * If neither is in the table -> OK
198 * If tag is in the table with another id -> FAIL
199 * If id is in the table with another tag -> FAIL unless strict < normal
201 for (n = 0; s->oformat->codec_tag[n]; n++) {
202 avctag = s->oformat->codec_tag[n];
203 while (avctag->id != AV_CODEC_ID_NONE) {
204 if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) {
206 if (id == st->codec->codec_id)
209 if (avctag->id == st->codec->codec_id)
214 if (id != AV_CODEC_ID_NONE)
216 if (tag && (st->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
222 static int init_muxer(AVFormatContext *s, AVDictionary **options)
226 AVDictionary *tmp = NULL;
227 AVCodecContext *codec = NULL;
228 AVOutputFormat *of = s->oformat;
231 av_dict_copy(&tmp, *options, 0);
233 if ((ret = av_opt_set_dict(s, &tmp)) < 0)
235 if (s->priv_data && s->oformat->priv_class && *(const AVClass**)s->priv_data==s->oformat->priv_class &&
236 (ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
239 // some sanity checks
240 if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
241 av_log(s, AV_LOG_ERROR, "no streams\n");
242 ret = AVERROR(EINVAL);
246 for (i = 0; i < s->nb_streams; i++) {
250 switch (codec->codec_type) {
251 case AVMEDIA_TYPE_AUDIO:
252 if (codec->sample_rate <= 0) {
253 av_log(s, AV_LOG_ERROR, "sample rate not set\n");
254 ret = AVERROR(EINVAL);
257 if (!codec->block_align)
258 codec->block_align = codec->channels *
259 av_get_bits_per_sample(codec->codec_id) >> 3;
261 case AVMEDIA_TYPE_VIDEO:
262 if (codec->time_base.num <= 0 ||
263 codec->time_base.den <= 0) { //FIXME audio too?
264 av_log(s, AV_LOG_ERROR, "time base not set\n");
265 ret = AVERROR(EINVAL);
269 if ((codec->width <= 0 || codec->height <= 0) &&
270 !(of->flags & AVFMT_NODIMENSIONS)) {
271 av_log(s, AV_LOG_ERROR, "dimensions not set\n");
272 ret = AVERROR(EINVAL);
275 if (av_cmp_q(st->sample_aspect_ratio, codec->sample_aspect_ratio)
276 && FFABS(av_q2d(st->sample_aspect_ratio) - av_q2d(codec->sample_aspect_ratio)) > 0.004*av_q2d(st->sample_aspect_ratio)
278 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
279 "(%d/%d) and encoder layer (%d/%d)\n",
280 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
281 codec->sample_aspect_ratio.num,
282 codec->sample_aspect_ratio.den);
283 ret = AVERROR(EINVAL);
290 if ( codec->codec_tag
291 && codec->codec_id == AV_CODEC_ID_RAWVIDEO
292 && ( av_codec_get_tag(of->codec_tag, codec->codec_id) == 0
293 || av_codec_get_tag(of->codec_tag, codec->codec_id) == MKTAG('r', 'a', 'w', ' '))
294 && !validate_codec_tag(s, st)) {
295 // the current rawvideo encoding system ends up setting
296 // the wrong codec_tag for avi/mov, we override it here
297 codec->codec_tag = 0;
299 if (codec->codec_tag) {
300 if (!validate_codec_tag(s, st)) {
301 char tagbuf[32], cortag[32];
302 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag);
303 av_get_codec_tag_string(cortag, sizeof(cortag), av_codec_get_tag(s->oformat->codec_tag, codec->codec_id));
304 av_log(s, AV_LOG_ERROR,
305 "Tag %s/0x%08x incompatible with output codec id '%d' (%s)\n",
306 tagbuf, codec->codec_tag, codec->codec_id, cortag);
307 ret = AVERROR_INVALIDDATA;
311 codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id);
314 if (of->flags & AVFMT_GLOBALHEADER &&
315 !(codec->flags & CODEC_FLAG_GLOBAL_HEADER))
316 av_log(s, AV_LOG_WARNING,
317 "Codec for stream %d does not use global headers "
318 "but container format requires global headers\n", i);
321 if (!s->priv_data && of->priv_data_size > 0) {
322 s->priv_data = av_mallocz(of->priv_data_size);
324 ret = AVERROR(ENOMEM);
327 if (of->priv_class) {
328 *(const AVClass **)s->priv_data = of->priv_class;
329 av_opt_set_defaults(s->priv_data);
330 if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
335 /* set muxer identification string */
336 if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
337 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
341 av_dict_free(options);
352 static int init_pts(AVFormatContext *s)
357 /* init PTS generation */
358 for (i = 0; i < s->nb_streams; i++) {
359 int64_t den = AV_NOPTS_VALUE;
362 switch (st->codec->codec_type) {
363 case AVMEDIA_TYPE_AUDIO:
364 den = (int64_t)st->time_base.num * st->codec->sample_rate;
366 case AVMEDIA_TYPE_VIDEO:
367 den = (int64_t)st->time_base.num * st->codec->time_base.den;
372 if (den != AV_NOPTS_VALUE) {
374 return AVERROR_INVALIDDATA;
376 frac_init(&st->pts, 0, 0, den);
383 int avformat_write_header(AVFormatContext *s, AVDictionary **options)
387 if (ret = init_muxer(s, options))
390 if (s->oformat->write_header) {
391 ret = s->oformat->write_header(s);
392 if (ret >= 0 && s->pb && s->pb->error < 0)
398 if ((ret = init_pts(s)) < 0)
401 if (s->avoid_negative_ts < 0) {
402 if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
403 s->avoid_negative_ts = 0;
405 s->avoid_negative_ts = 1;
411 //FIXME merge with compute_pkt_fields
412 static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
414 int delay = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames > 0);
415 int num, den, frame_size, i;
417 av_dlog(s, "compute_pkt_fields2: pts:%s dts:%s cur_dts:%s b:%d size:%d st:%d\n",
418 av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(st->cur_dts), delay, pkt->size, pkt->stream_index);
421 if (pkt->duration == 0) {
422 ff_compute_frame_duration(&num, &den, st, NULL, pkt);
424 pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
428 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
431 //XXX/FIXME this is a temporary hack until all encoders output pts
432 if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
435 av_log(s, AV_LOG_WARNING, "Encoder did not produce proper pts, making some up.\n");
439 // pkt->pts= st->cur_dts;
440 pkt->pts = st->pts.val;
443 //calculate dts from pts
444 if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
445 st->pts_buffer[0] = pkt->pts;
446 for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
447 st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
448 for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
449 FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
451 pkt->dts = st->pts_buffer[0];
454 if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
455 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
456 st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
457 av_log(s, AV_LOG_ERROR,
458 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n",
459 st->index, av_ts2str(st->cur_dts), av_ts2str(pkt->dts));
460 return AVERROR(EINVAL);
462 if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
463 av_log(s, AV_LOG_ERROR, "pts (%s) < dts (%s) in stream %d\n",
464 av_ts2str(pkt->pts), av_ts2str(pkt->dts), st->index);
465 return AVERROR(EINVAL);
468 av_dlog(s, "av_write_frame: pts2:%s dts2:%s\n",
469 av_ts2str(pkt->pts), av_ts2str(pkt->dts));
470 st->cur_dts = pkt->dts;
471 st->pts.val = pkt->dts;
474 switch (st->codec->codec_type) {
475 case AVMEDIA_TYPE_AUDIO:
476 frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 1);
478 /* HACK/FIXME, we skip the initial 0 size packets as they are most
479 * likely equal to the encoder delay, but it would be better if we
480 * had the real timestamps from the encoder */
481 if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
482 frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
485 case AVMEDIA_TYPE_VIDEO:
486 frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
495 * Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore
498 * FIXME: this function should NEVER get undefined pts/dts beside when the
499 * AVFMT_NOTIMESTAMPS is set.
500 * Those additional safety checks should be dropped once the correct checks
501 * are set in the callers.
503 static int write_packet(AVFormatContext *s, AVPacket *pkt)
507 if (s->avoid_negative_ts > 0) {
508 AVStream *st = s->streams[pkt->stream_index];
509 int64_t offset = st->mux_ts_offset;
511 if (pkt->dts < 0 && pkt->dts != AV_NOPTS_VALUE && !s->offset) {
512 s->offset = -pkt->dts;
513 s->offset_timebase = st->time_base;
516 if (s->offset && !offset) {
517 offset = st->mux_ts_offset =
518 av_rescale_q_rnd(s->offset,
524 if (pkt->dts != AV_NOPTS_VALUE)
526 if (pkt->pts != AV_NOPTS_VALUE)
529 av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0);
532 did_split = av_packet_split_side_data(pkt);
533 ret = s->oformat->write_packet(s, pkt);
534 if (s->flush_packets && s->pb && s->pb->error >= 0)
537 av_packet_merge_side_data(pkt);
541 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
546 if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
547 ret = s->oformat->write_packet(s, NULL);
548 if (s->flush_packets && s->pb && s->pb->error >= 0)
550 if (ret >= 0 && s->pb && s->pb->error < 0)
557 ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
559 if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
562 ret = write_packet(s, pkt);
563 if (ret >= 0 && s->pb && s->pb->error < 0)
567 s->streams[pkt->stream_index]->nb_frames++;
571 #define CHUNK_START 0x1000
573 int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
574 int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
576 AVPacketList **next_point, *this_pktl;
577 AVStream *st = s->streams[pkt->stream_index];
578 int chunked = s->max_chunk_size || s->max_chunk_duration;
580 this_pktl = av_mallocz(sizeof(AVPacketList));
582 return AVERROR(ENOMEM);
583 this_pktl->pkt = *pkt;
584 #if FF_API_DESTRUCT_PACKET
585 pkt->destruct = NULL; // do not free original but only the copy
588 av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-allocated memory
590 if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
591 next_point = &(st->last_in_packet_buffer->next);
593 next_point = &s->packet_buffer;
597 uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);
598 st->interleaver_chunk_size += pkt->size;
599 st->interleaver_chunk_duration += pkt->duration;
600 if ( (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size)
601 || (max && st->interleaver_chunk_duration > max)) {
602 st->interleaver_chunk_size = 0;
603 this_pktl->pkt.flags |= CHUNK_START;
604 if (max && st->interleaver_chunk_duration > max) {
605 int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
606 int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
608 st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
610 st->interleaver_chunk_duration = 0;
614 if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
617 if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
619 && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
620 || !compare(s, &(*next_point)->pkt, pkt)))
621 next_point = &(*next_point)->next;
625 next_point = &(s->packet_buffer_end->next);
628 av_assert1(!*next_point);
630 s->packet_buffer_end = this_pktl;
633 this_pktl->next = *next_point;
635 s->streams[pkt->stream_index]->last_in_packet_buffer =
636 *next_point = this_pktl;
640 static int interleave_compare_dts(AVFormatContext *s, AVPacket *next,
643 AVStream *st = s->streams[pkt->stream_index];
644 AVStream *st2 = s->streams[next->stream_index];
645 int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
647 if (s->audio_preload && ((st->codec->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codec->codec_type == AVMEDIA_TYPE_AUDIO))) {
648 int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO);
649 int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO);
651 ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den
652 -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den;
655 comp= (ts>ts2) - (ts<ts2);
659 return pkt->stream_index < next->stream_index;
663 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
664 AVPacket *pkt, int flush)
667 int stream_count = 0, noninterleaved_count = 0;
668 int64_t delta_dts_max = 0;
672 ret = ff_interleave_add_packet(s, pkt, interleave_compare_dts);
677 for (i = 0; i < s->nb_streams; i++) {
678 if (s->streams[i]->last_in_packet_buffer) {
680 } else if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
681 ++noninterleaved_count;
685 if (s->nb_streams == stream_count) {
688 for (i=0; i < s->nb_streams; i++) {
689 if (s->streams[i]->last_in_packet_buffer) {
691 av_rescale_q(s->streams[i]->last_in_packet_buffer->pkt.dts,
692 s->streams[i]->time_base,
694 av_rescale_q(s->packet_buffer->pkt.dts,
695 s->streams[s->packet_buffer->pkt.stream_index]->time_base,
697 delta_dts_max= FFMAX(delta_dts_max, delta_dts);
700 if (s->nb_streams == stream_count+noninterleaved_count &&
701 delta_dts_max > 20*AV_TIME_BASE) {
702 av_log(s, AV_LOG_DEBUG, "flushing with %d noninterleaved\n", noninterleaved_count);
706 if (stream_count && flush) {
708 pktl = s->packet_buffer;
710 st = s->streams[out->stream_index];
712 s->packet_buffer = pktl->next;
713 if (!s->packet_buffer)
714 s->packet_buffer_end = NULL;
716 if (st->last_in_packet_buffer == pktl)
717 st->last_in_packet_buffer = NULL;
728 * Interleave an AVPacket correctly so it can be muxed.
729 * @param out the interleaved packet will be output here
730 * @param in the input packet
731 * @param flush 1 if no further packets are available as input and all
732 * remaining packets should be output
733 * @return 1 if a packet was output, 0 if no packet could be output,
734 * < 0 if an error occurred
736 static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
738 if (s->oformat->interleave_packet) {
739 int ret = s->oformat->interleave_packet(s, out, in, flush);
744 return ff_interleave_packet_per_dts(s, out, in, flush);
747 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
752 AVStream *st = s->streams[pkt->stream_index];
754 //FIXME/XXX/HACK drop zero sized packets
755 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0)
758 av_dlog(s, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",
759 pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
760 if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
763 if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
764 return AVERROR(EINVAL);
766 av_dlog(s, "av_interleaved_write_frame FLUSH\n");
772 int ret = interleave_packet(s, &opkt, pkt, flush);
773 if (ret <= 0) //FIXME cleanup needed for ret<0 ?
776 ret = write_packet(s, &opkt);
778 s->streams[opkt.stream_index]->nb_frames++;
780 av_free_packet(&opkt);
785 if(s->pb && s->pb->error)
790 int av_write_trailer(AVFormatContext *s)
796 ret = interleave_packet(s, &pkt, NULL, 1);
797 if (ret < 0) //FIXME cleanup needed for ret<0 ?
802 ret = write_packet(s, &pkt);
804 s->streams[pkt.stream_index]->nb_frames++;
806 av_free_packet(&pkt);
810 if(s->pb && s->pb->error)
814 if (s->oformat->write_trailer)
815 ret = s->oformat->write_trailer(s);
821 ret = s->pb ? s->pb->error : 0;
822 for (i = 0; i < s->nb_streams; i++) {
823 av_freep(&s->streams[i]->priv_data);
824 av_freep(&s->streams[i]->index_entries);
826 if (s->oformat->priv_class)
827 av_opt_free(s->priv_data);
828 av_freep(&s->priv_data);
832 int av_get_output_timestamp(struct AVFormatContext *s, int stream,
833 int64_t *dts, int64_t *wall)
835 if (!s->oformat || !s->oformat->get_output_timestamp)
836 return AVERROR(ENOSYS);
837 s->oformat->get_output_timestamp(s, stream, dts, wall);