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.

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