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.

584 lines
19KB

  1. /*
  2. * MPEG1/2 demuxer
  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 "internal.h"
  23. #include "mpeg.h"
  24. #undef NDEBUG
  25. #include <assert.h>
  26. /*********************************************/
  27. /* demux code */
  28. #define MAX_SYNC_SIZE 100000
  29. static int check_pes(uint8_t *p, uint8_t *end){
  30. int pes1;
  31. int pes2= (p[3] & 0xC0) == 0x80
  32. && (p[4] & 0xC0) != 0x40
  33. &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0));
  34. for(p+=3; p<end && *p == 0xFF; p++);
  35. if((*p&0xC0) == 0x40) p+=2;
  36. if((*p&0xF0) == 0x20){
  37. pes1= p[0]&p[2]&p[4]&1;
  38. }else if((*p&0xF0) == 0x30){
  39. pes1= p[0]&p[2]&p[4]&p[5]&p[7]&p[9]&1;
  40. }else
  41. pes1 = *p == 0x0F;
  42. return pes1||pes2;
  43. }
  44. static int check_pack_header(const uint8_t *buf) {
  45. return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20;
  46. }
  47. static int mpegps_probe(AVProbeData *p)
  48. {
  49. uint32_t code= -1;
  50. int sys=0, pspack=0, priv1=0, vid=0, audio=0, invalid=0;
  51. int i;
  52. int score=0;
  53. for(i=0; i<p->buf_size; i++){
  54. code = (code<<8) + p->buf[i];
  55. if ((code & 0xffffff00) == 0x100) {
  56. int len= p->buf[i+1] << 8 | p->buf[i+2];
  57. int pes= check_pes(p->buf+i, p->buf+p->buf_size);
  58. int pack = check_pack_header(p->buf+i);
  59. if(code == SYSTEM_HEADER_START_CODE) sys++;
  60. else if(code == PACK_START_CODE && pack) pspack++;
  61. else if((code & 0xf0) == VIDEO_ID && pes) vid++;
  62. // skip pes payload to avoid start code emulation for private
  63. // and audio streams
  64. else if((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;}
  65. else if(code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;}
  66. else if(code == 0x1fd && pes) vid++; //VC1
  67. else if((code & 0xf0) == VIDEO_ID && !pes) invalid++;
  68. else if((code & 0xe0) == AUDIO_ID && !pes) invalid++;
  69. else if(code == PRIVATE_STREAM_1 && !pes) invalid++;
  70. }
  71. }
  72. if(vid+audio > invalid+1) /* invalid VDR files nd short PES streams */
  73. score= AVPROBE_SCORE_MAX/4;
  74. //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size);
  75. if(sys>invalid && sys*9 <= pspack*10)
  76. return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
  77. if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9)
  78. return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
  79. if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048 && vid + audio > invalid) /* PES stream */
  80. return (audio > 12 || vid > 3) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4;
  81. //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
  82. //mp3_misidentified_2.mp3 has sys:0 priv1:0 pspack:0 vid:0 audio:6
  83. return score;
  84. }
  85. typedef struct MpegDemuxContext {
  86. int32_t header_state;
  87. unsigned char psm_es_type[256];
  88. int sofdec;
  89. } MpegDemuxContext;
  90. static int mpegps_read_header(AVFormatContext *s)
  91. {
  92. MpegDemuxContext *m = s->priv_data;
  93. const char *sofdec = "Sofdec";
  94. int v, i = 0;
  95. int64_t last_pos = avio_tell(s->pb);
  96. m->header_state = 0xff;
  97. s->ctx_flags |= AVFMTCTX_NOHEADER;
  98. m->sofdec = -1;
  99. do {
  100. v = avio_r8(s->pb);
  101. m->sofdec++;
  102. } while (v == sofdec[i] && i++ < 6);
  103. m->sofdec = (m->sofdec == 6) ? 1 : 0;
  104. if (!m->sofdec)
  105. avio_seek(s->pb, last_pos, SEEK_SET);
  106. /* no need to do more */
  107. return 0;
  108. }
  109. static int64_t get_pts(AVIOContext *pb, int c)
  110. {
  111. uint8_t buf[5];
  112. buf[0] = c<0 ? avio_r8(pb) : c;
  113. avio_read(pb, buf+1, 4);
  114. return ff_parse_pes_pts(buf);
  115. }
  116. static int find_next_start_code(AVIOContext *pb, int *size_ptr,
  117. int32_t *header_state)
  118. {
  119. unsigned int state, v;
  120. int val, n;
  121. state = *header_state;
  122. n = *size_ptr;
  123. while (n > 0) {
  124. if (url_feof(pb))
  125. break;
  126. v = avio_r8(pb);
  127. n--;
  128. if (state == 0x000001) {
  129. state = ((state << 8) | v) & 0xffffff;
  130. val = state;
  131. goto found;
  132. }
  133. state = ((state << 8) | v) & 0xffffff;
  134. }
  135. val = -1;
  136. found:
  137. *header_state = state;
  138. *size_ptr = n;
  139. return val;
  140. }
  141. /**
  142. * Extract stream types from a program stream map
  143. * According to ISO/IEC 13818-1 ('MPEG-2 Systems') table 2-35
  144. *
  145. * @return number of bytes occupied by PSM in the bitstream
  146. */
  147. static long mpegps_psm_parse(MpegDemuxContext *m, AVIOContext *pb)
  148. {
  149. int psm_length, ps_info_length, es_map_length;
  150. psm_length = avio_rb16(pb);
  151. avio_r8(pb);
  152. avio_r8(pb);
  153. ps_info_length = avio_rb16(pb);
  154. /* skip program_stream_info */
  155. avio_skip(pb, ps_info_length);
  156. es_map_length = avio_rb16(pb);
  157. /* at least one es available? */
  158. while (es_map_length >= 4){
  159. unsigned char type = avio_r8(pb);
  160. unsigned char es_id = avio_r8(pb);
  161. uint16_t es_info_length = avio_rb16(pb);
  162. /* remember mapping from stream id to stream type */
  163. m->psm_es_type[es_id] = type;
  164. /* skip program_stream_info */
  165. avio_skip(pb, es_info_length);
  166. es_map_length -= 4 + es_info_length;
  167. }
  168. avio_rb32(pb); /* crc32 */
  169. return 2 + psm_length;
  170. }
  171. /* read the next PES header. Return its position in ppos
  172. (if not NULL), and its start code, pts and dts.
  173. */
  174. static int mpegps_read_pes_header(AVFormatContext *s,
  175. int64_t *ppos, int *pstart_code,
  176. int64_t *ppts, int64_t *pdts)
  177. {
  178. MpegDemuxContext *m = s->priv_data;
  179. int len, size, startcode, c, flags, header_len;
  180. int pes_ext, ext2_len, id_ext, skip;
  181. int64_t pts, dts;
  182. int64_t last_sync= avio_tell(s->pb);
  183. error_redo:
  184. avio_seek(s->pb, last_sync, SEEK_SET);
  185. redo:
  186. /* next start code (should be immediately after) */
  187. m->header_state = 0xff;
  188. size = MAX_SYNC_SIZE;
  189. startcode = find_next_start_code(s->pb, &size, &m->header_state);
  190. last_sync = avio_tell(s->pb);
  191. //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb));
  192. if (startcode < 0){
  193. if(url_feof(s->pb))
  194. return AVERROR_EOF;
  195. //FIXME we should remember header_state
  196. return AVERROR(EAGAIN);
  197. }
  198. if (startcode == PACK_START_CODE)
  199. goto redo;
  200. if (startcode == SYSTEM_HEADER_START_CODE)
  201. goto redo;
  202. if (startcode == PADDING_STREAM) {
  203. avio_skip(s->pb, avio_rb16(s->pb));
  204. goto redo;
  205. }
  206. if (startcode == PRIVATE_STREAM_2) {
  207. len = avio_rb16(s->pb);
  208. if (!m->sofdec) {
  209. while (len-- >= 6) {
  210. if (avio_r8(s->pb) == 'S') {
  211. uint8_t buf[5];
  212. avio_read(s->pb, buf, sizeof(buf));
  213. m->sofdec = !memcmp(buf, "ofdec", 5);
  214. len -= sizeof(buf);
  215. break;
  216. }
  217. }
  218. m->sofdec -= !m->sofdec;
  219. }
  220. avio_skip(s->pb, len);
  221. goto redo;
  222. }
  223. if (startcode == PROGRAM_STREAM_MAP) {
  224. mpegps_psm_parse(m, s->pb);
  225. goto redo;
  226. }
  227. /* find matching stream */
  228. if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
  229. (startcode >= 0x1e0 && startcode <= 0x1ef) ||
  230. (startcode == 0x1bd) || (startcode == 0x1fd)))
  231. goto redo;
  232. if (ppos) {
  233. *ppos = avio_tell(s->pb) - 4;
  234. }
  235. len = avio_rb16(s->pb);
  236. pts =
  237. dts = AV_NOPTS_VALUE;
  238. /* stuffing */
  239. for(;;) {
  240. if (len < 1)
  241. goto error_redo;
  242. c = avio_r8(s->pb);
  243. len--;
  244. /* XXX: for mpeg1, should test only bit 7 */
  245. if (c != 0xff)
  246. break;
  247. }
  248. if ((c & 0xc0) == 0x40) {
  249. /* buffer scale & size */
  250. avio_r8(s->pb);
  251. c = avio_r8(s->pb);
  252. len -= 2;
  253. }
  254. if ((c & 0xe0) == 0x20) {
  255. dts = pts = get_pts(s->pb, c);
  256. len -= 4;
  257. if (c & 0x10){
  258. dts = get_pts(s->pb, -1);
  259. len -= 5;
  260. }
  261. } else if ((c & 0xc0) == 0x80) {
  262. /* mpeg 2 PES */
  263. flags = avio_r8(s->pb);
  264. header_len = avio_r8(s->pb);
  265. len -= 2;
  266. if (header_len > len)
  267. goto error_redo;
  268. len -= header_len;
  269. if (flags & 0x80) {
  270. dts = pts = get_pts(s->pb, -1);
  271. header_len -= 5;
  272. if (flags & 0x40) {
  273. dts = get_pts(s->pb, -1);
  274. header_len -= 5;
  275. }
  276. }
  277. if (flags & 0x3f && header_len == 0){
  278. flags &= 0xC0;
  279. av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n");
  280. }
  281. if (flags & 0x01) { /* PES extension */
  282. pes_ext = avio_r8(s->pb);
  283. header_len--;
  284. /* Skip PES private data, program packet sequence counter and P-STD buffer */
  285. skip = (pes_ext >> 4) & 0xb;
  286. skip += skip & 0x9;
  287. if (pes_ext & 0x40 || skip > header_len){
  288. av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext);
  289. pes_ext=skip=0;
  290. }
  291. avio_skip(s->pb, skip);
  292. header_len -= skip;
  293. if (pes_ext & 0x01) { /* PES extension 2 */
  294. ext2_len = avio_r8(s->pb);
  295. header_len--;
  296. if ((ext2_len & 0x7f) > 0) {
  297. id_ext = avio_r8(s->pb);
  298. if ((id_ext & 0x80) == 0)
  299. startcode = ((startcode & 0xff) << 8) | id_ext;
  300. header_len--;
  301. }
  302. }
  303. }
  304. if(header_len < 0)
  305. goto error_redo;
  306. avio_skip(s->pb, header_len);
  307. }
  308. else if( c!= 0xf )
  309. goto redo;
  310. if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {
  311. startcode = avio_r8(s->pb);
  312. len--;
  313. if (startcode >= 0x80 && startcode <= 0xcf) {
  314. /* audio: skip header */
  315. avio_r8(s->pb);
  316. avio_r8(s->pb);
  317. avio_r8(s->pb);
  318. len -= 3;
  319. if (startcode >= 0xb0 && startcode <= 0xbf) {
  320. /* MLP/TrueHD audio has a 4-byte header */
  321. avio_r8(s->pb);
  322. len--;
  323. }
  324. }
  325. }
  326. if(len<0)
  327. goto error_redo;
  328. if(dts != AV_NOPTS_VALUE && ppos){
  329. int i;
  330. for(i=0; i<s->nb_streams; i++){
  331. if(startcode == s->streams[i]->id &&
  332. s->pb->seekable /* index useless on streams anyway */) {
  333. ff_reduce_index(s, i);
  334. av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
  335. }
  336. }
  337. }
  338. *pstart_code = startcode;
  339. *ppts = pts;
  340. *pdts = dts;
  341. return len;
  342. }
  343. static int mpegps_read_packet(AVFormatContext *s,
  344. AVPacket *pkt)
  345. {
  346. MpegDemuxContext *m = s->priv_data;
  347. AVStream *st;
  348. int len, startcode, i, es_type, ret;
  349. int request_probe= 0;
  350. enum CodecID codec_id = CODEC_ID_NONE;
  351. enum AVMediaType type;
  352. int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work
  353. uint8_t av_uninit(dvdaudio_substream_type);
  354. redo:
  355. len = mpegps_read_pes_header(s, &dummy_pos, &startcode, &pts, &dts);
  356. if (len < 0)
  357. return len;
  358. if(startcode == 0x1bd) {
  359. dvdaudio_substream_type = avio_r8(s->pb);
  360. avio_skip(s->pb, 3);
  361. len -= 4;
  362. }
  363. /* now find stream */
  364. for(i=0;i<s->nb_streams;i++) {
  365. st = s->streams[i];
  366. if (st->id == startcode)
  367. goto found;
  368. }
  369. es_type = m->psm_es_type[startcode & 0xff];
  370. if(es_type > 0 && es_type != STREAM_TYPE_PRIVATE_DATA){
  371. if(es_type == STREAM_TYPE_VIDEO_MPEG1){
  372. codec_id = CODEC_ID_MPEG2VIDEO;
  373. type = AVMEDIA_TYPE_VIDEO;
  374. } else if(es_type == STREAM_TYPE_VIDEO_MPEG2){
  375. codec_id = CODEC_ID_MPEG2VIDEO;
  376. type = AVMEDIA_TYPE_VIDEO;
  377. } else if(es_type == STREAM_TYPE_AUDIO_MPEG1 ||
  378. es_type == STREAM_TYPE_AUDIO_MPEG2){
  379. codec_id = CODEC_ID_MP3;
  380. type = AVMEDIA_TYPE_AUDIO;
  381. } else if(es_type == STREAM_TYPE_AUDIO_AAC){
  382. codec_id = CODEC_ID_AAC;
  383. type = AVMEDIA_TYPE_AUDIO;
  384. } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){
  385. codec_id = CODEC_ID_MPEG4;
  386. type = AVMEDIA_TYPE_VIDEO;
  387. } else if(es_type == STREAM_TYPE_VIDEO_H264){
  388. codec_id = CODEC_ID_H264;
  389. type = AVMEDIA_TYPE_VIDEO;
  390. } else if(es_type == STREAM_TYPE_AUDIO_AC3){
  391. codec_id = CODEC_ID_AC3;
  392. type = AVMEDIA_TYPE_AUDIO;
  393. } else {
  394. goto skip;
  395. }
  396. } else if (startcode >= 0x1e0 && startcode <= 0x1ef) {
  397. static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
  398. unsigned char buf[8];
  399. avio_read(s->pb, buf, 8);
  400. avio_seek(s->pb, -8, SEEK_CUR);
  401. if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
  402. codec_id = CODEC_ID_CAVS;
  403. else
  404. request_probe= 1;
  405. type = AVMEDIA_TYPE_VIDEO;
  406. } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
  407. type = AVMEDIA_TYPE_AUDIO;
  408. codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2;
  409. } else if (startcode >= 0x80 && startcode <= 0x87) {
  410. type = AVMEDIA_TYPE_AUDIO;
  411. codec_id = CODEC_ID_AC3;
  412. } else if ( ( startcode >= 0x88 && startcode <= 0x8f)
  413. ||( startcode >= 0x98 && startcode <= 0x9f)) {
  414. /* 0x90 - 0x97 is reserved for SDDS in DVD specs */
  415. type = AVMEDIA_TYPE_AUDIO;
  416. codec_id = CODEC_ID_DTS;
  417. } else if (startcode >= 0xa0 && startcode <= 0xaf) {
  418. type = AVMEDIA_TYPE_AUDIO;
  419. /* 16 bit form will be handled as CODEC_ID_PCM_S16BE */
  420. codec_id = CODEC_ID_PCM_DVD;
  421. } else if (startcode >= 0xb0 && startcode <= 0xbf) {
  422. type = AVMEDIA_TYPE_AUDIO;
  423. codec_id = CODEC_ID_TRUEHD;
  424. } else if (startcode >= 0xc0 && startcode <= 0xcf) {
  425. /* Used for both AC-3 and E-AC-3 in EVOB files */
  426. type = AVMEDIA_TYPE_AUDIO;
  427. codec_id = CODEC_ID_AC3;
  428. } else if (startcode >= 0x20 && startcode <= 0x3f) {
  429. type = AVMEDIA_TYPE_SUBTITLE;
  430. codec_id = CODEC_ID_DVD_SUBTITLE;
  431. } else if (startcode >= 0xfd55 && startcode <= 0xfd5f) {
  432. type = AVMEDIA_TYPE_VIDEO;
  433. codec_id = CODEC_ID_VC1;
  434. } else if (startcode == 0x1bd) {
  435. // check dvd audio substream type
  436. type = AVMEDIA_TYPE_AUDIO;
  437. switch(dvdaudio_substream_type & 0xe0) {
  438. case 0xa0: codec_id = CODEC_ID_PCM_DVD;
  439. break;
  440. case 0x80: if((dvdaudio_substream_type & 0xf8) == 0x88)
  441. codec_id = CODEC_ID_DTS;
  442. else codec_id = CODEC_ID_AC3;
  443. break;
  444. default: av_log(s, AV_LOG_ERROR, "Unknown 0x1bd sub-stream\n");
  445. goto skip;
  446. }
  447. } else {
  448. skip:
  449. /* skip packet */
  450. avio_skip(s->pb, len);
  451. goto redo;
  452. }
  453. /* no stream found: add a new stream */
  454. st = avformat_new_stream(s, NULL);
  455. if (!st)
  456. goto skip;
  457. st->id = startcode;
  458. st->codec->codec_type = type;
  459. st->codec->codec_id = codec_id;
  460. st->request_probe = request_probe;
  461. if (codec_id != CODEC_ID_PCM_S16BE)
  462. st->need_parsing = AVSTREAM_PARSE_FULL;
  463. found:
  464. if(st->discard >= AVDISCARD_ALL)
  465. goto skip;
  466. if ((startcode >= 0xa0 && startcode <= 0xaf) ||
  467. (startcode == 0x1bd && ((dvdaudio_substream_type & 0xe0) == 0xa0))) {
  468. int b1, freq;
  469. /* for LPCM, we just skip the header and consider it is raw
  470. audio data */
  471. if (len <= 3)
  472. goto skip;
  473. avio_r8(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */
  474. b1 = avio_r8(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */
  475. avio_r8(s->pb); /* dynamic range control (0x80 = off) */
  476. len -= 3;
  477. freq = (b1 >> 4) & 3;
  478. st->codec->sample_rate = lpcm_freq_tab[freq];
  479. st->codec->channels = 1 + (b1 & 7);
  480. st->codec->bits_per_coded_sample = 16 + ((b1 >> 6) & 3) * 4;
  481. st->codec->bit_rate = st->codec->channels *
  482. st->codec->sample_rate *
  483. st->codec->bits_per_coded_sample;
  484. if (st->codec->bits_per_coded_sample == 16)
  485. st->codec->codec_id = CODEC_ID_PCM_S16BE;
  486. else if (st->codec->bits_per_coded_sample == 28)
  487. return AVERROR(EINVAL);
  488. }
  489. ret = av_get_packet(s->pb, pkt, len);
  490. pkt->pts = pts;
  491. pkt->dts = dts;
  492. pkt->pos = dummy_pos;
  493. pkt->stream_index = st->index;
  494. av_dlog(s, "%d: pts=%0.3f dts=%0.3f size=%d\n",
  495. pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0,
  496. pkt->size);
  497. return (ret < 0) ? ret : 0;
  498. }
  499. static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index,
  500. int64_t *ppos, int64_t pos_limit)
  501. {
  502. int len, startcode;
  503. int64_t pos, pts, dts;
  504. pos = *ppos;
  505. if (avio_seek(s->pb, pos, SEEK_SET) < 0)
  506. return AV_NOPTS_VALUE;
  507. for(;;) {
  508. len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts);
  509. if (len < 0) {
  510. av_dlog(s, "none (ret=%d)\n", len);
  511. return AV_NOPTS_VALUE;
  512. }
  513. if (startcode == s->streams[stream_index]->id &&
  514. dts != AV_NOPTS_VALUE) {
  515. break;
  516. }
  517. avio_skip(s->pb, len);
  518. }
  519. av_dlog(s, "pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n",
  520. pos, dts, dts / 90000.0);
  521. *ppos = pos;
  522. return dts;
  523. }
  524. AVInputFormat ff_mpegps_demuxer = {
  525. .name = "mpeg",
  526. .long_name = NULL_IF_CONFIG_SMALL("MPEG-PS format"),
  527. .priv_data_size = sizeof(MpegDemuxContext),
  528. .read_probe = mpegps_probe,
  529. .read_header = mpegps_read_header,
  530. .read_packet = mpegps_read_packet,
  531. .read_timestamp = mpegps_read_dts,
  532. .flags = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
  533. };