6 #include "loader/wine/mmreg.h"
7 #include "loader/wine/avifmt.h"
8 #include "loader/wine/vfw.h"
10 #include "libmpdemux/muxer.h"
17 char *info_sourceform
;
20 static const short h263_format
[8][2] = {
30 unsigned char* buffer
;
35 unsigned int x_get_bits(int n
){
43 //x=(x<<1)|(buf&1);buf>>=1;
44 x
=(x
<<1)|(buf
>>7);buf
<<=1;
50 #define get_bits(xxx,n) x_get_bits(n)
51 #define get_bits1(xxx) x_get_bits(1)
52 #define skip_bits(xxx,n) x_get_bits(n)
53 #define skip_bits1(xxx) x_get_bits(1)
59 /* most is hardcoded. should extend to handle all h263 streams */
60 int h263_decode_picture_header(unsigned char *b_ptr
)
64 for(i
=0;i
<16;i
++) printf(" %02X",b_ptr
[i
]); printf("\n");
70 if (get_bits(&s
->gb
, 22) != 0x20){
71 printf("bad picture header\n");
74 skip_bits(&s
->gb
, 8); /* picture timestamp */
76 if (get_bits1(&s
->gb
) != 1){
77 printf("bad marker\n");
78 return -1; /* marker */
80 if (get_bits1(&s
->gb
) != 0){
81 printf("bad h263 id\n");
82 return -1; /* h263 id */
84 skip_bits1(&s
->gb
); /* split screen off */
85 skip_bits1(&s
->gb
); /* camera off */
86 skip_bits1(&s
->gb
); /* freeze picture release off */
88 format
= get_bits(&s
->gb
, 3);
91 printf("h263_plus = 0 format = %d\n",format
);
93 width
= h263_format
[format
][0];
94 height
= h263_format
[format
][1];
95 printf("%d x %d\n",width
,height
);
96 // if (!width) return -1;
98 printf("pict_type=%d\n",get_bits1(&s
->gb
));
99 printf("unrestricted_mv=%d\n",get_bits1(&s
->gb
));
101 printf("SAC: %d\n",get_bits1(&s
->gb
));
102 printf("advanced prediction mode: %d\n",get_bits1(&s
->gb
));
103 printf("PB frame: %d\n",get_bits1(&s
->gb
));
105 if (get_bits1(&s
->gb
) != 0)
106 return -1; /* SAC: off */
107 if (get_bits1(&s
->gb
) != 0)
108 return -1; /* advanced prediction mode: off */
109 if (get_bits1(&s
->gb
) != 0)
110 return -1; /* not PB frame */
112 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
113 skip_bits1(&s
->gb
); /* Continuous Presence Multipoint mode: off */
115 printf("h263_plus = 1\n");
117 if (get_bits(&s
->gb
, 3) != 1){
118 printf("H.263v2 A error\n");
121 if (get_bits(&s
->gb
, 3) != 6){ /* custom source format */
122 printf("custom source format\n");
125 skip_bits(&s
->gb
, 12);
126 skip_bits(&s
->gb
, 3);
127 printf("pict_type=%d\n",get_bits(&s
->gb
, 3) + 1);
128 // if (s->pict_type != I_TYPE &&
129 // s->pict_type != P_TYPE)
131 skip_bits(&s
->gb
, 7);
132 skip_bits(&s
->gb
, 4); /* aspect ratio */
133 width
= (get_bits(&s
->gb
, 9) + 1) * 4;
135 height
= get_bits(&s
->gb
, 9) * 4;
136 printf("%d x %d\n",width
,height
);
139 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
143 while (get_bits1(&s
->gb
) != 0) {
144 skip_bits(&s
->gb
, 8);
148 // s->height = height;
154 int main(int argc
,char ** argv
){
156 unsigned int head
=-1;
163 //unsigned char* buffer=malloc(0x200000);
170 // check if enough args were given
172 printf("Too few arguments given!\n"
173 "Usage: %s <input_file> <output_file>\n", argv
[0]);
178 if(!(f
=fopen(argv
[1],"rb"))){
179 printf("Couldn't open input file.\n");
183 if(!(f2
=fopen(argv
[2],"wb"))){
184 printf("Couldn't open output file.\n");
188 avi
=muxer_new_muxer(MUXER_TYPE_AVI
,f2
);
189 mux
=muxer_new_stream(avi
,MUXER_TYPE_VIDEO
);
191 mux
->buffer_size
=0x200000;
192 mux
->buffer
=malloc(mux
->buffer_size
);
197 mux
->bih
=malloc(sizeof(BITMAPINFOHEADER
));
198 mux
->bih
->biSize
=sizeof(BITMAPINFOHEADER
);
199 mux
->bih
->biPlanes
=1;
200 mux
->bih
->biBitCount
=24;
201 mux
->bih
->biCompression
=0x6f766976;// 7669766f;
202 muxer_write_header(avi
);
205 c=fgetc(f); if(c) printf("error! not vivo file?\n");
207 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
209 printf("hdr1: %d\n",len);
210 for(i=0;i<len;i++) fgetc(f);
213 while((c
=fgetc(f
))>=0){
215 printf("%08X %02X\n",ftell(f
),c
);
222 printf("%08X %02X\n",ftell(f
),c
);
228 while((c
=fgetc(f
))>=0x80) len
+=0x80*(c
&0x0F);
230 printf("header: 00 (%d)\n",len
);
231 for(i
=0;i
<len
;i
++) fgetc(f
);
238 if(prefix
) len
=fgetc(f
);
239 printf("audio: %02X (%d)\n",c
,len
);
240 for(i
=0;i
<len
;i
++) fgetc(f
);
246 if(prefix
) len
=fgetc(f
);
247 printf("audio: %02X (%d)\n",c
,len
);
248 for(i
=0;i
<len
;i
++) fgetc(f
);
251 if(flag2
|| (((c
&0xF0)==0x10 || (c
&0xF0)==0x20) && (c
&0x0F)!=(v_id
&0xF))){
253 printf("Frame size: %d\n",mux
->buffer_len
);
254 h263_decode_picture_header(mux
->buffer
);
255 muxer_write_chunk(mux
,mux
->buffer_len
,0x10);
258 if((v_id
&0xF0)==0x10) fprintf(stderr
,"hmm. last video packet %02X\n",v_id
);
264 if(prefix
) len
=fgetc(f
);
265 printf("video: %02X (%d)\n",c
,len
);
266 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
267 mux
->buffer_len
+=len
;
273 printf("video: %02X (%d)\n",c
,len
);
274 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
275 mux
->buffer_len
+=len
;
280 printf("error: %02X!\n",c
);
284 if(!width
) width
=320;
285 if(!height
) height
=240;
287 mux
->bih
->biWidth
=width
;
288 mux
->bih
->biHeight
=height
;
289 mux
->bih
->biSizeImage
=3*width
*height
;
291 muxer_write_index(avi
);
292 fseek(f2
,0,SEEK_SET
);
293 muxer_write_header(avi
);