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.

703 lines
19KB

  1. /*
  2. * MPEG1/2 mux/demux
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. #include "tick.h"
  21. #define MAX_PAYLOAD_SIZE 4096
  22. #define NB_STREAMS 2
  23. typedef struct {
  24. UINT8 buffer[MAX_PAYLOAD_SIZE];
  25. int buffer_ptr;
  26. UINT8 id;
  27. int max_buffer_size; /* in bytes */
  28. int packet_number;
  29. INT64 pts;
  30. Ticker pts_ticker;
  31. INT64 start_pts;
  32. } StreamInfo;
  33. typedef struct {
  34. int packet_size; /* required packet size */
  35. int packet_data_max_size; /* maximum data size inside a packet */
  36. int packet_number;
  37. int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
  38. int system_header_freq;
  39. int mux_rate; /* bitrate in units of 50 bytes/s */
  40. /* stream info */
  41. int audio_bound;
  42. int video_bound;
  43. int is_mpeg2;
  44. int is_vcd;
  45. } MpegMuxContext;
  46. #define PACK_START_CODE ((unsigned int)0x000001ba)
  47. #define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb)
  48. #define SEQUENCE_END_CODE ((unsigned int)0x000001b7)
  49. #define PACKET_START_CODE_MASK ((unsigned int)0xffffff00)
  50. #define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100)
  51. #define ISO_11172_END_CODE ((unsigned int)0x000001b9)
  52. /* mpeg2 */
  53. #define PROGRAM_STREAM_MAP 0x1bc
  54. #define PRIVATE_STREAM_1 0x1bd
  55. #define PADDING_STREAM 0x1be
  56. #define PRIVATE_STREAM_2 0x1bf
  57. #define AUDIO_ID 0xc0
  58. #define VIDEO_ID 0xe0
  59. extern AVOutputFormat mpeg1system_mux;
  60. extern AVOutputFormat mpeg1vcd_mux;
  61. extern AVOutputFormat mpeg2vob_mux;
  62. static int put_pack_header(AVFormatContext *ctx,
  63. UINT8 *buf, INT64 timestamp)
  64. {
  65. MpegMuxContext *s = ctx->priv_data;
  66. PutBitContext pb;
  67. init_put_bits(&pb, buf, 128, NULL, NULL);
  68. put_bits(&pb, 32, PACK_START_CODE);
  69. put_bits(&pb, 4, 0x2);
  70. put_bits(&pb, 3, (UINT32)((timestamp >> 30) & 0x07));
  71. put_bits(&pb, 1, 1);
  72. put_bits(&pb, 15, (UINT32)((timestamp >> 15) & 0x7fff));
  73. put_bits(&pb, 1, 1);
  74. put_bits(&pb, 15, (UINT32)((timestamp) & 0x7fff));
  75. put_bits(&pb, 1, 1);
  76. put_bits(&pb, 1, 1);
  77. put_bits(&pb, 22, s->mux_rate);
  78. put_bits(&pb, 1, 1);
  79. flush_put_bits(&pb);
  80. return pbBufPtr(&pb) - pb.buf;
  81. }
  82. static int put_system_header(AVFormatContext *ctx, UINT8 *buf)
  83. {
  84. MpegMuxContext *s = ctx->priv_data;
  85. int size, rate_bound, i, private_stream_coded, id;
  86. PutBitContext pb;
  87. init_put_bits(&pb, buf, 128, NULL, NULL);
  88. put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
  89. put_bits(&pb, 16, 0);
  90. put_bits(&pb, 1, 1);
  91. rate_bound = s->mux_rate; /* maximum bit rate of the multiplexed stream */
  92. put_bits(&pb, 22, rate_bound);
  93. put_bits(&pb, 1, 1); /* marker */
  94. put_bits(&pb, 6, s->audio_bound);
  95. put_bits(&pb, 1, 1); /* variable bitrate */
  96. put_bits(&pb, 1, 1); /* non constrainted bit stream */
  97. put_bits(&pb, 1, 0); /* audio locked */
  98. put_bits(&pb, 1, 0); /* video locked */
  99. put_bits(&pb, 1, 1); /* marker */
  100. put_bits(&pb, 5, s->video_bound);
  101. put_bits(&pb, 8, 0xff); /* reserved byte */
  102. /* audio stream info */
  103. private_stream_coded = 0;
  104. for(i=0;i<ctx->nb_streams;i++) {
  105. StreamInfo *stream = ctx->streams[i]->priv_data;
  106. id = stream->id;
  107. if (id < 0xc0) {
  108. /* special case for private streams (AC3 use that) */
  109. if (private_stream_coded)
  110. continue;
  111. private_stream_coded = 1;
  112. id = 0xbd;
  113. }
  114. put_bits(&pb, 8, id); /* stream ID */
  115. put_bits(&pb, 2, 3);
  116. if (id < 0xe0) {
  117. /* audio */
  118. put_bits(&pb, 1, 0);
  119. put_bits(&pb, 13, stream->max_buffer_size / 128);
  120. } else {
  121. /* video */
  122. put_bits(&pb, 1, 1);
  123. put_bits(&pb, 13, stream->max_buffer_size / 1024);
  124. }
  125. }
  126. flush_put_bits(&pb);
  127. size = pbBufPtr(&pb) - pb.buf;
  128. /* patch packet size */
  129. buf[4] = (size - 6) >> 8;
  130. buf[5] = (size - 6) & 0xff;
  131. return size;
  132. }
  133. static int mpeg_mux_init(AVFormatContext *ctx)
  134. {
  135. MpegMuxContext *s = ctx->priv_data;
  136. int bitrate, i, mpa_id, mpv_id, ac3_id;
  137. AVStream *st;
  138. StreamInfo *stream;
  139. s->packet_number = 0;
  140. s->is_vcd = (ctx->oformat == &mpeg1vcd_mux);
  141. s->is_mpeg2 = (ctx->oformat == &mpeg2vob_mux);
  142. if (s->is_vcd)
  143. s->packet_size = 2324; /* VCD packet size */
  144. else
  145. s->packet_size = 2048;
  146. /* startcode(4) + length(2) + flags(1) */
  147. s->packet_data_max_size = s->packet_size - 7;
  148. s->audio_bound = 0;
  149. s->video_bound = 0;
  150. mpa_id = AUDIO_ID;
  151. ac3_id = 0x80;
  152. mpv_id = VIDEO_ID;
  153. for(i=0;i<ctx->nb_streams;i++) {
  154. st = ctx->streams[i];
  155. stream = av_mallocz(sizeof(StreamInfo));
  156. if (!stream)
  157. goto fail;
  158. st->priv_data = stream;
  159. switch(st->codec.codec_type) {
  160. case CODEC_TYPE_AUDIO:
  161. if (st->codec.codec_id == CODEC_ID_AC3)
  162. stream->id = ac3_id++;
  163. else
  164. stream->id = mpa_id++;
  165. stream->max_buffer_size = 4 * 1024;
  166. s->audio_bound++;
  167. break;
  168. case CODEC_TYPE_VIDEO:
  169. stream->id = mpv_id++;
  170. stream->max_buffer_size = 46 * 1024;
  171. s->video_bound++;
  172. break;
  173. default:
  174. av_abort();
  175. }
  176. }
  177. /* we increase slightly the bitrate to take into account the
  178. headers. XXX: compute it exactly */
  179. bitrate = 2000;
  180. for(i=0;i<ctx->nb_streams;i++) {
  181. st = ctx->streams[i];
  182. bitrate += st->codec.bit_rate;
  183. }
  184. s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
  185. if (s->is_vcd || s->is_mpeg2)
  186. /* every packet */
  187. s->pack_header_freq = 1;
  188. else
  189. /* every 2 seconds */
  190. s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
  191. if (s->is_vcd)
  192. /* every 40 packets, this is my invention */
  193. s->system_header_freq = s->pack_header_freq * 40;
  194. else
  195. /* every 10 seconds */
  196. s->system_header_freq = s->pack_header_freq * 5;
  197. for(i=0;i<ctx->nb_streams;i++) {
  198. stream = ctx->streams[i]->priv_data;
  199. stream->buffer_ptr = 0;
  200. stream->packet_number = 0;
  201. stream->pts = 0;
  202. stream->start_pts = -1;
  203. st = ctx->streams[i];
  204. switch (st->codec.codec_type) {
  205. case CODEC_TYPE_AUDIO:
  206. ticker_init(&stream->pts_ticker,
  207. st->codec.sample_rate,
  208. 90000 * st->codec.frame_size);
  209. break;
  210. case CODEC_TYPE_VIDEO:
  211. ticker_init(&stream->pts_ticker,
  212. st->codec.frame_rate,
  213. 90000 * FRAME_RATE_BASE);
  214. break;
  215. default:
  216. av_abort();
  217. }
  218. }
  219. return 0;
  220. fail:
  221. for(i=0;i<ctx->nb_streams;i++) {
  222. av_free(ctx->streams[i]->priv_data);
  223. }
  224. return -ENOMEM;
  225. }
  226. /* flush the packet on stream stream_index */
  227. static void flush_packet(AVFormatContext *ctx, int stream_index, int last_pkt)
  228. {
  229. MpegMuxContext *s = ctx->priv_data;
  230. StreamInfo *stream = ctx->streams[stream_index]->priv_data;
  231. UINT8 *buf_ptr;
  232. int size, payload_size, startcode, id, len, stuffing_size, i, header_len;
  233. INT64 timestamp;
  234. UINT8 buffer[128];
  235. int last = last_pkt ? 4 : 0;
  236. id = stream->id;
  237. timestamp = stream->start_pts;
  238. #if 0
  239. printf("packet ID=%2x PTS=%0.3f\n",
  240. id, timestamp / 90000.0);
  241. #endif
  242. buf_ptr = buffer;
  243. if (((s->packet_number % s->pack_header_freq) == 0)) {
  244. /* output pack and systems header if needed */
  245. size = put_pack_header(ctx, buf_ptr, timestamp);
  246. buf_ptr += size;
  247. if ((s->packet_number % s->system_header_freq) == 0) {
  248. size = put_system_header(ctx, buf_ptr);
  249. buf_ptr += size;
  250. }
  251. }
  252. size = buf_ptr - buffer;
  253. put_buffer(&ctx->pb, buffer, size);
  254. /* packet header */
  255. if (s->is_mpeg2) {
  256. header_len = 8;
  257. } else {
  258. header_len = 5;
  259. }
  260. payload_size = s->packet_size - (size + 6 + header_len + last);
  261. if (id < 0xc0) {
  262. startcode = PRIVATE_STREAM_1;
  263. payload_size -= 4;
  264. } else {
  265. startcode = 0x100 + id;
  266. }
  267. stuffing_size = payload_size - stream->buffer_ptr;
  268. if (stuffing_size < 0)
  269. stuffing_size = 0;
  270. put_be32(&ctx->pb, startcode);
  271. put_be16(&ctx->pb, payload_size + header_len);
  272. /* stuffing */
  273. for(i=0;i<stuffing_size;i++)
  274. put_byte(&ctx->pb, 0xff);
  275. if (s->is_mpeg2) {
  276. put_byte(&ctx->pb, 0x80); /* mpeg2 id */
  277. put_byte(&ctx->pb, 0x80); /* flags */
  278. put_byte(&ctx->pb, 0x05); /* header len (only pts is included) */
  279. }
  280. put_byte(&ctx->pb,
  281. (0x02 << 4) |
  282. (((timestamp >> 30) & 0x07) << 1) |
  283. 1);
  284. put_be16(&ctx->pb, (UINT16)((((timestamp >> 15) & 0x7fff) << 1) | 1));
  285. put_be16(&ctx->pb, (UINT16)((((timestamp) & 0x7fff) << 1) | 1));
  286. if (startcode == PRIVATE_STREAM_1) {
  287. put_byte(&ctx->pb, id);
  288. if (id >= 0x80 && id <= 0xbf) {
  289. /* XXX: need to check AC3 spec */
  290. put_byte(&ctx->pb, 1);
  291. put_byte(&ctx->pb, 0);
  292. put_byte(&ctx->pb, 2);
  293. }
  294. }
  295. if (last_pkt) {
  296. put_be32(&ctx->pb, ISO_11172_END_CODE);
  297. }
  298. /* output data */
  299. put_buffer(&ctx->pb, stream->buffer, payload_size - stuffing_size);
  300. put_flush_packet(&ctx->pb);
  301. /* preserve remaining data */
  302. len = stream->buffer_ptr - payload_size;
  303. if (len < 0)
  304. len = 0;
  305. memmove(stream->buffer, stream->buffer + stream->buffer_ptr - len, len);
  306. stream->buffer_ptr = len;
  307. s->packet_number++;
  308. stream->packet_number++;
  309. stream->start_pts = -1;
  310. }
  311. static int mpeg_mux_write_packet(AVFormatContext *ctx, int stream_index,
  312. UINT8 *buf, int size, int force_pts)
  313. {
  314. MpegMuxContext *s = ctx->priv_data;
  315. AVStream *st = ctx->streams[stream_index];
  316. StreamInfo *stream = st->priv_data;
  317. int len;
  318. while (size > 0) {
  319. /* set pts */
  320. if (stream->start_pts == -1) {
  321. if (force_pts)
  322. stream->pts = force_pts;
  323. stream->start_pts = stream->pts;
  324. }
  325. len = s->packet_data_max_size - stream->buffer_ptr;
  326. if (len > size)
  327. len = size;
  328. memcpy(stream->buffer + stream->buffer_ptr, buf, len);
  329. stream->buffer_ptr += len;
  330. buf += len;
  331. size -= len;
  332. while (stream->buffer_ptr >= s->packet_data_max_size) {
  333. /* output the packet */
  334. if (stream->start_pts == -1)
  335. stream->start_pts = stream->pts;
  336. flush_packet(ctx, stream_index, 0);
  337. }
  338. }
  339. stream->pts += ticker_tick(&stream->pts_ticker, 1);
  340. //if (st->codec.codec_type == CODEC_TYPE_VIDEO)
  341. // fprintf(stderr,"\nVideo PTS: %6lld", stream->pts);
  342. //else
  343. // fprintf(stderr,"\nAudio PTS: %6lld", stream->pts);
  344. return 0;
  345. }
  346. static int mpeg_mux_end(AVFormatContext *ctx)
  347. {
  348. StreamInfo *stream;
  349. int i;
  350. /* flush each packet */
  351. for(i=0;i<ctx->nb_streams;i++) {
  352. stream = ctx->streams[i]->priv_data;
  353. if (stream->buffer_ptr > 0) {
  354. if (i == (ctx->nb_streams - 1))
  355. flush_packet(ctx, i, 1);
  356. else
  357. flush_packet(ctx, i, 0);
  358. }
  359. }
  360. /* write the end header */
  361. //put_be32(&ctx->pb, ISO_11172_END_CODE);
  362. //put_flush_packet(&ctx->pb);
  363. return 0;
  364. }
  365. /*********************************************/
  366. /* demux code */
  367. #define MAX_SYNC_SIZE 100000
  368. static int mpegps_probe(AVProbeData *p)
  369. {
  370. int code, c, i;
  371. code = 0xff;
  372. /* we search the first start code. If it is a packet start code,
  373. then we decide it is mpeg ps. We do not send highest value to
  374. give a chance to mpegts */
  375. for(i=0;i<p->buf_size;i++) {
  376. c = p->buf[i];
  377. code = (code << 8) | c;
  378. if ((code & 0xffffff00) == 0x100) {
  379. if (code == PACK_START_CODE ||
  380. code == SYSTEM_HEADER_START_CODE ||
  381. (code >= 0x1e0 && code <= 0x1ef) ||
  382. (code >= 0x1c0 && code <= 0x1df) ||
  383. code == PRIVATE_STREAM_2 ||
  384. code == PROGRAM_STREAM_MAP ||
  385. code == PRIVATE_STREAM_1 ||
  386. code == PADDING_STREAM)
  387. return AVPROBE_SCORE_MAX - 1;
  388. else
  389. return 0;
  390. }
  391. }
  392. return 0;
  393. }
  394. typedef struct MpegDemuxContext {
  395. int header_state;
  396. } MpegDemuxContext;
  397. static int find_start_code(ByteIOContext *pb, int *size_ptr,
  398. UINT32 *header_state)
  399. {
  400. unsigned int state, v;
  401. int val, n;
  402. state = *header_state;
  403. n = *size_ptr;
  404. while (n > 0) {
  405. if (url_feof(pb))
  406. break;
  407. v = get_byte(pb);
  408. n--;
  409. if (state == 0x000001) {
  410. state = ((state << 8) | v) & 0xffffff;
  411. val = state;
  412. goto found;
  413. }
  414. state = ((state << 8) | v) & 0xffffff;
  415. }
  416. val = -1;
  417. found:
  418. *header_state = state;
  419. *size_ptr = n;
  420. return val;
  421. }
  422. static int mpegps_read_header(AVFormatContext *s,
  423. AVFormatParameters *ap)
  424. {
  425. MpegDemuxContext *m = s->priv_data;
  426. m->header_state = 0xff;
  427. /* no need to do more */
  428. return 0;
  429. }
  430. static INT64 get_pts(ByteIOContext *pb, int c)
  431. {
  432. INT64 pts;
  433. int val;
  434. if (c < 0)
  435. c = get_byte(pb);
  436. pts = (INT64)((c >> 1) & 0x07) << 30;
  437. val = get_be16(pb);
  438. pts |= (INT64)(val >> 1) << 15;
  439. val = get_be16(pb);
  440. pts |= (INT64)(val >> 1);
  441. return pts;
  442. }
  443. static int mpegps_read_packet(AVFormatContext *s,
  444. AVPacket *pkt)
  445. {
  446. MpegDemuxContext *m = s->priv_data;
  447. AVStream *st;
  448. int len, size, startcode, i, c, flags, header_len, type, codec_id;
  449. INT64 pts, dts;
  450. /* next start code (should be immediately after */
  451. redo:
  452. m->header_state = 0xff;
  453. size = MAX_SYNC_SIZE;
  454. startcode = find_start_code(&s->pb, &size, &m->header_state);
  455. //printf("startcode=%x pos=0x%Lx\n", startcode, url_ftell(&s->pb));
  456. if (startcode < 0)
  457. return -EIO;
  458. if (startcode == PACK_START_CODE)
  459. goto redo;
  460. if (startcode == SYSTEM_HEADER_START_CODE)
  461. goto redo;
  462. if (startcode == PADDING_STREAM ||
  463. startcode == PRIVATE_STREAM_2) {
  464. /* skip them */
  465. len = get_be16(&s->pb);
  466. url_fskip(&s->pb, len);
  467. goto redo;
  468. }
  469. /* find matching stream */
  470. if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
  471. (startcode >= 0x1e0 && startcode <= 0x1ef) ||
  472. (startcode == 0x1bd)))
  473. goto redo;
  474. len = get_be16(&s->pb);
  475. pts = 0;
  476. dts = 0;
  477. /* stuffing */
  478. for(;;) {
  479. c = get_byte(&s->pb);
  480. len--;
  481. /* XXX: for mpeg1, should test only bit 7 */
  482. if (c != 0xff)
  483. break;
  484. }
  485. if ((c & 0xc0) == 0x40) {
  486. /* buffer scale & size */
  487. get_byte(&s->pb);
  488. c = get_byte(&s->pb);
  489. len -= 2;
  490. }
  491. if ((c & 0xf0) == 0x20) {
  492. pts = get_pts(&s->pb, c);
  493. len -= 4;
  494. dts = pts;
  495. } else if ((c & 0xf0) == 0x30) {
  496. pts = get_pts(&s->pb, c);
  497. dts = get_pts(&s->pb, -1);
  498. len -= 9;
  499. } else if ((c & 0xc0) == 0x80) {
  500. /* mpeg 2 PES */
  501. if ((c & 0x30) != 0) {
  502. fprintf(stderr, "Encrypted multiplex not handled\n");
  503. return -EIO;
  504. }
  505. flags = get_byte(&s->pb);
  506. header_len = get_byte(&s->pb);
  507. len -= 2;
  508. if (header_len > len)
  509. goto redo;
  510. if ((flags & 0xc0) == 0x80) {
  511. pts = get_pts(&s->pb, -1);
  512. dts = pts;
  513. header_len -= 5;
  514. len -= 5;
  515. } if ((flags & 0xc0) == 0xc0) {
  516. pts = get_pts(&s->pb, -1);
  517. dts = get_pts(&s->pb, -1);
  518. header_len -= 10;
  519. len -= 10;
  520. }
  521. len -= header_len;
  522. while (header_len > 0) {
  523. get_byte(&s->pb);
  524. header_len--;
  525. }
  526. }
  527. if (startcode == 0x1bd) {
  528. startcode = get_byte(&s->pb);
  529. len--;
  530. if (startcode >= 0x80 && startcode <= 0xbf) {
  531. /* audio: skip header */
  532. get_byte(&s->pb);
  533. get_byte(&s->pb);
  534. get_byte(&s->pb);
  535. len -= 3;
  536. }
  537. }
  538. /* now find stream */
  539. for(i=0;i<s->nb_streams;i++) {
  540. st = s->streams[i];
  541. if (st->id == startcode)
  542. goto found;
  543. }
  544. if (startcode >= 0x1e0 && startcode <= 0x1ef) {
  545. type = CODEC_TYPE_VIDEO;
  546. codec_id = CODEC_ID_MPEG1VIDEO;
  547. } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
  548. type = CODEC_TYPE_AUDIO;
  549. codec_id = CODEC_ID_MP2;
  550. } else if (startcode >= 0x80 && startcode <= 0x9f) {
  551. type = CODEC_TYPE_AUDIO;
  552. codec_id = CODEC_ID_AC3;
  553. } else {
  554. skip:
  555. /* skip packet */
  556. url_fskip(&s->pb, len);
  557. goto redo;
  558. }
  559. /* no stream found: add a new stream */
  560. st = av_new_stream(s, startcode);
  561. if (!st)
  562. goto skip;
  563. st->codec.codec_type = type;
  564. st->codec.codec_id = codec_id;
  565. found:
  566. av_new_packet(pkt, len);
  567. //printf("\nRead Packet ID: %x PTS: %f Size: %d", startcode,
  568. // (float)pts/90000, len);
  569. get_buffer(&s->pb, pkt->data, pkt->size);
  570. pkt->pts = pts;
  571. pkt->stream_index = st->index;
  572. return 0;
  573. }
  574. static int mpegps_read_close(AVFormatContext *s)
  575. {
  576. return 0;
  577. }
  578. static AVOutputFormat mpeg1system_mux = {
  579. "mpeg",
  580. "MPEG1 System format",
  581. "video/x-mpeg",
  582. "mpg,mpeg",
  583. sizeof(MpegMuxContext),
  584. CODEC_ID_MP2,
  585. CODEC_ID_MPEG1VIDEO,
  586. mpeg_mux_init,
  587. mpeg_mux_write_packet,
  588. mpeg_mux_end,
  589. };
  590. static AVOutputFormat mpeg1vcd_mux = {
  591. "vcd",
  592. "MPEG1 System format (VCD)",
  593. "video/x-mpeg",
  594. NULL,
  595. sizeof(MpegMuxContext),
  596. CODEC_ID_MP2,
  597. CODEC_ID_MPEG1VIDEO,
  598. mpeg_mux_init,
  599. mpeg_mux_write_packet,
  600. mpeg_mux_end,
  601. };
  602. static AVOutputFormat mpeg2vob_mux = {
  603. "vob",
  604. "MPEG2 PS format (VOB)",
  605. "video/x-mpeg",
  606. "vob",
  607. sizeof(MpegMuxContext),
  608. CODEC_ID_MP2,
  609. CODEC_ID_MPEG1VIDEO,
  610. mpeg_mux_init,
  611. mpeg_mux_write_packet,
  612. mpeg_mux_end,
  613. };
  614. static AVInputFormat mpegps_demux = {
  615. "mpeg",
  616. "MPEG PS format",
  617. sizeof(MpegDemuxContext),
  618. mpegps_probe,
  619. mpegps_read_header,
  620. mpegps_read_packet,
  621. mpegps_read_close,
  622. .flags = AVFMT_NOHEADER,
  623. };
  624. int mpegps_init(void)
  625. {
  626. av_register_output_format(&mpeg1system_mux);
  627. av_register_output_format(&mpeg1vcd_mux);
  628. av_register_output_format(&mpeg2vob_mux);
  629. av_register_input_format(&mpegps_demux);
  630. return 0;
  631. }