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.

711 lines
20KB

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