You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

656 lines
20KB

  1. /*
  2. * muxing functions for use within Libav
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. *
  5. * This file is part of Libav.
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. */
  21. #include "avformat.h"
  22. #include "avio_internal.h"
  23. #include "internal.h"
  24. #include "libavcodec/internal.h"
  25. #include "libavcodec/bytestream.h"
  26. #include "libavutil/opt.h"
  27. #include "libavutil/dict.h"
  28. #include "libavutil/pixdesc.h"
  29. #include "metadata.h"
  30. #include "id3v2.h"
  31. #include "libavutil/avassert.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"
  37. #include "riff.h"
  38. #include "audiointerleave.h"
  39. #include "url.h"
  40. #include <stdarg.h>
  41. #if CONFIG_NETWORK
  42. #include "network.h"
  43. #endif
  44. #undef NDEBUG
  45. #include <assert.h>
  46. /**
  47. * @file
  48. * muxing functions for use within Libav
  49. */
  50. /* fraction handling */
  51. /**
  52. * f = val + (num / den) + 0.5.
  53. *
  54. * 'num' is normalized so that it is such as 0 <= num < den.
  55. *
  56. * @param f fractional number
  57. * @param val integer value
  58. * @param num must be >= 0
  59. * @param den must be >= 1
  60. */
  61. static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
  62. {
  63. num += (den >> 1);
  64. if (num >= den) {
  65. val += num / den;
  66. num = num % den;
  67. }
  68. f->val = val;
  69. f->num = num;
  70. f->den = den;
  71. }
  72. /**
  73. * Fractional addition to f: f = f + (incr / f->den).
  74. *
  75. * @param f fractional number
  76. * @param incr increment, can be positive or negative
  77. */
  78. static void frac_add(AVFrac *f, int64_t incr)
  79. {
  80. int64_t num, den;
  81. num = f->num + incr;
  82. den = f->den;
  83. if (num < 0) {
  84. f->val += num / den;
  85. num = num % den;
  86. if (num < 0) {
  87. num += den;
  88. f->val--;
  89. }
  90. } else if (num >= den) {
  91. f->val += num / den;
  92. num = num % den;
  93. }
  94. f->num = num;
  95. }
  96. static int validate_codec_tag(AVFormatContext *s, AVStream *st)
  97. {
  98. const AVCodecTag *avctag;
  99. int n;
  100. enum AVCodecID id = AV_CODEC_ID_NONE;
  101. unsigned int tag = 0;
  102. /**
  103. * Check that tag + id is in the table
  104. * If neither is in the table -> OK
  105. * If tag is in the table with another id -> FAIL
  106. * If id is in the table with another tag -> FAIL unless strict < normal
  107. */
  108. for (n = 0; s->oformat->codec_tag[n]; n++) {
  109. avctag = s->oformat->codec_tag[n];
  110. while (avctag->id != AV_CODEC_ID_NONE) {
  111. if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) {
  112. id = avctag->id;
  113. if (id == st->codec->codec_id)
  114. return 1;
  115. }
  116. if (avctag->id == st->codec->codec_id)
  117. tag = avctag->tag;
  118. avctag++;
  119. }
  120. }
  121. if (id != AV_CODEC_ID_NONE)
  122. return 0;
  123. if (tag && (st->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
  124. return 0;
  125. return 1;
  126. }
  127. static int init_muxer(AVFormatContext *s, AVDictionary **options)
  128. {
  129. int ret = 0, i;
  130. AVStream *st;
  131. AVDictionary *tmp = NULL;
  132. AVCodecContext *codec = NULL;
  133. AVOutputFormat *of = s->oformat;
  134. if (options)
  135. av_dict_copy(&tmp, *options, 0);
  136. if ((ret = av_opt_set_dict(s, &tmp)) < 0)
  137. goto fail;
  138. // some sanity checks
  139. if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) {
  140. av_log(s, AV_LOG_ERROR, "no streams\n");
  141. ret = AVERROR(EINVAL);
  142. goto fail;
  143. }
  144. for (i = 0; i < s->nb_streams; i++) {
  145. st = s->streams[i];
  146. codec = st->codec;
  147. switch (codec->codec_type) {
  148. case AVMEDIA_TYPE_AUDIO:
  149. if (codec->sample_rate <= 0) {
  150. av_log(s, AV_LOG_ERROR, "sample rate not set\n");
  151. ret = AVERROR(EINVAL);
  152. goto fail;
  153. }
  154. if (!codec->block_align)
  155. codec->block_align = codec->channels *
  156. av_get_bits_per_sample(codec->codec_id) >> 3;
  157. break;
  158. case AVMEDIA_TYPE_VIDEO:
  159. if (codec->time_base.num <= 0 ||
  160. codec->time_base.den <= 0) { //FIXME audio too?
  161. av_log(s, AV_LOG_ERROR, "time base not set\n");
  162. ret = AVERROR(EINVAL);
  163. goto fail;
  164. }
  165. if ((codec->width <= 0 || codec->height <= 0) &&
  166. !(of->flags & AVFMT_NODIMENSIONS)) {
  167. av_log(s, AV_LOG_ERROR, "dimensions not set\n");
  168. ret = AVERROR(EINVAL);
  169. goto fail;
  170. }
  171. if (av_cmp_q(st->sample_aspect_ratio,
  172. codec->sample_aspect_ratio)) {
  173. if (st->sample_aspect_ratio.num != 0 &&
  174. st->sample_aspect_ratio.den != 0 &&
  175. codec->sample_aspect_ratio.den != 0 &&
  176. codec->sample_aspect_ratio.den != 0) {
  177. av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer "
  178. "(%d/%d) and encoder layer (%d/%d)\n",
  179. st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
  180. codec->sample_aspect_ratio.num,
  181. codec->sample_aspect_ratio.den);
  182. ret = AVERROR(EINVAL);
  183. goto fail;
  184. }
  185. }
  186. break;
  187. }
  188. if (of->codec_tag) {
  189. if (codec->codec_tag &&
  190. codec->codec_id == AV_CODEC_ID_RAWVIDEO &&
  191. !av_codec_get_tag(of->codec_tag, codec->codec_id) &&
  192. !validate_codec_tag(s, st)) {
  193. // the current rawvideo encoding system ends up setting
  194. // the wrong codec_tag for avi, we override it here
  195. codec->codec_tag = 0;
  196. }
  197. if (codec->codec_tag) {
  198. if (!validate_codec_tag(s, st)) {
  199. char tagbuf[32];
  200. av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag);
  201. av_log(s, AV_LOG_ERROR,
  202. "Tag %s/0x%08x incompatible with output codec id '%d'\n",
  203. tagbuf, codec->codec_tag, codec->codec_id);
  204. ret = AVERROR_INVALIDDATA;
  205. goto fail;
  206. }
  207. } else
  208. codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id);
  209. }
  210. if (of->flags & AVFMT_GLOBALHEADER &&
  211. !(codec->flags & CODEC_FLAG_GLOBAL_HEADER))
  212. av_log(s, AV_LOG_WARNING,
  213. "Codec for stream %d does not use global headers "
  214. "but container format requires global headers\n", i);
  215. }
  216. if (!s->priv_data && of->priv_data_size > 0) {
  217. s->priv_data = av_mallocz(of->priv_data_size);
  218. if (!s->priv_data) {
  219. ret = AVERROR(ENOMEM);
  220. goto fail;
  221. }
  222. if (of->priv_class) {
  223. *(const AVClass **)s->priv_data = of->priv_class;
  224. av_opt_set_defaults(s->priv_data);
  225. if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
  226. goto fail;
  227. }
  228. }
  229. /* set muxer identification string */
  230. if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
  231. av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
  232. }
  233. if (options) {
  234. av_dict_free(options);
  235. *options = tmp;
  236. }
  237. return 0;
  238. fail:
  239. av_dict_free(&tmp);
  240. return ret;
  241. }
  242. static int init_pts(AVFormatContext *s)
  243. {
  244. int i;
  245. AVStream *st;
  246. /* init PTS generation */
  247. for (i = 0; i < s->nb_streams; i++) {
  248. int64_t den = AV_NOPTS_VALUE;
  249. st = s->streams[i];
  250. switch (st->codec->codec_type) {
  251. case AVMEDIA_TYPE_AUDIO:
  252. den = (int64_t)st->time_base.num * st->codec->sample_rate;
  253. break;
  254. case AVMEDIA_TYPE_VIDEO:
  255. den = (int64_t)st->time_base.num * st->codec->time_base.den;
  256. break;
  257. default:
  258. break;
  259. }
  260. if (den != AV_NOPTS_VALUE) {
  261. if (den <= 0)
  262. return AVERROR_INVALIDDATA;
  263. frac_init(&st->pts, 0, 0, den);
  264. }
  265. }
  266. return 0;
  267. }
  268. int avformat_write_header(AVFormatContext *s, AVDictionary **options)
  269. {
  270. int ret = 0;
  271. if (ret = init_muxer(s, options))
  272. return ret;
  273. if (s->oformat->write_header) {
  274. ret = s->oformat->write_header(s);
  275. if (ret < 0)
  276. return ret;
  277. }
  278. if ((ret = init_pts(s)) < 0)
  279. return ret;
  280. return 0;
  281. }
  282. //FIXME merge with compute_pkt_fields
  283. static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
  284. {
  285. int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);
  286. int num, den, frame_size, i;
  287. av_dlog(s, "compute_pkt_fields2: pts:%" PRId64 " dts:%" PRId64 " cur_dts:%" PRId64 " b:%d size:%d st:%d\n",
  288. pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index);
  289. /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)
  290. * return AVERROR(EINVAL);*/
  291. /* duration field */
  292. if (pkt->duration == 0) {
  293. ff_compute_frame_duration(&num, &den, st, NULL, pkt);
  294. if (den && num) {
  295. pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num);
  296. }
  297. }
  298. if (pkt->pts == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && delay == 0)
  299. pkt->pts = pkt->dts;
  300. //XXX/FIXME this is a temporary hack until all encoders output pts
  301. if ((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay) {
  302. pkt->dts =
  303. // pkt->pts= st->cur_dts;
  304. pkt->pts = st->pts.val;
  305. }
  306. //calculate dts from pts
  307. if (pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
  308. st->pts_buffer[0] = pkt->pts;
  309. for (i = 1; i < delay + 1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
  310. st->pts_buffer[i] = pkt->pts + (i - delay - 1) * pkt->duration;
  311. for (i = 0; i<delay && st->pts_buffer[i] > st->pts_buffer[i + 1]; i++)
  312. FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i + 1]);
  313. pkt->dts = st->pts_buffer[0];
  314. }
  315. if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE &&
  316. ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) &&
  317. st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) {
  318. av_log(s, AV_LOG_ERROR,
  319. "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %" PRId64 " >= %" PRId64 "\n",
  320. st->index, st->cur_dts, pkt->dts);
  321. return AVERROR(EINVAL);
  322. }
  323. if (pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts) {
  324. av_log(s, AV_LOG_ERROR, "pts < dts in stream %d\n", st->index);
  325. return AVERROR(EINVAL);
  326. }
  327. av_dlog(s, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n",
  328. pkt->pts, pkt->dts);
  329. st->cur_dts = pkt->dts;
  330. st->pts.val = pkt->dts;
  331. /* update pts */
  332. switch (st->codec->codec_type) {
  333. case AVMEDIA_TYPE_AUDIO:
  334. frame_size = ff_get_audio_frame_size(st->codec, pkt->size, 1);
  335. /* HACK/FIXME, we skip the initial 0 size packets as they are most
  336. * likely equal to the encoder delay, but it would be better if we
  337. * had the real timestamps from the encoder */
  338. if (frame_size >= 0 && (pkt->size || st->pts.num != st->pts.den >> 1 || st->pts.val)) {
  339. frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
  340. }
  341. break;
  342. case AVMEDIA_TYPE_VIDEO:
  343. frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num);
  344. break;
  345. default:
  346. break;
  347. }
  348. return 0;
  349. }
  350. /*
  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.
  355. */
  356. static int write_packet(AVFormatContext *s, AVPacket *pkt)
  357. {
  358. int ret;
  359. if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) {
  360. AVRational time_base = s->streams[pkt->stream_index]->time_base;
  361. int64_t offset = 0;
  362. if (!s->offset && pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
  363. s->offset = -pkt->dts;
  364. s->offset_timebase = time_base;
  365. }
  366. if (s->offset)
  367. offset = av_rescale_q(s->offset, s->offset_timebase, time_base);
  368. if (pkt->dts != AV_NOPTS_VALUE)
  369. pkt->dts += offset;
  370. if (pkt->pts != AV_NOPTS_VALUE)
  371. pkt->pts += offset;
  372. }
  373. ret = s->oformat->write_packet(s, pkt);
  374. if (s->pb && ret >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
  375. avio_flush(s->pb);
  376. return ret;
  377. }
  378. int av_write_frame(AVFormatContext *s, AVPacket *pkt)
  379. {
  380. int ret;
  381. if (!pkt) {
  382. if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
  383. return s->oformat->write_packet(s, pkt);
  384. return 1;
  385. }
  386. ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
  387. if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
  388. return ret;
  389. ret = write_packet(s, pkt);
  390. if (ret >= 0)
  391. s->streams[pkt->stream_index]->nb_frames++;
  392. return ret;
  393. }
  394. void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
  395. int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
  396. {
  397. AVPacketList **next_point, *this_pktl;
  398. this_pktl = av_mallocz(sizeof(AVPacketList));
  399. this_pktl->pkt = *pkt;
  400. #if FF_API_DESTRUCT_PACKET
  401. FF_DISABLE_DEPRECATION_WARNINGS
  402. pkt->destruct = NULL; // do not free original but only the copy
  403. FF_ENABLE_DEPRECATION_WARNINGS
  404. #endif
  405. pkt->buf = NULL;
  406. av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory
  407. if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
  408. next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
  409. } else
  410. next_point = &s->packet_buffer;
  411. if (*next_point) {
  412. if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
  413. while (!compare(s, &(*next_point)->pkt, pkt))
  414. next_point = &(*next_point)->next;
  415. goto next_non_null;
  416. } else {
  417. next_point = &(s->packet_buffer_end->next);
  418. }
  419. }
  420. assert(!*next_point);
  421. s->packet_buffer_end = this_pktl;
  422. next_non_null:
  423. this_pktl->next = *next_point;
  424. s->streams[pkt->stream_index]->last_in_packet_buffer =
  425. *next_point = this_pktl;
  426. }
  427. static int interleave_compare_dts(AVFormatContext *s, AVPacket *next,
  428. AVPacket *pkt)
  429. {
  430. AVStream *st = s->streams[pkt->stream_index];
  431. AVStream *st2 = s->streams[next->stream_index];
  432. int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts,
  433. st->time_base);
  434. if (comp == 0)
  435. return pkt->stream_index < next->stream_index;
  436. return comp > 0;
  437. }
  438. int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
  439. AVPacket *pkt, int flush)
  440. {
  441. AVPacketList *pktl;
  442. int stream_count = 0;
  443. int i;
  444. if (pkt) {
  445. ff_interleave_add_packet(s, pkt, interleave_compare_dts);
  446. }
  447. for (i = 0; i < s->nb_streams; i++)
  448. stream_count += !!s->streams[i]->last_in_packet_buffer;
  449. if (stream_count && (s->nb_streams == stream_count || flush)) {
  450. pktl = s->packet_buffer;
  451. *out = pktl->pkt;
  452. s->packet_buffer = pktl->next;
  453. if (!s->packet_buffer)
  454. s->packet_buffer_end = NULL;
  455. if (s->streams[out->stream_index]->last_in_packet_buffer == pktl)
  456. s->streams[out->stream_index]->last_in_packet_buffer = NULL;
  457. av_freep(&pktl);
  458. return 1;
  459. } else {
  460. av_init_packet(out);
  461. return 0;
  462. }
  463. }
  464. /**
  465. * Interleave an AVPacket correctly so it can be muxed.
  466. * @param out the interleaved packet will be output here
  467. * @param in the input packet
  468. * @param flush 1 if no further packets are available as input and all
  469. * remaining packets should be output
  470. * @return 1 if a packet was output, 0 if no packet could be output,
  471. * < 0 if an error occurred
  472. */
  473. static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
  474. {
  475. if (s->oformat->interleave_packet) {
  476. int ret = s->oformat->interleave_packet(s, out, in, flush);
  477. if (in)
  478. av_free_packet(in);
  479. return ret;
  480. } else
  481. return ff_interleave_packet_per_dts(s, out, in, flush);
  482. }
  483. int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
  484. {
  485. int ret, flush = 0;
  486. if (pkt) {
  487. AVStream *st = s->streams[pkt->stream_index];
  488. //FIXME/XXX/HACK drop zero sized packets
  489. if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0)
  490. return 0;
  491. av_dlog(s, "av_interleaved_write_frame size:%d dts:%" PRId64 " pts:%" PRId64 "\n",
  492. pkt->size, pkt->dts, pkt->pts);
  493. if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
  494. return ret;
  495. if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
  496. return AVERROR(EINVAL);
  497. } else {
  498. av_dlog(s, "av_interleaved_write_frame FLUSH\n");
  499. flush = 1;
  500. }
  501. for (;; ) {
  502. AVPacket opkt;
  503. int ret = interleave_packet(s, &opkt, pkt, flush);
  504. if (ret <= 0) //FIXME cleanup needed for ret<0 ?
  505. return ret;
  506. ret = write_packet(s, &opkt);
  507. if (ret >= 0)
  508. s->streams[opkt.stream_index]->nb_frames++;
  509. av_free_packet(&opkt);
  510. pkt = NULL;
  511. if (ret < 0)
  512. return ret;
  513. }
  514. }
  515. int av_write_trailer(AVFormatContext *s)
  516. {
  517. int ret, i;
  518. for (;; ) {
  519. AVPacket pkt;
  520. ret = interleave_packet(s, &pkt, NULL, 1);
  521. if (ret < 0) //FIXME cleanup needed for ret<0 ?
  522. goto fail;
  523. if (!ret)
  524. break;
  525. ret = write_packet(s, &pkt);
  526. if (ret >= 0)
  527. s->streams[pkt.stream_index]->nb_frames++;
  528. av_free_packet(&pkt);
  529. if (ret < 0)
  530. goto fail;
  531. }
  532. if (s->oformat->write_trailer)
  533. ret = s->oformat->write_trailer(s);
  534. if (!(s->oformat->flags & AVFMT_NOFILE))
  535. avio_flush(s->pb);
  536. fail:
  537. for (i = 0; i < s->nb_streams; i++) {
  538. av_freep(&s->streams[i]->priv_data);
  539. av_freep(&s->streams[i]->index_entries);
  540. }
  541. if (s->oformat->priv_class)
  542. av_opt_free(s->priv_data);
  543. av_freep(&s->priv_data);
  544. return ret;
  545. }
  546. int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
  547. AVFormatContext *src)
  548. {
  549. AVPacket local_pkt;
  550. local_pkt = *pkt;
  551. local_pkt.stream_index = dst_stream;
  552. if (pkt->pts != AV_NOPTS_VALUE)
  553. local_pkt.pts = av_rescale_q(pkt->pts,
  554. src->streams[pkt->stream_index]->time_base,
  555. dst->streams[dst_stream]->time_base);
  556. if (pkt->dts != AV_NOPTS_VALUE)
  557. local_pkt.dts = av_rescale_q(pkt->dts,
  558. src->streams[pkt->stream_index]->time_base,
  559. dst->streams[dst_stream]->time_base);
  560. return av_write_frame(dst, &local_pkt);
  561. }