annotate libmpdemux/parse_es.c @ 11623:ecaf7047b6e8

Patch from the author, Zoltan Hidvegi: The filmdint filter does not handle NTSC "telecined" 15fps movies where there is a frame break in the middle of every second NTSC frame, it outputs only 15 frames for every 30 input frames, ignoring the io option. You can notice this during encoding such a sequence you will have lots of diplicate frames / skip frames messages. The patch below fixes this.
author rfelker
date Thu, 11 Dec 2003 04:47:42 +0000
parents 66837325b929
children 8ea2e7ab3106
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
1 //=================== MPEG-ES VIDEO PARSER =========================
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
2
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
3 #include <stdio.h>
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
4 #include <stdlib.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1376
diff changeset
5 #include <unistd.h>
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
6
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
7 #include "config.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
8 #include "mp_msg.h"
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
9 #include "help_mp.h"
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
10
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
11 #include "stream.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
12 #include "demuxer.h"
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
13 #include "parse_es.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 //static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
1376
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
16 unsigned char* videobuffer=NULL;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
17 int videobuf_len=0;
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
18 unsigned char videobuf_code[4];
d1fb303707d3 parse_es moved out from mplayer.c (it was included as .c file)
arpi
parents: 400
diff changeset
19 int videobuf_code_len=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 // sync video stream, and returns next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 int sync_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 // we need enough bytes in the buffer:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 while(videobuf_code_len<4){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 videobuf_code[videobuf_code_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 videobuf_code[videobuf_code_len++]=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 // sync packet:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 int c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 if(videobuf_code[0]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 videobuf_code[1]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 videobuf_code[2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 // shift buffer, drop first byte
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 ++skipped;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 videobuf_code[0]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 videobuf_code[1]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 videobuf_code[2]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 c=demux_getc(ds);if(c<0){ return 0;} // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 videobuf_code[3]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 }
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
48 if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,videobuf_code[3]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 return 0x100|videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 // return: packet length
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 int read_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 int packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 // COPY STARTCODE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 packet_start=videobuf_len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 videobuffer[videobuf_len+0]=videobuf_code[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 videobuffer[videobuf_len+1]=videobuf_code[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 videobuffer[videobuf_len+2]=videobuf_code[2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 videobuffer[videobuf_len+3]=videobuf_code[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 videobuf_len+=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 // READ PACKET:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 { unsigned int head=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 while(videobuf_len<VIDEOBUFFER_SIZE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 int c=demux_getc(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if(c<0) break; // EOF
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 videobuffer[videobuf_len++]=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 head<<=8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(head==0x100) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 head|=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 if(videobuffer[videobuf_len-4]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 videobuffer[videobuf_len-3]==0 &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 videobuffer[videobuf_len-2]==1) break; // synced
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 if(ds->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 videobuf_code_len=0; // EOF, no next code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 videobuf_len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1430
diff changeset
92 mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 // Save next packet code:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 videobuf_code[0]=videobuffer[videobuf_len];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 videobuf_code[1]=videobuffer[videobuf_len+1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 videobuf_code[2]=videobuffer[videobuf_len+2];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 videobuf_code[3]=videobuffer[videobuf_len+3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 videobuf_code_len=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 return videobuf_len-packet_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 // return: next packet code
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 int skip_video_packet(demux_stream_t *ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 // SYNC STREAM
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 // if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 videobuf_code_len=0; // force resync
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 // SYNC AGAIN:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 return sync_video_packet(ds);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }