6 #include "loader/wine/mmreg.h"
7 #include "loader/wine/vfw.h"
9 #include "stream/stream.h"
10 #include "libmpdemux/muxer.h"
11 #include "libmpdemux/demuxer.h"
19 char *info_sourceform
;
22 char* out_filename
= NULL
;
23 char* force_fourcc
=NULL
;
24 char* passtmpfile
="divx2pass.log";
26 static const short h263_format
[8][2] = {
36 unsigned char* buffer
;
41 static unsigned int x_get_bits(int n
){
49 //x=(x<<1)|(buf&1);buf>>=1;
50 x
=(x
<<1)|(buf
>>7);buf
<<=1;
56 #define get_bits(xxx,n) x_get_bits(n)
57 #define get_bits1(xxx) x_get_bits(1)
58 #define skip_bits(xxx,n) x_get_bits(n)
59 #define skip_bits1(xxx) x_get_bits(1)
65 /* most is hardcoded. should extend to handle all h263 streams */
66 static int h263_decode_picture_header(unsigned char *b_ptr
)
70 for(i
=0;i
<16;i
++) printf(" %02X",b_ptr
[i
]); printf("\n");
76 if (get_bits(&s
->gb
, 22) != 0x20){
77 printf("bad picture header\n");
80 skip_bits(&s
->gb
, 8); /* picture timestamp */
82 if (get_bits1(&s
->gb
) != 1){
83 printf("bad marker\n");
84 return -1; /* marker */
86 if (get_bits1(&s
->gb
) != 0){
87 printf("bad h263 id\n");
88 return -1; /* h263 id */
90 skip_bits1(&s
->gb
); /* split screen off */
91 skip_bits1(&s
->gb
); /* camera off */
92 skip_bits1(&s
->gb
); /* freeze picture release off */
94 format
= get_bits(&s
->gb
, 3);
97 printf("h263_plus = 0 format = %d\n",format
);
99 width
= h263_format
[format
][0];
100 height
= h263_format
[format
][1];
101 printf("%d x %d\n",width
,height
);
102 // if (!width) return -1;
104 printf("pict_type=%d\n",get_bits1(&s
->gb
));
105 printf("unrestricted_mv=%d\n",get_bits1(&s
->gb
));
107 printf("SAC: %d\n",get_bits1(&s
->gb
));
108 printf("advanced prediction mode: %d\n",get_bits1(&s
->gb
));
109 printf("PB frame: %d\n",get_bits1(&s
->gb
));
111 if (get_bits1(&s
->gb
) != 0)
112 return -1; /* SAC: off */
113 if (get_bits1(&s
->gb
) != 0)
114 return -1; /* advanced prediction mode: off */
115 if (get_bits1(&s
->gb
) != 0)
116 return -1; /* not PB frame */
118 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
119 skip_bits1(&s
->gb
); /* Continuous Presence Multipoint mode: off */
121 printf("h263_plus = 1\n");
123 if (get_bits(&s
->gb
, 3) != 1){
124 printf("H.263v2 A error\n");
127 if (get_bits(&s
->gb
, 3) != 6){ /* custom source format */
128 printf("custom source format\n");
131 skip_bits(&s
->gb
, 12);
132 skip_bits(&s
->gb
, 3);
133 printf("pict_type=%d\n",get_bits(&s
->gb
, 3) + 1);
134 // if (s->pict_type != I_TYPE &&
135 // s->pict_type != P_TYPE)
137 skip_bits(&s
->gb
, 7);
138 skip_bits(&s
->gb
, 4); /* aspect ratio */
139 width
= (get_bits(&s
->gb
, 9) + 1) * 4;
141 height
= get_bits(&s
->gb
, 9) * 4;
142 printf("%d x %d\n",width
,height
);
145 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
149 while (get_bits1(&s
->gb
) != 0) {
150 skip_bits(&s
->gb
, 8);
154 // s->height = height;
160 int main(int argc
,char ** argv
){
166 //unsigned char* buffer=malloc(0x200000);
172 // check if enough args were given
174 printf("Too few arguments given!\n"
175 "Usage: %s <input_file> <output_file>\n", argv
[0]);
180 if(!(f
=fopen(argv
[1],"rb"))){
181 printf("Couldn't open input file.\n");
185 if(!(f2
=fopen(argv
[2],"wb"))){
186 printf("Couldn't open output file.\n");
190 avi
=muxer_new_muxer(MUXER_TYPE_AVI
,f2
);
191 mux
=muxer_new_stream(avi
,MUXER_TYPE_VIDEO
);
193 mux
->buffer_size
=0x200000;
194 mux
->buffer
=malloc(mux
->buffer_size
);
199 mux
->bih
=malloc(sizeof(BITMAPINFOHEADER
));
200 mux
->bih
->biSize
=sizeof(BITMAPINFOHEADER
);
201 mux
->bih
->biPlanes
=1;
202 mux
->bih
->biBitCount
=24;
203 mux
->bih
->biCompression
=0x6f766976;// 7669766f;
204 muxer_write_header(avi
);
207 c=fgetc(f); if(c) printf("error! not vivo file?\n");
209 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
211 printf("hdr1: %d\n",len);
212 for(i=0;i<len;i++) fgetc(f);
215 while((c
=fgetc(f
))>=0){
217 printf("%08lX %02X\n",ftell(f
),c
);
224 printf("%08lX %02X\n",ftell(f
),c
);
230 while((c
=fgetc(f
))>=0x80) len
+=0x80*(c
&0x0F);
232 printf("header: 00 (%d)\n",len
);
233 for(i
=0;i
<len
;i
++) fgetc(f
);
240 if(prefix
) len
=fgetc(f
);
241 printf("audio: %02X (%d)\n",c
,len
);
242 for(i
=0;i
<len
;i
++) fgetc(f
);
248 if(prefix
) len
=fgetc(f
);
249 printf("audio: %02X (%d)\n",c
,len
);
250 for(i
=0;i
<len
;i
++) fgetc(f
);
253 if(flag2
|| (((c
&0xF0)==0x10 || (c
&0xF0)==0x20) && (c
&0x0F)!=(v_id
&0xF))){
255 printf("Frame size: %d\n",mux
->buffer_len
);
256 h263_decode_picture_header(mux
->buffer
);
257 muxer_write_chunk(mux
,mux
->buffer_len
,0x10, MP_NOPTS_VALUE
, MP_NOPTS_VALUE
);
260 if((v_id
&0xF0)==0x10) fprintf(stderr
,"hmm. last video packet %02X\n",v_id
);
266 if(prefix
) len
=fgetc(f
);
267 printf("video: %02X (%d)\n",c
,len
);
268 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
269 mux
->buffer_len
+=len
;
275 printf("video: %02X (%d)\n",c
,len
);
276 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
277 mux
->buffer_len
+=len
;
282 printf("error: %02X!\n",c
);
286 if(!width
) width
=320;
287 if(!height
) height
=240;
289 mux
->bih
->biWidth
=width
;
290 mux
->bih
->biHeight
=height
;
291 mux
->bih
->biSizeImage
=3*width
*height
;
293 muxer_write_index(avi
);
294 fseek(f2
,0,SEEK_SET
);
295 muxer_write_header(avi
);