6 #include "loader/wine/mmreg.h"
7 #include "loader/wine/avifmt.h"
8 #include "loader/wine/vfw.h"
10 #include "stream/stream.h"
11 #include "libmpdemux/muxer.h"
12 #include "libmpdemux/demuxer.h"
19 char *info_sourceform
;
22 static const short h263_format
[8][2] = {
32 unsigned char* buffer
;
37 unsigned int x_get_bits(int n
){
45 //x=(x<<1)|(buf&1);buf>>=1;
46 x
=(x
<<1)|(buf
>>7);buf
<<=1;
52 #define get_bits(xxx,n) x_get_bits(n)
53 #define get_bits1(xxx) x_get_bits(1)
54 #define skip_bits(xxx,n) x_get_bits(n)
55 #define skip_bits1(xxx) x_get_bits(1)
61 /* most is hardcoded. should extend to handle all h263 streams */
62 int h263_decode_picture_header(unsigned char *b_ptr
)
66 for(i
=0;i
<16;i
++) printf(" %02X",b_ptr
[i
]); printf("\n");
72 if (get_bits(&s
->gb
, 22) != 0x20){
73 printf("bad picture header\n");
76 skip_bits(&s
->gb
, 8); /* picture timestamp */
78 if (get_bits1(&s
->gb
) != 1){
79 printf("bad marker\n");
80 return -1; /* marker */
82 if (get_bits1(&s
->gb
) != 0){
83 printf("bad h263 id\n");
84 return -1; /* h263 id */
86 skip_bits1(&s
->gb
); /* split screen off */
87 skip_bits1(&s
->gb
); /* camera off */
88 skip_bits1(&s
->gb
); /* freeze picture release off */
90 format
= get_bits(&s
->gb
, 3);
93 printf("h263_plus = 0 format = %d\n",format
);
95 width
= h263_format
[format
][0];
96 height
= h263_format
[format
][1];
97 printf("%d x %d\n",width
,height
);
98 // if (!width) return -1;
100 printf("pict_type=%d\n",get_bits1(&s
->gb
));
101 printf("unrestricted_mv=%d\n",get_bits1(&s
->gb
));
103 printf("SAC: %d\n",get_bits1(&s
->gb
));
104 printf("advanced prediction mode: %d\n",get_bits1(&s
->gb
));
105 printf("PB frame: %d\n",get_bits1(&s
->gb
));
107 if (get_bits1(&s
->gb
) != 0)
108 return -1; /* SAC: off */
109 if (get_bits1(&s
->gb
) != 0)
110 return -1; /* advanced prediction mode: off */
111 if (get_bits1(&s
->gb
) != 0)
112 return -1; /* not PB frame */
114 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
115 skip_bits1(&s
->gb
); /* Continuous Presence Multipoint mode: off */
117 printf("h263_plus = 1\n");
119 if (get_bits(&s
->gb
, 3) != 1){
120 printf("H.263v2 A error\n");
123 if (get_bits(&s
->gb
, 3) != 6){ /* custom source format */
124 printf("custom source format\n");
127 skip_bits(&s
->gb
, 12);
128 skip_bits(&s
->gb
, 3);
129 printf("pict_type=%d\n",get_bits(&s
->gb
, 3) + 1);
130 // if (s->pict_type != I_TYPE &&
131 // s->pict_type != P_TYPE)
133 skip_bits(&s
->gb
, 7);
134 skip_bits(&s
->gb
, 4); /* aspect ratio */
135 width
= (get_bits(&s
->gb
, 9) + 1) * 4;
137 height
= get_bits(&s
->gb
, 9) * 4;
138 printf("%d x %d\n",width
,height
);
141 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
145 while (get_bits1(&s
->gb
) != 0) {
146 skip_bits(&s
->gb
, 8);
150 // s->height = height;
156 int main(int argc
,char ** argv
){
162 //unsigned char* buffer=malloc(0x200000);
168 // check if enough args were given
170 printf("Too few arguments given!\n"
171 "Usage: %s <input_file> <output_file>\n", argv
[0]);
176 if(!(f
=fopen(argv
[1],"rb"))){
177 printf("Couldn't open input file.\n");
181 if(!(f2
=fopen(argv
[2],"wb"))){
182 printf("Couldn't open output file.\n");
186 avi
=muxer_new_muxer(MUXER_TYPE_AVI
,f2
);
187 mux
=muxer_new_stream(avi
,MUXER_TYPE_VIDEO
);
189 mux
->buffer_size
=0x200000;
190 mux
->buffer
=malloc(mux
->buffer_size
);
195 mux
->bih
=malloc(sizeof(BITMAPINFOHEADER
));
196 mux
->bih
->biSize
=sizeof(BITMAPINFOHEADER
);
197 mux
->bih
->biPlanes
=1;
198 mux
->bih
->biBitCount
=24;
199 mux
->bih
->biCompression
=0x6f766976;// 7669766f;
200 muxer_write_header(avi
);
203 c=fgetc(f); if(c) printf("error! not vivo file?\n");
205 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
207 printf("hdr1: %d\n",len);
208 for(i=0;i<len;i++) fgetc(f);
211 while((c
=fgetc(f
))>=0){
213 printf("%08lX %02X\n",ftell(f
),c
);
220 printf("%08lX %02X\n",ftell(f
),c
);
226 while((c
=fgetc(f
))>=0x80) len
+=0x80*(c
&0x0F);
228 printf("header: 00 (%d)\n",len
);
229 for(i
=0;i
<len
;i
++) fgetc(f
);
236 if(prefix
) len
=fgetc(f
);
237 printf("audio: %02X (%d)\n",c
,len
);
238 for(i
=0;i
<len
;i
++) fgetc(f
);
244 if(prefix
) len
=fgetc(f
);
245 printf("audio: %02X (%d)\n",c
,len
);
246 for(i
=0;i
<len
;i
++) fgetc(f
);
249 if(flag2
|| (((c
&0xF0)==0x10 || (c
&0xF0)==0x20) && (c
&0x0F)!=(v_id
&0xF))){
251 printf("Frame size: %d\n",mux
->buffer_len
);
252 h263_decode_picture_header(mux
->buffer
);
253 muxer_write_chunk(mux
,mux
->buffer_len
,0x10, MP_NOPTS_VALUE
, MP_NOPTS_VALUE
);
256 if((v_id
&0xF0)==0x10) fprintf(stderr
,"hmm. last video packet %02X\n",v_id
);
262 if(prefix
) len
=fgetc(f
);
263 printf("video: %02X (%d)\n",c
,len
);
264 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
265 mux
->buffer_len
+=len
;
271 printf("video: %02X (%d)\n",c
,len
);
272 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
273 mux
->buffer_len
+=len
;
278 printf("error: %02X!\n",c
);
282 if(!width
) width
=320;
283 if(!height
) height
=240;
285 mux
->bih
->biWidth
=width
;
286 mux
->bih
->biHeight
=height
;
287 mux
->bih
->biSizeImage
=3*width
*height
;
289 muxer_write_index(avi
);
290 fseek(f2
,0,SEEK_SET
);
291 muxer_write_header(avi
);