2 * muxing functions for use within Libav
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "avio_internal.h"
25 #include "libavcodec/internal.h"
26 #include "libavcodec/bytestream.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/dict.h"
29 #include "libavutil/pixdesc.h"
32 #include "libavutil/avstring.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/parseutils.h"
36 #include "libavutil/time.h"
38 #include "audiointerleave.h"
50 * muxing functions for use within Libav
53 static int validate_codec_tag(AVFormatContext *s, AVStream *st)
55 const AVCodecTag *avctag;
57 enum AVCodecID id = AV_CODEC_ID_NONE;
61 * Check that tag + id is in the table
62 * If neither is in the table -> OK
63 * If tag is in the table with another id -> FAIL
64 * If id is in the table with another tag -> FAIL unless strict < normal
66 for (n = 0; s->oformat->codec_tag[n]; n++) {
67 avctag = s->oformat->codec_tag[n];
68 while (avctag->id != AV_CODEC_ID_NONE) {
69 if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) {
71 if (id == st->codecpar->codec_id)
74 if (avctag->id == st->codecpar->codec_id)
79 if (id != AV_CODEC_ID_NONE)
81 if (tag && (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
87 static int init_muxer(AVFormatContext *s, AVDictionary **options)
91 AVDictionary *tmp = NULL;
92 AVCodecParameters *par = NULL;
93 AVOutputFormat *of = s->oformat;
94 const AVCodecDescriptor *desc;
97 av_dict_copy(&tmp, *options, 0);
99 if ((ret = av_opt_set_dict(s, &tmp)) < 0)
102 #if FF_API_LAVF_BITEXACT && FF_API_LAVF_AVCTX
103 FF_DISABLE_DEPRECATION_WARNINGS
104 if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT)
105 s->flags |= AVFMT_FLAG_BITEXACT;
106 FF_ENABLE_DEPRECATION_WARNINGS
109 // some sanity checks
110 if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
111 av_log(s, AV_LOG_ERROR, "no streams\n");
112 ret = AVERROR(EINVAL);
116 for (i = 0; i < s->nb_streams; i++) {
120 #if FF_API_LAVF_CODEC_TB && FF_API_LAVF_AVCTX
121 FF_DISABLE_DEPRECATION_WARNINGS
122 if (!st->time_base.num && st->codec->time_base.num) {
123 av_log(s, AV_LOG_WARNING, "Using AVStream.codec.time_base as a "
124 "timebase hint to the muxer is deprecated. Set "
125 "AVStream.time_base instead.\n");
126 avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
128 FF_ENABLE_DEPRECATION_WARNINGS
131 #if FF_API_LAVF_AVCTX
132 FF_DISABLE_DEPRECATION_WARNINGS
133 if (st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
134 st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) {
135 av_log(s, AV_LOG_WARNING, "Using AVStream.codec to pass codec "
136 "parameters to muxers is deprecated, use AVStream.codecpar "
138 ret = avcodec_parameters_from_context(st->codecpar, st->codec);
142 FF_ENABLE_DEPRECATION_WARNINGS
145 if (!st->time_base.num) {
146 /* fall back on the default timebase values */
147 if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate)
148 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
150 avpriv_set_pts_info(st, 33, 1, 90000);
153 switch (par->codec_type) {
154 case AVMEDIA_TYPE_AUDIO:
155 if (par->sample_rate <= 0) {
156 av_log(s, AV_LOG_ERROR, "sample rate not set\n");
157 ret = AVERROR(EINVAL);
160 if (!par->block_align)
161 par->block_align = par->channels *
162 av_get_bits_per_sample(par->codec_id) >> 3;
164 case AVMEDIA_TYPE_VIDEO:
165 if ((par->width <= 0 || par->height <= 0) &&
166 !(of->flags & AVFMT_NODIMENSIONS)) {
167 av_log(s, AV_LOG_ERROR, "dimensions not set\n");
168 ret = AVERROR(EINVAL);
172 if (av_cmp_q(st->sample_aspect_ratio,
173 par->sample_aspect_ratio)) {
174 if (st->sample_aspect_ratio.num != 0 &&
175 st->sample_aspect_ratio.den != 0 &&
176 par->sample_aspect_ratio.den != 0 &&
177 par->sample_aspect_ratio.den != 0) {
178 av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
179 "(%d/%d) and encoder layer (%d/%d)\n",
180 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
181 par->sample_aspect_ratio.num,
182 par->sample_aspect_ratio.den);
183 ret = AVERROR(EINVAL);
190 desc = avcodec_descriptor_get(par->codec_id);
191 if (desc && desc->props & AV_CODEC_PROP_REORDER)
192 st->internal->reorder = 1;
195 if (par->codec_tag &&
196 par->codec_id == AV_CODEC_ID_RAWVIDEO &&
197 !av_codec_get_tag(of->codec_tag, par->codec_id) &&
198 !validate_codec_tag(s, st)) {
199 // the current rawvideo encoding system ends up setting
200 // the wrong codec_tag for avi, we override it here
203 if (par->codec_tag) {
204 if (!validate_codec_tag(s, st)) {
206 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), par->codec_tag);
207 av_log(s, AV_LOG_ERROR,
208 "Tag %s/0x%08x incompatible with output codec id '%d'\n",
209 tagbuf, par->codec_tag, par->codec_id);
210 ret = AVERROR_INVALIDDATA;
214 par->codec_tag = av_codec_get_tag(of->codec_tag, par->codec_id);
217 if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT)
218 s->internal->nb_interleaved_streams++;
221 if (!s->priv_data && of->priv_data_size > 0) {
222 s->priv_data = av_mallocz(of->priv_data_size);
224 ret = AVERROR(ENOMEM);
227 if (of->priv_class) {
228 *(const AVClass **)s->priv_data = of->priv_class;
229 av_opt_set_defaults(s->priv_data);
230 if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
235 /* set muxer identification string */
236 if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
237 av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
241 av_dict_free(options);
252 int avformat_write_header(AVFormatContext *s, AVDictionary **options)
256 if (ret = init_muxer(s, options))
259 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
260 avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
261 if (s->oformat->write_header) {
262 ret = s->oformat->write_header(s);
266 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
267 avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN);
269 if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO) {
270 if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) {
271 s->avoid_negative_ts = 0;
273 s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE;
279 #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
280 FF_DISABLE_DEPRECATION_WARNINGS
281 //FIXME merge with compute_pkt_fields
282 static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
284 int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);
287 if (!s->internal->missing_ts_warning &&
288 !(s->oformat->flags & AVFMT_NOTIMESTAMPS) &&
289 (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE)) {
290 av_log(s, AV_LOG_WARNING,
291 "Timestamps are unset in a packet for stream %d. "
292 "This is deprecated and will stop working in the future. "
293 "Fix your code to set the timestamps properly\n", st->index);
294 s->internal->missing_ts_warning = 1;
297 av_log(s, AV_LOG_TRACE, "compute_pkt_fields2: pts:%" PRId64 " dts:%" PRId64 " cur_dts:%" PRId64 " b:%d size:%d st:%d\n",
298 pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index);
300 /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)
301 * return AVERROR(EINVAL);*/
304 if (pkt->duration == 0) {
305 ff_compute_frame_duration(s, &num, &den, st, NULL, pkt);
307 pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
311 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
314 //calculate dts from pts
315 if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
316 st->pts_buffer[0] = pkt->pts;
317 for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
318 st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
319 for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
320 FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
322 pkt->dts = st->pts_buffer[0];
325 if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
326 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
327 st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
328 av_log(s, AV_LOG_ERROR,
329 "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
330 st->index, st->cur_dts, pkt->dts);
331 return AVERROR(EINVAL);
333 if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
334 av_log(s, AV_LOG_ERROR,
335 "pts %" PRId64 " < dts %" PRId64 " in stream %d\n",
338 return AVERROR(EINVAL);
341 av_log(s, AV_LOG_TRACE, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n",
343 st->cur_dts = pkt->dts;
347 FF_ENABLE_DEPRECATION_WARNINGS
351 * FIXME: this function should NEVER get undefined pts/dts beside when the
352 * AVFMT_NOTIMESTAMPS is set.
353 * Those additional safety checks should be dropped once the correct checks
354 * are set in the callers.
357 static int write_packet(AVFormatContext *s, AVPacket *pkt)
360 // If the timestamp offsetting below is adjusted, adjust
361 // ff_interleaved_peek similarly.
362 if (s->avoid_negative_ts > 0) {
363 AVRational time_base = s->streams[pkt->stream_index]->time_base;
366 if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
367 (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
368 s->internal->offset = -pkt->dts;
369 s->internal->offset_timebase = time_base;
371 if (s->internal->offset != AV_NOPTS_VALUE)
372 offset = av_rescale_q(s->internal->offset, s->internal->offset_timebase, time_base);
374 if (pkt->dts != AV_NOPTS_VALUE)
376 if (pkt->pts != AV_NOPTS_VALUE)
379 if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
380 av_log(s, AV_LOG_WARNING,
381 "Packets poorly interleaved, failed to avoid negative "
382 "timestamp %"PRId64" in stream %d.\n"
383 "Try -max_interleave_delta 0 as a possible workaround.\n",
384 pkt->dts, pkt->stream_index);
387 ret = s->oformat->write_packet(s, pkt);
389 if (s->pb && ret >= 0) {
390 if (s->flags & AVFMT_FLAG_FLUSH_PACKETS)
392 if (s->pb->error < 0)
399 static int check_packet(AVFormatContext *s, AVPacket *pkt)
404 if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
405 av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
407 return AVERROR(EINVAL);
410 if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
411 av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n");
412 return AVERROR(EINVAL);
418 static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt)
422 ret = check_packet(s, pkt);
426 #if !FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
427 /* sanitize the timestamps */
428 if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
429 AVStream *st = s->streams[pkt->stream_index];
431 /* when there is no reordering (so dts is equal to pts), but
432 * only one of them is set, set the other as well */
433 if (!st->internal->reorder) {
434 if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE)
436 if (pkt->dts == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE)
440 /* check that the timestamps are set */
441 if (pkt->pts == AV_NOPTS_VALUE || pkt->dts == AV_NOPTS_VALUE) {
442 av_log(s, AV_LOG_ERROR,
443 "Timestamps are unset in a packet for stream %d\n", st->index);
444 return AVERROR(EINVAL);
447 /* check that the dts are increasing (or at least non-decreasing,
448 * if the format allows it */
449 if (st->cur_dts != AV_NOPTS_VALUE &&
450 ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) ||
451 st->cur_dts > pkt->dts)) {
452 av_log(s, AV_LOG_ERROR,
453 "Application provided invalid, non monotonically increasing "
454 "dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
455 st->index, st->cur_dts, pkt->dts);
456 return AVERROR(EINVAL);
459 if (pkt->pts < pkt->dts) {
460 av_log(s, AV_LOG_ERROR, "pts %" PRId64 " < dts %" PRId64 " in stream %d\n",
461 pkt->pts, pkt->dts, st->index);
462 return AVERROR(EINVAL);
470 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
474 ret = prepare_input_packet(s, pkt);
479 if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
480 return s->oformat->write_packet(s, pkt);
484 #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
485 ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
487 if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
491 ret = write_packet(s, pkt);
494 s->streams[pkt->stream_index]->nb_frames++;
498 int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
499 int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
502 AVPacketList **next_point, *this_pktl;
504 this_pktl = av_mallocz(sizeof(AVPacketList));
506 return AVERROR(ENOMEM);
508 if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) {
513 if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
514 next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
516 next_point = &s->internal->packet_buffer;
519 if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) {
520 while (!compare(s, &(*next_point)->pkt, pkt))
521 next_point = &(*next_point)->next;
524 next_point = &(s->internal->packet_buffer_end->next);
527 assert(!*next_point);
529 s->internal->packet_buffer_end = this_pktl;
532 this_pktl->next = *next_point;
534 s->streams[pkt->stream_index]->last_in_packet_buffer =
535 *next_point = this_pktl;
537 av_packet_unref(pkt);
542 static int interleave_compare_dts(AVFormatContext *s, AVPacket *next,
545 AVStream *st = s->streams[pkt->stream_index];
546 AVStream *st2 = s->streams[next->stream_index];
547 int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
551 return pkt->stream_index < next->stream_index;
555 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
556 AVPacket *pkt, int flush)
559 int stream_count = 0;
563 if ((ret = ff_interleave_add_packet(s, pkt, interleave_compare_dts)) < 0)
567 if (s->max_interleave_delta > 0 && s->internal->packet_buffer && !flush) {
568 AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
569 int64_t delta_dts = INT64_MIN;
570 int64_t top_dts = av_rescale_q(top_pkt->dts,
571 s->streams[top_pkt->stream_index]->time_base,
574 for (i = 0; i < s->nb_streams; i++) {
576 const AVPacketList *last = s->streams[i]->last_in_packet_buffer;
581 last_dts = av_rescale_q(last->pkt.dts,
582 s->streams[i]->time_base,
584 delta_dts = FFMAX(delta_dts, last_dts - top_dts);
588 if (delta_dts > s->max_interleave_delta) {
589 av_log(s, AV_LOG_DEBUG,
590 "Delay between the first packet and last packet in the "
591 "muxing queue is %"PRId64" > %"PRId64": forcing output\n",
592 delta_dts, s->max_interleave_delta);
596 for (i = 0; i < s->nb_streams; i++)
597 stream_count += !!s->streams[i]->last_in_packet_buffer;
601 if (stream_count && (s->internal->nb_interleaved_streams == stream_count || flush)) {
602 pktl = s->internal->packet_buffer;
605 s->internal->packet_buffer = pktl->next;
606 if (!s->internal->packet_buffer)
607 s->internal->packet_buffer_end = NULL;
609 if (s->streams[out->stream_index]->last_in_packet_buffer == pktl)
610 s->streams[out->stream_index]->last_in_packet_buffer = NULL;
619 int ff_interleaved_peek(AVFormatContext *s, int stream,
620 AVPacket *pkt, int add_offset)
622 AVPacketList *pktl = s->internal->packet_buffer;
624 if (pktl->pkt.stream_index == stream) {
626 if (add_offset && s->internal->offset != AV_NOPTS_VALUE) {
627 int64_t offset = av_rescale_q(s->internal->offset,
628 s->internal->offset_timebase,
629 s->streams[stream]->time_base);
630 if (pkt->dts != AV_NOPTS_VALUE)
632 if (pkt->pts != AV_NOPTS_VALUE)
639 return AVERROR(ENOENT);
643 * Interleave an AVPacket correctly so it can be muxed.
644 * @param out the interleaved packet will be output here
645 * @param in the input packet
646 * @param flush 1 if no further packets are available as input and all
647 * remaining packets should be output
648 * @return 1 if a packet was output, 0 if no packet could be output,
649 * < 0 if an error occurred
651 static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
653 if (s->oformat->interleave_packet) {
654 int ret = s->oformat->interleave_packet(s, out, in, flush);
659 return ff_interleave_packet_per_dts(s, out, in, flush);
662 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
666 ret = prepare_input_packet(s, pkt);
671 #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX
672 AVStream *st = s->streams[pkt->stream_index];
674 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",
675 pkt->size, pkt->dts, pkt->pts);
676 if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
680 if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
681 ret = AVERROR(EINVAL);
685 av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
691 int ret = interleave_packet(s, &opkt, pkt, flush);
693 memset(pkt, 0, sizeof(*pkt));
697 if (ret <= 0) //FIXME cleanup needed for ret<0 ?
700 ret = write_packet(s, &opkt);
702 s->streams[opkt.stream_index]->nb_frames++;
704 av_packet_unref(&opkt);
710 av_packet_unref(pkt);
714 int av_write_trailer(AVFormatContext *s)
720 ret = interleave_packet(s, &pkt, NULL, 1);
721 if (ret < 0) //FIXME cleanup needed for ret<0 ?
726 ret = write_packet(s, &pkt);
728 s->streams[pkt.stream_index]->nb_frames++;
730 av_packet_unref(&pkt);
736 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
737 avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);
738 if (s->oformat->write_trailer)
739 ret = s->oformat->write_trailer(s);
741 if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
745 for (i = 0; i < s->nb_streams; i++) {
746 av_freep(&s->streams[i]->priv_data);
747 av_freep(&s->streams[i]->index_entries);
749 if (s->oformat->priv_class)
750 av_opt_free(s->priv_data);
751 av_freep(&s->priv_data);
755 int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
756 AVFormatContext *src)
761 local_pkt.stream_index = dst_stream;
762 if (pkt->pts != AV_NOPTS_VALUE)
763 local_pkt.pts = av_rescale_q(pkt->pts,
764 src->streams[pkt->stream_index]->time_base,
765 dst->streams[dst_stream]->time_base);
766 if (pkt->dts != AV_NOPTS_VALUE)
767 local_pkt.dts = av_rescale_q(pkt->dts,
768 src->streams[pkt->stream_index]->time_base,
769 dst->streams[dst_stream]->time_base);
770 return av_write_frame(dst, &local_pkt);