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