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.

1291 lines
41KB

  1. /*
  2. * MPEG1/2 muxer
  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. #include "avformat.h"
  22. #include "allformats.h"
  23. #include "bitstream.h"
  24. #include "fifo.h"
  25. #include "mpeg.h"
  26. #define MAX_PAYLOAD_SIZE 4096
  27. //#define DEBUG_SEEK
  28. #undef NDEBUG
  29. #include <assert.h>
  30. typedef struct PacketDesc {
  31. int64_t pts;
  32. int64_t dts;
  33. int size;
  34. int unwritten_size;
  35. int flags;
  36. struct PacketDesc *next;
  37. } PacketDesc;
  38. typedef struct {
  39. AVFifoBuffer fifo;
  40. uint8_t id;
  41. int max_buffer_size; /* in bytes */
  42. int buffer_index;
  43. PacketDesc *predecode_packet;
  44. PacketDesc *premux_packet;
  45. PacketDesc **next_packet;
  46. int packet_number;
  47. uint8_t lpcm_header[3];
  48. int lpcm_align;
  49. int bytes_to_iframe;
  50. int align_iframe;
  51. int64_t vobu_start_pts;
  52. } StreamInfo;
  53. typedef struct {
  54. int packet_size; /* required packet size */
  55. int packet_number;
  56. int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
  57. int system_header_freq;
  58. int system_header_size;
  59. int mux_rate; /* bitrate in units of 50 bytes/s */
  60. /* stream info */
  61. int audio_bound;
  62. int video_bound;
  63. int is_mpeg2;
  64. int is_vcd;
  65. int is_svcd;
  66. int is_dvd;
  67. int64_t last_scr; /* current system clock */
  68. double vcd_padding_bitrate; //FIXME floats
  69. int64_t vcd_padding_bytes_written;
  70. } MpegMuxContext;
  71. static int put_pack_header(AVFormatContext *ctx,
  72. uint8_t *buf, int64_t timestamp)
  73. {
  74. MpegMuxContext *s = ctx->priv_data;
  75. PutBitContext pb;
  76. init_put_bits(&pb, buf, 128);
  77. put_bits(&pb, 32, PACK_START_CODE);
  78. if (s->is_mpeg2) {
  79. put_bits(&pb, 2, 0x1);
  80. } else {
  81. put_bits(&pb, 4, 0x2);
  82. }
  83. put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07));
  84. put_bits(&pb, 1, 1);
  85. put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff));
  86. put_bits(&pb, 1, 1);
  87. put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff));
  88. put_bits(&pb, 1, 1);
  89. if (s->is_mpeg2) {
  90. /* clock extension */
  91. put_bits(&pb, 9, 0);
  92. }
  93. put_bits(&pb, 1, 1);
  94. put_bits(&pb, 22, s->mux_rate);
  95. put_bits(&pb, 1, 1);
  96. if (s->is_mpeg2) {
  97. put_bits(&pb, 1, 1);
  98. put_bits(&pb, 5, 0x1f); /* reserved */
  99. put_bits(&pb, 3, 0); /* stuffing length */
  100. }
  101. flush_put_bits(&pb);
  102. return pbBufPtr(&pb) - pb.buf;
  103. }
  104. static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_stream_id)
  105. {
  106. MpegMuxContext *s = ctx->priv_data;
  107. int size, i, private_stream_coded, id;
  108. PutBitContext pb;
  109. init_put_bits(&pb, buf, 128);
  110. put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
  111. put_bits(&pb, 16, 0);
  112. put_bits(&pb, 1, 1);
  113. put_bits(&pb, 22, s->mux_rate); /* maximum bit rate of the multiplexed stream */
  114. put_bits(&pb, 1, 1); /* marker */
  115. if (s->is_vcd && only_for_stream_id==VIDEO_ID) {
  116. /* This header applies only to the video stream (see VCD standard p. IV-7)*/
  117. put_bits(&pb, 6, 0);
  118. } else
  119. put_bits(&pb, 6, s->audio_bound);
  120. if (s->is_vcd) {
  121. /* see VCD standard, p. IV-7*/
  122. put_bits(&pb, 1, 0);
  123. put_bits(&pb, 1, 1);
  124. } else {
  125. put_bits(&pb, 1, 0); /* variable bitrate*/
  126. put_bits(&pb, 1, 0); /* non constrainted bit stream */
  127. }
  128. if (s->is_vcd || s->is_dvd) {
  129. /* see VCD standard p IV-7 */
  130. put_bits(&pb, 1, 1); /* audio locked */
  131. put_bits(&pb, 1, 1); /* video locked */
  132. } else {
  133. put_bits(&pb, 1, 0); /* audio locked */
  134. put_bits(&pb, 1, 0); /* video locked */
  135. }
  136. put_bits(&pb, 1, 1); /* marker */
  137. if (s->is_vcd && only_for_stream_id==AUDIO_ID) {
  138. /* This header applies only to the audio stream (see VCD standard p. IV-7)*/
  139. put_bits(&pb, 5, 0);
  140. } else
  141. put_bits(&pb, 5, s->video_bound);
  142. if (s->is_dvd) {
  143. put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */
  144. put_bits(&pb, 7, 0x7f); /* reserved byte */
  145. } else
  146. put_bits(&pb, 8, 0xff); /* reserved byte */
  147. /* DVD-Video Stream_bound entries
  148. id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1)
  149. id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0)
  150. id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1)
  151. id (0xBF) private stream 2, NAV packs, set to 2x1024. */
  152. if (s->is_dvd) {
  153. int P_STD_max_video = 0;
  154. int P_STD_max_mpeg_audio = 0;
  155. int P_STD_max_mpeg_PS1 = 0;
  156. for(i=0;i<ctx->nb_streams;i++) {
  157. StreamInfo *stream = ctx->streams[i]->priv_data;
  158. id = stream->id;
  159. if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) {
  160. P_STD_max_mpeg_PS1 = stream->max_buffer_size;
  161. } else if (id >= 0xc0 && id <= 0xc7 && stream->max_buffer_size > P_STD_max_mpeg_audio) {
  162. P_STD_max_mpeg_audio = stream->max_buffer_size;
  163. } else if (id == 0xe0 && stream->max_buffer_size > P_STD_max_video) {
  164. P_STD_max_video = stream->max_buffer_size;
  165. }
  166. }
  167. /* video */
  168. put_bits(&pb, 8, 0xb9); /* stream ID */
  169. put_bits(&pb, 2, 3);
  170. put_bits(&pb, 1, 1);
  171. put_bits(&pb, 13, P_STD_max_video / 1024);
  172. /* audio */
  173. if (P_STD_max_mpeg_audio == 0)
  174. P_STD_max_mpeg_audio = 4096;
  175. put_bits(&pb, 8, 0xb8); /* stream ID */
  176. put_bits(&pb, 2, 3);
  177. put_bits(&pb, 1, 0);
  178. put_bits(&pb, 13, P_STD_max_mpeg_audio / 128);
  179. /* private stream 1 */
  180. put_bits(&pb, 8, 0xbd); /* stream ID */
  181. put_bits(&pb, 2, 3);
  182. put_bits(&pb, 1, 0);
  183. put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128);
  184. /* private stream 2 */
  185. put_bits(&pb, 8, 0xbf); /* stream ID */
  186. put_bits(&pb, 2, 3);
  187. put_bits(&pb, 1, 1);
  188. put_bits(&pb, 13, 2);
  189. }
  190. else {
  191. /* audio stream info */
  192. private_stream_coded = 0;
  193. for(i=0;i<ctx->nb_streams;i++) {
  194. StreamInfo *stream = ctx->streams[i]->priv_data;
  195. /* For VCDs, only include the stream info for the stream
  196. that the pack which contains this system belongs to.
  197. (see VCD standard p. IV-7) */
  198. if ( !s->is_vcd || stream->id==only_for_stream_id
  199. || only_for_stream_id==0) {
  200. id = stream->id;
  201. if (id < 0xc0) {
  202. /* special case for private streams (AC3 use that) */
  203. if (private_stream_coded)
  204. continue;
  205. private_stream_coded = 1;
  206. id = 0xbd;
  207. }
  208. put_bits(&pb, 8, id); /* stream ID */
  209. put_bits(&pb, 2, 3);
  210. if (id < 0xe0) {
  211. /* audio */
  212. put_bits(&pb, 1, 0);
  213. put_bits(&pb, 13, stream->max_buffer_size / 128);
  214. } else {
  215. /* video */
  216. put_bits(&pb, 1, 1);
  217. put_bits(&pb, 13, stream->max_buffer_size / 1024);
  218. }
  219. }
  220. }
  221. }
  222. flush_put_bits(&pb);
  223. size = pbBufPtr(&pb) - pb.buf;
  224. /* patch packet size */
  225. buf[4] = (size - 6) >> 8;
  226. buf[5] = (size - 6) & 0xff;
  227. return size;
  228. }
  229. static int get_system_header_size(AVFormatContext *ctx)
  230. {
  231. int buf_index, i, private_stream_coded;
  232. StreamInfo *stream;
  233. MpegMuxContext *s = ctx->priv_data;
  234. if (s->is_dvd)
  235. return 18; // DVD-Video system headers are 18 bytes fixed length.
  236. buf_index = 12;
  237. private_stream_coded = 0;
  238. for(i=0;i<ctx->nb_streams;i++) {
  239. stream = ctx->streams[i]->priv_data;
  240. if (stream->id < 0xc0) {
  241. if (private_stream_coded)
  242. continue;
  243. private_stream_coded = 1;
  244. }
  245. buf_index += 3;
  246. }
  247. return buf_index;
  248. }
  249. static int mpeg_mux_init(AVFormatContext *ctx)
  250. {
  251. MpegMuxContext *s = ctx->priv_data;
  252. int bitrate, i, mpa_id, mpv_id, mps_id, ac3_id, dts_id, lpcm_id, j;
  253. AVStream *st;
  254. StreamInfo *stream;
  255. int audio_bitrate;
  256. int video_bitrate;
  257. s->packet_number = 0;
  258. s->is_vcd = (ENABLE_MPEG1VCD_MUXER && ctx->oformat == &mpeg1vcd_muxer);
  259. s->is_svcd = (ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer);
  260. s->is_mpeg2 = (ENABLE_MPEG2VOB_MUXER && ctx->oformat == &mpeg2vob_muxer ||
  261. ENABLE_MPEG2DVD_MUXER && ctx->oformat == &mpeg2dvd_muxer ||
  262. ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer);
  263. s->is_dvd = (ENABLE_MPEG2DVD_MUXER && ctx->oformat == &mpeg2dvd_muxer);
  264. if(ctx->packet_size)
  265. s->packet_size = ctx->packet_size;
  266. else
  267. s->packet_size = 2048;
  268. s->vcd_padding_bytes_written = 0;
  269. s->vcd_padding_bitrate=0;
  270. s->audio_bound = 0;
  271. s->video_bound = 0;
  272. mpa_id = AUDIO_ID;
  273. ac3_id = AC3_ID;
  274. dts_id = DTS_ID;
  275. mpv_id = VIDEO_ID;
  276. mps_id = SUB_ID;
  277. lpcm_id = LPCM_ID;
  278. for(i=0;i<ctx->nb_streams;i++) {
  279. st = ctx->streams[i];
  280. stream = av_mallocz(sizeof(StreamInfo));
  281. if (!stream)
  282. goto fail;
  283. st->priv_data = stream;
  284. av_set_pts_info(st, 64, 1, 90000);
  285. switch(st->codec->codec_type) {
  286. case CODEC_TYPE_AUDIO:
  287. if (st->codec->codec_id == CODEC_ID_AC3) {
  288. stream->id = ac3_id++;
  289. } else if (st->codec->codec_id == CODEC_ID_DTS) {
  290. stream->id = dts_id++;
  291. } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) {
  292. stream->id = lpcm_id++;
  293. for(j = 0; j < 4; j++) {
  294. if (lpcm_freq_tab[j] == st->codec->sample_rate)
  295. break;
  296. }
  297. if (j == 4)
  298. goto fail;
  299. if (st->codec->channels > 8)
  300. return -1;
  301. stream->lpcm_header[0] = 0x0c;
  302. stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4);
  303. stream->lpcm_header[2] = 0x80;
  304. stream->lpcm_align = st->codec->channels * 2;
  305. } else {
  306. stream->id = mpa_id++;
  307. }
  308. /* This value HAS to be used for VCD (see VCD standard, p. IV-7).
  309. Right now it is also used for everything else.*/
  310. stream->max_buffer_size = 4 * 1024;
  311. s->audio_bound++;
  312. break;
  313. case CODEC_TYPE_VIDEO:
  314. stream->id = mpv_id++;
  315. if (st->codec->rc_buffer_size)
  316. stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8;
  317. else
  318. stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default
  319. #if 0
  320. /* see VCD standard, p. IV-7*/
  321. stream->max_buffer_size = 46 * 1024;
  322. else
  323. /* This value HAS to be used for SVCD (see SVCD standard, p. 26 V.2.3.2).
  324. Right now it is also used for everything else.*/
  325. stream->max_buffer_size = 230 * 1024;
  326. #endif
  327. s->video_bound++;
  328. break;
  329. case CODEC_TYPE_SUBTITLE:
  330. stream->id = mps_id++;
  331. stream->max_buffer_size = 16 * 1024;
  332. break;
  333. default:
  334. return -1;
  335. }
  336. av_fifo_init(&stream->fifo, 16);
  337. }
  338. bitrate = 0;
  339. audio_bitrate = 0;
  340. video_bitrate = 0;
  341. for(i=0;i<ctx->nb_streams;i++) {
  342. int codec_rate;
  343. st = ctx->streams[i];
  344. stream = (StreamInfo*) st->priv_data;
  345. if(st->codec->rc_max_rate || stream->id==VIDEO_ID)
  346. codec_rate= st->codec->rc_max_rate;
  347. else
  348. codec_rate= st->codec->bit_rate;
  349. if(!codec_rate)
  350. codec_rate= (1<<21)*8*50/ctx->nb_streams;
  351. bitrate += codec_rate;
  352. if (stream->id==AUDIO_ID)
  353. audio_bitrate += codec_rate;
  354. else if (stream->id==VIDEO_ID)
  355. video_bitrate += codec_rate;
  356. }
  357. if(ctx->mux_rate){
  358. s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50);
  359. } else {
  360. /* we increase slightly the bitrate to take into account the
  361. headers. XXX: compute it exactly */
  362. bitrate += bitrate*5/100;
  363. bitrate += 10000;
  364. s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
  365. }
  366. if (s->is_vcd) {
  367. double overhead_rate;
  368. /* The VCD standard mandates that the mux_rate field is 3528
  369. (see standard p. IV-6).
  370. The value is actually "wrong", i.e. if you calculate
  371. it using the normal formula and the 75 sectors per second transfer
  372. rate you get a different value because the real pack size is 2324,
  373. not 2352. But the standard explicitly specifies that the mux_rate
  374. field in the header must have this value.*/
  375. // s->mux_rate=2352 * 75 / 50; /* = 3528*/
  376. /* The VCD standard states that the muxed stream must be
  377. exactly 75 packs / second (the data rate of a single speed cdrom).
  378. Since the video bitrate (probably 1150000 bits/sec) will be below
  379. the theoretical maximum we have to add some padding packets
  380. to make up for the lower data rate.
  381. (cf. VCD standard p. IV-6 )*/
  382. /* Add the header overhead to the data rate.
  383. 2279 data bytes per audio pack, 2294 data bytes per video pack*/
  384. overhead_rate = ((audio_bitrate / 8.0) / 2279) * (2324 - 2279);
  385. overhead_rate += ((video_bitrate / 8.0) / 2294) * (2324 - 2294);
  386. overhead_rate *= 8;
  387. /* Add padding so that the full bitrate is 2324*75 bytes/sec */
  388. s->vcd_padding_bitrate = 2324 * 75 * 8 - (bitrate + overhead_rate);
  389. }
  390. if (s->is_vcd || s->is_mpeg2)
  391. /* every packet */
  392. s->pack_header_freq = 1;
  393. else
  394. /* every 2 seconds */
  395. s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
  396. /* the above seems to make pack_header_freq zero sometimes */
  397. if (s->pack_header_freq == 0)
  398. s->pack_header_freq = 1;
  399. if (s->is_mpeg2)
  400. /* every 200 packets. Need to look at the spec. */
  401. s->system_header_freq = s->pack_header_freq * 40;
  402. else if (s->is_vcd)
  403. /* the standard mandates that there are only two system headers
  404. in the whole file: one in the first packet of each stream.
  405. (see standard p. IV-7 and IV-8) */
  406. s->system_header_freq = 0x7fffffff;
  407. else
  408. s->system_header_freq = s->pack_header_freq * 5;
  409. for(i=0;i<ctx->nb_streams;i++) {
  410. stream = ctx->streams[i]->priv_data;
  411. stream->packet_number = 0;
  412. }
  413. s->system_header_size = get_system_header_size(ctx);
  414. s->last_scr = 0;
  415. return 0;
  416. fail:
  417. for(i=0;i<ctx->nb_streams;i++) {
  418. av_free(ctx->streams[i]->priv_data);
  419. }
  420. return AVERROR(ENOMEM);
  421. }
  422. static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp)
  423. {
  424. put_byte(pb,
  425. (id << 4) |
  426. (((timestamp >> 30) & 0x07) << 1) |
  427. 1);
  428. put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
  429. put_be16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
  430. }
  431. /* return the number of padding bytes that should be inserted into
  432. the multiplexed stream.*/
  433. static int get_vcd_padding_size(AVFormatContext *ctx, int64_t pts)
  434. {
  435. MpegMuxContext *s = ctx->priv_data;
  436. int pad_bytes = 0;
  437. if (s->vcd_padding_bitrate > 0 && pts!=AV_NOPTS_VALUE)
  438. {
  439. int64_t full_pad_bytes;
  440. full_pad_bytes = (int64_t)((s->vcd_padding_bitrate * (pts / 90000.0)) / 8.0); //FIXME this is wrong
  441. pad_bytes = (int) (full_pad_bytes - s->vcd_padding_bytes_written);
  442. if (pad_bytes<0)
  443. /* might happen if we have already padded to a later timestamp. This
  444. can occur if another stream has already advanced further.*/
  445. pad_bytes=0;
  446. }
  447. return pad_bytes;
  448. }
  449. #if 0 /* unused, remove? */
  450. /* return the exact available payload size for the next packet for
  451. stream 'stream_index'. 'pts' and 'dts' are only used to know if
  452. timestamps are needed in the packet header. */
  453. static int get_packet_payload_size(AVFormatContext *ctx, int stream_index,
  454. int64_t pts, int64_t dts)
  455. {
  456. MpegMuxContext *s = ctx->priv_data;
  457. int buf_index;
  458. StreamInfo *stream;
  459. stream = ctx->streams[stream_index]->priv_data;
  460. buf_index = 0;
  461. if (((s->packet_number % s->pack_header_freq) == 0)) {
  462. /* pack header size */
  463. if (s->is_mpeg2)
  464. buf_index += 14;
  465. else
  466. buf_index += 12;
  467. if (s->is_vcd) {
  468. /* there is exactly one system header for each stream in a VCD MPEG,
  469. One in the very first video packet and one in the very first
  470. audio packet (see VCD standard p. IV-7 and IV-8).*/
  471. if (stream->packet_number==0)
  472. /* The system headers refer only to the stream they occur in,
  473. so they have a constant size.*/
  474. buf_index += 15;
  475. } else {
  476. if ((s->packet_number % s->system_header_freq) == 0)
  477. buf_index += s->system_header_size;
  478. }
  479. }
  480. if ((s->is_vcd && stream->packet_number==0)
  481. || (s->is_svcd && s->packet_number==0))
  482. /* the first pack of each stream contains only the pack header,
  483. the system header and some padding (see VCD standard p. IV-6)
  484. Add the padding size, so that the actual payload becomes 0.*/
  485. buf_index += s->packet_size - buf_index;
  486. else {
  487. /* packet header size */
  488. buf_index += 6;
  489. if (s->is_mpeg2) {
  490. buf_index += 3;
  491. if (stream->packet_number==0)
  492. buf_index += 3; /* PES extension */
  493. buf_index += 1; /* obligatory stuffing byte */
  494. }
  495. if (pts != AV_NOPTS_VALUE) {
  496. if (dts != pts)
  497. buf_index += 5 + 5;
  498. else
  499. buf_index += 5;
  500. } else {
  501. if (!s->is_mpeg2)
  502. buf_index++;
  503. }
  504. if (stream->id < 0xc0) {
  505. /* AC3/LPCM private data header */
  506. buf_index += 4;
  507. if (stream->id >= 0xa0) {
  508. int n;
  509. buf_index += 3;
  510. /* NOTE: we round the payload size to an integer number of
  511. LPCM samples */
  512. n = (s->packet_size - buf_index) % stream->lpcm_align;
  513. if (n)
  514. buf_index += (stream->lpcm_align - n);
  515. }
  516. }
  517. if (s->is_vcd && stream->id == AUDIO_ID)
  518. /* The VCD standard demands that 20 zero bytes follow
  519. each audio packet (see standard p. IV-8).*/
  520. buf_index+=20;
  521. }
  522. return s->packet_size - buf_index;
  523. }
  524. #endif
  525. /* Write an MPEG padding packet header. */
  526. static void put_padding_packet(AVFormatContext *ctx, ByteIOContext *pb,int packet_bytes)
  527. {
  528. MpegMuxContext *s = ctx->priv_data;
  529. int i;
  530. put_be32(pb, PADDING_STREAM);
  531. put_be16(pb, packet_bytes - 6);
  532. if (!s->is_mpeg2) {
  533. put_byte(pb, 0x0f);
  534. packet_bytes -= 7;
  535. } else
  536. packet_bytes -= 6;
  537. for(i=0;i<packet_bytes;i++)
  538. put_byte(pb, 0xff);
  539. }
  540. static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len){
  541. int nb_frames=0;
  542. PacketDesc *pkt_desc= stream->premux_packet;
  543. while(len>0){
  544. if(pkt_desc->size == pkt_desc->unwritten_size)
  545. nb_frames++;
  546. len -= pkt_desc->unwritten_size;
  547. pkt_desc= pkt_desc->next;
  548. }
  549. return nb_frames;
  550. }
  551. /* flush the packet on stream stream_index */
  552. static int flush_packet(AVFormatContext *ctx, int stream_index,
  553. int64_t pts, int64_t dts, int64_t scr, int trailer_size)
  554. {
  555. MpegMuxContext *s = ctx->priv_data;
  556. StreamInfo *stream = ctx->streams[stream_index]->priv_data;
  557. uint8_t *buf_ptr;
  558. int size, payload_size, startcode, id, stuffing_size, i, header_len;
  559. int packet_size;
  560. uint8_t buffer[128];
  561. int zero_trail_bytes = 0;
  562. int pad_packet_bytes = 0;
  563. int pes_flags;
  564. int general_pack = 0; /*"general" pack without data specific to one stream?*/
  565. int nb_frames;
  566. id = stream->id;
  567. #if 0
  568. printf("packet ID=%2x PTS=%0.3f\n",
  569. id, pts / 90000.0);
  570. #endif
  571. buf_ptr = buffer;
  572. if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) {
  573. /* output pack and systems header if needed */
  574. size = put_pack_header(ctx, buf_ptr, scr);
  575. buf_ptr += size;
  576. s->last_scr= scr;
  577. if (s->is_vcd) {
  578. /* there is exactly one system header for each stream in a VCD MPEG,
  579. One in the very first video packet and one in the very first
  580. audio packet (see VCD standard p. IV-7 and IV-8).*/
  581. if (stream->packet_number==0) {
  582. size = put_system_header(ctx, buf_ptr, id);
  583. buf_ptr += size;
  584. }
  585. } else if (s->is_dvd) {
  586. if (stream->align_iframe || s->packet_number == 0){
  587. int PES_bytes_to_fill = s->packet_size - size - 10;
  588. if (pts != AV_NOPTS_VALUE) {
  589. if (dts != pts)
  590. PES_bytes_to_fill -= 5 + 5;
  591. else
  592. PES_bytes_to_fill -= 5;
  593. }
  594. if (stream->bytes_to_iframe == 0 || s->packet_number == 0) {
  595. size = put_system_header(ctx, buf_ptr, 0);
  596. buf_ptr += size;
  597. size = buf_ptr - buffer;
  598. put_buffer(&ctx->pb, buffer, size);
  599. put_be32(&ctx->pb, PRIVATE_STREAM_2);
  600. put_be16(&ctx->pb, 0x03d4); // length
  601. put_byte(&ctx->pb, 0x00); // substream ID, 00=PCI
  602. for (i = 0; i < 979; i++)
  603. put_byte(&ctx->pb, 0x00);
  604. put_be32(&ctx->pb, PRIVATE_STREAM_2);
  605. put_be16(&ctx->pb, 0x03fa); // length
  606. put_byte(&ctx->pb, 0x01); // substream ID, 01=DSI
  607. for (i = 0; i < 1017; i++)
  608. put_byte(&ctx->pb, 0x00);
  609. memset(buffer, 0, 128);
  610. buf_ptr = buffer;
  611. s->packet_number++;
  612. stream->align_iframe = 0;
  613. scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
  614. size = put_pack_header(ctx, buf_ptr, scr);
  615. s->last_scr= scr;
  616. buf_ptr += size;
  617. /* GOP Start */
  618. } else if (stream->bytes_to_iframe < PES_bytes_to_fill) {
  619. pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe;
  620. }
  621. }
  622. } else {
  623. if ((s->packet_number % s->system_header_freq) == 0) {
  624. size = put_system_header(ctx, buf_ptr, 0);
  625. buf_ptr += size;
  626. }
  627. }
  628. }
  629. size = buf_ptr - buffer;
  630. put_buffer(&ctx->pb, buffer, size);
  631. packet_size = s->packet_size - size;
  632. if (s->is_vcd && id == AUDIO_ID)
  633. /* The VCD standard demands that 20 zero bytes follow
  634. each audio pack (see standard p. IV-8).*/
  635. zero_trail_bytes += 20;
  636. if ((s->is_vcd && stream->packet_number==0)
  637. || (s->is_svcd && s->packet_number==0)) {
  638. /* for VCD the first pack of each stream contains only the pack header,
  639. the system header and lots of padding (see VCD standard p. IV-6).
  640. In the case of an audio pack, 20 zero bytes are also added at
  641. the end.*/
  642. /* For SVCD we fill the very first pack to increase compatibility with
  643. some DVD players. Not mandated by the standard.*/
  644. if (s->is_svcd)
  645. general_pack = 1; /* the system header refers to both streams and no stream data*/
  646. pad_packet_bytes = packet_size - zero_trail_bytes;
  647. }
  648. packet_size -= pad_packet_bytes + zero_trail_bytes;
  649. if (packet_size > 0) {
  650. /* packet header size */
  651. packet_size -= 6;
  652. /* packet header */
  653. if (s->is_mpeg2) {
  654. header_len = 3;
  655. if (stream->packet_number==0)
  656. header_len += 3; /* PES extension */
  657. header_len += 1; /* obligatory stuffing byte */
  658. } else {
  659. header_len = 0;
  660. }
  661. if (pts != AV_NOPTS_VALUE) {
  662. if (dts != pts)
  663. header_len += 5 + 5;
  664. else
  665. header_len += 5;
  666. } else {
  667. if (!s->is_mpeg2)
  668. header_len++;
  669. }
  670. payload_size = packet_size - header_len;
  671. if (id < 0xc0) {
  672. startcode = PRIVATE_STREAM_1;
  673. payload_size -= 1;
  674. if (id >= 0x40) {
  675. payload_size -= 3;
  676. if (id >= 0xa0)
  677. payload_size -= 3;
  678. }
  679. } else {
  680. startcode = 0x100 + id;
  681. }
  682. stuffing_size = payload_size - av_fifo_size(&stream->fifo);
  683. // first byte does not fit -> reset pts/dts + stuffing
  684. if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){
  685. int timestamp_len=0;
  686. if(dts != pts)
  687. timestamp_len += 5;
  688. if(pts != AV_NOPTS_VALUE)
  689. timestamp_len += s->is_mpeg2 ? 5 : 4;
  690. pts=dts= AV_NOPTS_VALUE;
  691. header_len -= timestamp_len;
  692. if (s->is_dvd && stream->align_iframe) {
  693. pad_packet_bytes += timestamp_len;
  694. packet_size -= timestamp_len;
  695. } else {
  696. payload_size += timestamp_len;
  697. }
  698. stuffing_size += timestamp_len;
  699. if(payload_size > trailer_size)
  700. stuffing_size += payload_size - trailer_size;
  701. }
  702. if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) { // can't use padding, so use stuffing
  703. packet_size += pad_packet_bytes;
  704. payload_size += pad_packet_bytes; // undo the previous adjustment
  705. if (stuffing_size < 0) {
  706. stuffing_size = pad_packet_bytes;
  707. } else {
  708. stuffing_size += pad_packet_bytes;
  709. }
  710. pad_packet_bytes = 0;
  711. }
  712. if (stuffing_size < 0)
  713. stuffing_size = 0;
  714. if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/
  715. pad_packet_bytes += stuffing_size;
  716. packet_size -= stuffing_size;
  717. payload_size -= stuffing_size;
  718. stuffing_size = 0;
  719. }
  720. nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size);
  721. put_be32(&ctx->pb, startcode);
  722. put_be16(&ctx->pb, packet_size);
  723. if (!s->is_mpeg2)
  724. for(i=0;i<stuffing_size;i++)
  725. put_byte(&ctx->pb, 0xff);
  726. if (s->is_mpeg2) {
  727. put_byte(&ctx->pb, 0x80); /* mpeg2 id */
  728. pes_flags=0;
  729. if (pts != AV_NOPTS_VALUE) {
  730. pes_flags |= 0x80;
  731. if (dts != pts)
  732. pes_flags |= 0x40;
  733. }
  734. /* Both the MPEG-2 and the SVCD standards demand that the
  735. P-STD_buffer_size field be included in the first packet of
  736. every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2
  737. and MPEG-2 standard 2.7.7) */
  738. if (stream->packet_number == 0)
  739. pes_flags |= 0x01;
  740. put_byte(&ctx->pb, pes_flags); /* flags */
  741. put_byte(&ctx->pb, header_len - 3 + stuffing_size);
  742. if (pes_flags & 0x80) /*write pts*/
  743. put_timestamp(&ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts);
  744. if (pes_flags & 0x40) /*write dts*/
  745. put_timestamp(&ctx->pb, 0x01, dts);
  746. if (pes_flags & 0x01) { /*write pes extension*/
  747. put_byte(&ctx->pb, 0x10); /* flags */
  748. /* P-STD buffer info */
  749. if (id == AUDIO_ID)
  750. put_be16(&ctx->pb, 0x4000 | stream->max_buffer_size/128);
  751. else
  752. put_be16(&ctx->pb, 0x6000 | stream->max_buffer_size/1024);
  753. }
  754. } else {
  755. if (pts != AV_NOPTS_VALUE) {
  756. if (dts != pts) {
  757. put_timestamp(&ctx->pb, 0x03, pts);
  758. put_timestamp(&ctx->pb, 0x01, dts);
  759. } else {
  760. put_timestamp(&ctx->pb, 0x02, pts);
  761. }
  762. } else {
  763. put_byte(&ctx->pb, 0x0f);
  764. }
  765. }
  766. if (s->is_mpeg2) {
  767. /* special stuffing byte that is always written
  768. to prevent accidental generation of start codes. */
  769. put_byte(&ctx->pb, 0xff);
  770. for(i=0;i<stuffing_size;i++)
  771. put_byte(&ctx->pb, 0xff);
  772. }
  773. if (startcode == PRIVATE_STREAM_1) {
  774. put_byte(&ctx->pb, id);
  775. if (id >= 0xa0) {
  776. /* LPCM (XXX: check nb_frames) */
  777. put_byte(&ctx->pb, 7);
  778. put_be16(&ctx->pb, 4); /* skip 3 header bytes */
  779. put_byte(&ctx->pb, stream->lpcm_header[0]);
  780. put_byte(&ctx->pb, stream->lpcm_header[1]);
  781. put_byte(&ctx->pb, stream->lpcm_header[2]);
  782. } else if (id >= 0x40) {
  783. /* AC3 */
  784. put_byte(&ctx->pb, nb_frames);
  785. put_be16(&ctx->pb, trailer_size+1);
  786. }
  787. }
  788. /* output data */
  789. if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, &ctx->pb) < 0)
  790. return -1;
  791. stream->bytes_to_iframe -= payload_size - stuffing_size;
  792. }else{
  793. payload_size=
  794. stuffing_size= 0;
  795. }
  796. if (pad_packet_bytes > 0)
  797. put_padding_packet(ctx,&ctx->pb, pad_packet_bytes);
  798. for(i=0;i<zero_trail_bytes;i++)
  799. put_byte(&ctx->pb, 0x00);
  800. put_flush_packet(&ctx->pb);
  801. s->packet_number++;
  802. /* only increase the stream packet number if this pack actually contains
  803. something that is specific to this stream! I.e. a dedicated header
  804. or some data.*/
  805. if (!general_pack)
  806. stream->packet_number++;
  807. return payload_size - stuffing_size;
  808. }
  809. static void put_vcd_padding_sector(AVFormatContext *ctx)
  810. {
  811. /* There are two ways to do this padding: writing a sector/pack
  812. of 0 values, or writing an MPEG padding pack. Both seem to
  813. work with most decoders, BUT the VCD standard only allows a 0-sector
  814. (see standard p. IV-4, IV-5).
  815. So a 0-sector it is...*/
  816. MpegMuxContext *s = ctx->priv_data;
  817. int i;
  818. for(i=0;i<s->packet_size;i++)
  819. put_byte(&ctx->pb, 0);
  820. s->vcd_padding_bytes_written += s->packet_size;
  821. put_flush_packet(&ctx->pb);
  822. /* increasing the packet number is correct. The SCR of the following packs
  823. is calculated from the packet_number and it has to include the padding
  824. sector (it represents the sector index, not the MPEG pack index)
  825. (see VCD standard p. IV-6)*/
  826. s->packet_number++;
  827. }
  828. #if 0 /* unused, remove? */
  829. static int64_t get_vcd_scr(AVFormatContext *ctx,int stream_index,int64_t pts)
  830. {
  831. MpegMuxContext *s = ctx->priv_data;
  832. int64_t scr;
  833. /* Since the data delivery rate is constant, SCR is computed
  834. using the formula C + i * 1200 where C is the start constant
  835. and i is the pack index.
  836. It is recommended that SCR 0 is at the beginning of the VCD front
  837. margin (a sequence of empty Form 2 sectors on the CD).
  838. It is recommended that the front margin is 30 sectors long, so
  839. we use C = 30*1200 = 36000
  840. (Note that even if the front margin is not 30 sectors the file
  841. will still be correct according to the standard. It just won't have
  842. the "recommended" value).*/
  843. scr = 36000 + s->packet_number * 1200;
  844. return scr;
  845. }
  846. #endif
  847. static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr){
  848. // MpegMuxContext *s = ctx->priv_data;
  849. int i;
  850. for(i=0; i<ctx->nb_streams; i++){
  851. AVStream *st = ctx->streams[i];
  852. StreamInfo *stream = st->priv_data;
  853. PacketDesc *pkt_desc;
  854. while((pkt_desc= stream->predecode_packet)
  855. && scr > pkt_desc->dts){ //FIXME > vs >=
  856. if(stream->buffer_index < pkt_desc->size ||
  857. stream->predecode_packet == stream->premux_packet){
  858. av_log(ctx, AV_LOG_ERROR,
  859. "buffer underflow i=%d bufi=%d size=%d\n",
  860. i, stream->buffer_index, pkt_desc->size);
  861. break;
  862. }
  863. stream->buffer_index -= pkt_desc->size;
  864. stream->predecode_packet= pkt_desc->next;
  865. av_freep(&pkt_desc);
  866. }
  867. }
  868. return 0;
  869. }
  870. static int output_packet(AVFormatContext *ctx, int flush){
  871. MpegMuxContext *s = ctx->priv_data;
  872. AVStream *st;
  873. StreamInfo *stream;
  874. int i, avail_space, es_size, trailer_size;
  875. int best_i= -1;
  876. int best_score= INT_MIN;
  877. int ignore_constraints=0;
  878. int64_t scr= s->last_scr;
  879. PacketDesc *timestamp_packet;
  880. const int64_t max_delay= av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
  881. retry:
  882. for(i=0; i<ctx->nb_streams; i++){
  883. AVStream *st = ctx->streams[i];
  884. StreamInfo *stream = st->priv_data;
  885. const int avail_data= av_fifo_size(&stream->fifo);
  886. const int space= stream->max_buffer_size - stream->buffer_index;
  887. int rel_space= 1024*space / stream->max_buffer_size;
  888. PacketDesc *next_pkt= stream->premux_packet;
  889. /* for subtitle, a single PES packet must be generated,
  890. so we flush after every single subtitle packet */
  891. if(s->packet_size > avail_data && !flush
  892. && st->codec->codec_type != CODEC_TYPE_SUBTITLE)
  893. return 0;
  894. if(avail_data==0)
  895. continue;
  896. assert(avail_data>0);
  897. if(space < s->packet_size && !ignore_constraints)
  898. continue;
  899. if(next_pkt && next_pkt->dts - scr > max_delay)
  900. continue;
  901. if(rel_space > best_score){
  902. best_score= rel_space;
  903. best_i = i;
  904. avail_space= space;
  905. }
  906. }
  907. if(best_i < 0){
  908. int64_t best_dts= INT64_MAX;
  909. for(i=0; i<ctx->nb_streams; i++){
  910. AVStream *st = ctx->streams[i];
  911. StreamInfo *stream = st->priv_data;
  912. PacketDesc *pkt_desc= stream->predecode_packet;
  913. if(pkt_desc && pkt_desc->dts < best_dts)
  914. best_dts= pkt_desc->dts;
  915. }
  916. #if 0
  917. av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n",
  918. scr/90000.0, best_dts/90000.0);
  919. #endif
  920. if(best_dts == INT64_MAX)
  921. return 0;
  922. if(scr >= best_dts+1 && !ignore_constraints){
  923. av_log(ctx, AV_LOG_ERROR, "packet too large, ignoring buffer limits to mux it\n");
  924. ignore_constraints= 1;
  925. }
  926. scr= FFMAX(best_dts+1, scr);
  927. if(remove_decoded_packets(ctx, scr) < 0)
  928. return -1;
  929. goto retry;
  930. }
  931. assert(best_i >= 0);
  932. st = ctx->streams[best_i];
  933. stream = st->priv_data;
  934. assert(av_fifo_size(&stream->fifo) > 0);
  935. assert(avail_space >= s->packet_size || ignore_constraints);
  936. timestamp_packet= stream->premux_packet;
  937. if(timestamp_packet->unwritten_size == timestamp_packet->size){
  938. trailer_size= 0;
  939. }else{
  940. trailer_size= timestamp_packet->unwritten_size;
  941. timestamp_packet= timestamp_packet->next;
  942. }
  943. if(timestamp_packet){
  944. //av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i);
  945. es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size);
  946. }else{
  947. assert(av_fifo_size(&stream->fifo) == trailer_size);
  948. es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size);
  949. }
  950. if (s->is_vcd) {
  951. /* Write one or more padding sectors, if necessary, to reach
  952. the constant overall bitrate.*/
  953. int vcd_pad_bytes;
  954. while((vcd_pad_bytes = get_vcd_padding_size(ctx,stream->premux_packet->pts) ) >= s->packet_size){ //FIXME pts cannot be correct here
  955. put_vcd_padding_sector(ctx);
  956. s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
  957. }
  958. }
  959. stream->buffer_index += es_size;
  960. s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet
  961. while(stream->premux_packet && stream->premux_packet->unwritten_size <= es_size){
  962. es_size -= stream->premux_packet->unwritten_size;
  963. stream->premux_packet= stream->premux_packet->next;
  964. }
  965. if(es_size)
  966. stream->premux_packet->unwritten_size -= es_size;
  967. if(remove_decoded_packets(ctx, s->last_scr) < 0)
  968. return -1;
  969. return 1;
  970. }
  971. static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
  972. {
  973. MpegMuxContext *s = ctx->priv_data;
  974. int stream_index= pkt->stream_index;
  975. int size= pkt->size;
  976. uint8_t *buf= pkt->data;
  977. AVStream *st = ctx->streams[stream_index];
  978. StreamInfo *stream = st->priv_data;
  979. int64_t pts, dts;
  980. PacketDesc *pkt_desc;
  981. const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE);
  982. const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY);
  983. pts= pkt->pts;
  984. dts= pkt->dts;
  985. if(pts != AV_NOPTS_VALUE) pts += preload;
  986. if(dts != AV_NOPTS_VALUE) dts += preload;
  987. //av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE);
  988. if (!stream->premux_packet)
  989. stream->next_packet = &stream->premux_packet;
  990. *stream->next_packet=
  991. pkt_desc= av_mallocz(sizeof(PacketDesc));
  992. pkt_desc->pts= pts;
  993. pkt_desc->dts= dts;
  994. pkt_desc->unwritten_size=
  995. pkt_desc->size= size;
  996. if(!stream->predecode_packet)
  997. stream->predecode_packet= pkt_desc;
  998. stream->next_packet= &pkt_desc->next;
  999. av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1);
  1000. if (s->is_dvd){
  1001. if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
  1002. stream->bytes_to_iframe = av_fifo_size(&stream->fifo);
  1003. stream->align_iframe = 1;
  1004. stream->vobu_start_pts = pts;
  1005. }
  1006. }
  1007. av_fifo_write(&stream->fifo, buf, size);
  1008. for(;;){
  1009. int ret= output_packet(ctx, 0);
  1010. if(ret<=0)
  1011. return ret;
  1012. }
  1013. }
  1014. static int mpeg_mux_end(AVFormatContext *ctx)
  1015. {
  1016. // MpegMuxContext *s = ctx->priv_data;
  1017. StreamInfo *stream;
  1018. int i;
  1019. for(;;){
  1020. int ret= output_packet(ctx, 1);
  1021. if(ret<0)
  1022. return ret;
  1023. else if(ret==0)
  1024. break;
  1025. }
  1026. /* End header according to MPEG1 systems standard. We do not write
  1027. it as it is usually not needed by decoders and because it
  1028. complicates MPEG stream concatenation. */
  1029. //put_be32(&ctx->pb, ISO_11172_END_CODE);
  1030. //put_flush_packet(&ctx->pb);
  1031. for(i=0;i<ctx->nb_streams;i++) {
  1032. stream = ctx->streams[i]->priv_data;
  1033. assert(av_fifo_size(&stream->fifo) == 0);
  1034. av_fifo_free(&stream->fifo);
  1035. }
  1036. return 0;
  1037. }
  1038. #ifdef CONFIG_MPEG1SYSTEM_MUXER
  1039. AVOutputFormat mpeg1system_muxer = {
  1040. "mpeg",
  1041. "MPEG1 System format",
  1042. "video/mpeg",
  1043. "mpg,mpeg",
  1044. sizeof(MpegMuxContext),
  1045. CODEC_ID_MP2,
  1046. CODEC_ID_MPEG1VIDEO,
  1047. mpeg_mux_init,
  1048. mpeg_mux_write_packet,
  1049. mpeg_mux_end,
  1050. };
  1051. #endif
  1052. #ifdef CONFIG_MPEG1VCD_MUXER
  1053. AVOutputFormat mpeg1vcd_muxer = {
  1054. "vcd",
  1055. "MPEG1 System format (VCD)",
  1056. "video/mpeg",
  1057. NULL,
  1058. sizeof(MpegMuxContext),
  1059. CODEC_ID_MP2,
  1060. CODEC_ID_MPEG1VIDEO,
  1061. mpeg_mux_init,
  1062. mpeg_mux_write_packet,
  1063. mpeg_mux_end,
  1064. };
  1065. #endif
  1066. #ifdef CONFIG_MPEG2VOB_MUXER
  1067. AVOutputFormat mpeg2vob_muxer = {
  1068. "vob",
  1069. "MPEG2 PS format (VOB)",
  1070. "video/mpeg",
  1071. "vob",
  1072. sizeof(MpegMuxContext),
  1073. CODEC_ID_MP2,
  1074. CODEC_ID_MPEG2VIDEO,
  1075. mpeg_mux_init,
  1076. mpeg_mux_write_packet,
  1077. mpeg_mux_end,
  1078. };
  1079. #endif
  1080. /* Same as mpeg2vob_mux except that the pack size is 2324 */
  1081. #ifdef CONFIG_MPEG2SVCD_MUXER
  1082. AVOutputFormat mpeg2svcd_muxer = {
  1083. "svcd",
  1084. "MPEG2 PS format (VOB)",
  1085. "video/mpeg",
  1086. "vob",
  1087. sizeof(MpegMuxContext),
  1088. CODEC_ID_MP2,
  1089. CODEC_ID_MPEG2VIDEO,
  1090. mpeg_mux_init,
  1091. mpeg_mux_write_packet,
  1092. mpeg_mux_end,
  1093. };
  1094. #endif
  1095. /* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
  1096. #ifdef CONFIG_MPEG2DVD_MUXER
  1097. AVOutputFormat mpeg2dvd_muxer = {
  1098. "dvd",
  1099. "MPEG2 PS format (DVD VOB)",
  1100. "video/mpeg",
  1101. "dvd",
  1102. sizeof(MpegMuxContext),
  1103. CODEC_ID_MP2,
  1104. CODEC_ID_MPEG2VIDEO,
  1105. mpeg_mux_init,
  1106. mpeg_mux_write_packet,
  1107. mpeg_mux_end,
  1108. };
  1109. #endif