2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write to the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "loader/wine/mmreg.h"
23 #include "loader/wine/vfw.h"
25 #include "stream/stream.h"
26 #include "libmpdemux/muxer.h"
27 #include "libmpdemux/demuxer.h"
35 char *info_sourceform
;
38 char* out_filename
= NULL
;
39 char* force_fourcc
=NULL
;
40 char* passtmpfile
="divx2pass.log";
42 static const short h263_format
[8][2] = {
52 unsigned char* buffer
;
57 static unsigned int x_get_bits(int n
){
65 //x=(x<<1)|(buf&1);buf>>=1;
66 x
=(x
<<1)|(buf
>>7);buf
<<=1;
72 #define get_bits(xxx,n) x_get_bits(n)
73 #define get_bits1(xxx) x_get_bits(1)
74 #define skip_bits(xxx,n) x_get_bits(n)
75 #define skip_bits1(xxx) x_get_bits(1)
81 /* most is hardcoded. should extend to handle all h263 streams */
82 static int h263_decode_picture_header(unsigned char *b_ptr
)
86 for(i
=0;i
<16;i
++) printf(" %02X",b_ptr
[i
]); printf("\n");
92 if (get_bits(&s
->gb
, 22) != 0x20){
93 printf("bad picture header\n");
96 skip_bits(&s
->gb
, 8); /* picture timestamp */
98 if (get_bits1(&s
->gb
) != 1){
99 printf("bad marker\n");
100 return -1; /* marker */
102 if (get_bits1(&s
->gb
) != 0){
103 printf("bad h263 id\n");
104 return -1; /* h263 id */
106 skip_bits1(&s
->gb
); /* split screen off */
107 skip_bits1(&s
->gb
); /* camera off */
108 skip_bits1(&s
->gb
); /* freeze picture release off */
110 format
= get_bits(&s
->gb
, 3);
113 printf("h263_plus = 0 format = %d\n",format
);
115 width
= h263_format
[format
][0];
116 height
= h263_format
[format
][1];
117 printf("%d x %d\n",width
,height
);
118 // if (!width) return -1;
120 printf("pict_type=%d\n",get_bits1(&s
->gb
));
121 printf("unrestricted_mv=%d\n",get_bits1(&s
->gb
));
123 printf("SAC: %d\n",get_bits1(&s
->gb
));
124 printf("advanced prediction mode: %d\n",get_bits1(&s
->gb
));
125 printf("PB frame: %d\n",get_bits1(&s
->gb
));
127 if (get_bits1(&s
->gb
) != 0)
128 return -1; /* SAC: off */
129 if (get_bits1(&s
->gb
) != 0)
130 return -1; /* advanced prediction mode: off */
131 if (get_bits1(&s
->gb
) != 0)
132 return -1; /* not PB frame */
134 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
135 skip_bits1(&s
->gb
); /* Continuous Presence Multipoint mode: off */
137 printf("h263_plus = 1\n");
139 if (get_bits(&s
->gb
, 3) != 1){
140 printf("H.263v2 A error\n");
143 if (get_bits(&s
->gb
, 3) != 6){ /* custom source format */
144 printf("custom source format\n");
147 skip_bits(&s
->gb
, 12);
148 skip_bits(&s
->gb
, 3);
149 printf("pict_type=%d\n",get_bits(&s
->gb
, 3) + 1);
150 // if (s->pict_type != I_TYPE &&
151 // s->pict_type != P_TYPE)
153 skip_bits(&s
->gb
, 7);
154 skip_bits(&s
->gb
, 4); /* aspect ratio */
155 width
= (get_bits(&s
->gb
, 9) + 1) * 4;
157 height
= get_bits(&s
->gb
, 9) * 4;
158 printf("%d x %d\n",width
,height
);
161 printf("qscale=%d\n",get_bits(&s
->gb
, 5));
165 while (get_bits1(&s
->gb
) != 0) {
166 skip_bits(&s
->gb
, 8);
170 // s->height = height;
176 int main(int argc
,char ** argv
){
182 //unsigned char* buffer=malloc(0x200000);
188 // check if enough args were given
190 printf("Too few arguments given!\n"
191 "Usage: %s <input_file> <output_file>\n", argv
[0]);
196 if(!(f
=fopen(argv
[1],"rb"))){
197 printf("Couldn't open input file.\n");
201 if(!(f2
=fopen(argv
[2],"wb"))){
202 printf("Couldn't open output file.\n");
206 avi
=muxer_new_muxer(MUXER_TYPE_AVI
,f2
);
207 mux
=muxer_new_stream(avi
,MUXER_TYPE_VIDEO
);
209 mux
->buffer_size
=0x200000;
210 mux
->buffer
=malloc(mux
->buffer_size
);
215 mux
->bih
=malloc(sizeof(BITMAPINFOHEADER
));
216 mux
->bih
->biSize
=sizeof(BITMAPINFOHEADER
);
217 mux
->bih
->biPlanes
=1;
218 mux
->bih
->biBitCount
=24;
219 mux
->bih
->biCompression
=0x6f766976;// 7669766f;
220 muxer_write_header(avi
);
223 c=fgetc(f); if(c) printf("error! not vivo file?\n");
225 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F);
227 printf("hdr1: %d\n",len);
228 for(i=0;i<len;i++) fgetc(f);
231 while((c
=fgetc(f
))>=0){
233 printf("%08lX %02X\n",ftell(f
),c
);
240 printf("%08lX %02X\n",ftell(f
),c
);
246 while((c
=fgetc(f
))>=0x80) len
+=0x80*(c
&0x0F);
248 printf("header: 00 (%d)\n",len
);
249 for(i
=0;i
<len
;i
++) fgetc(f
);
256 if(prefix
) len
=fgetc(f
);
257 printf("audio: %02X (%d)\n",c
,len
);
258 for(i
=0;i
<len
;i
++) fgetc(f
);
264 if(prefix
) len
=fgetc(f
);
265 printf("audio: %02X (%d)\n",c
,len
);
266 for(i
=0;i
<len
;i
++) fgetc(f
);
269 if(flag2
|| (((c
&0xF0)==0x10 || (c
&0xF0)==0x20) && (c
&0x0F)!=(v_id
&0xF))){
271 printf("Frame size: %d\n",mux
->buffer_len
);
272 h263_decode_picture_header(mux
->buffer
);
273 muxer_write_chunk(mux
,mux
->buffer_len
,0x10, MP_NOPTS_VALUE
, MP_NOPTS_VALUE
);
276 if((v_id
&0xF0)==0x10) fprintf(stderr
,"hmm. last video packet %02X\n",v_id
);
282 if(prefix
) len
=fgetc(f
);
283 printf("video: %02X (%d)\n",c
,len
);
284 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
285 mux
->buffer_len
+=len
;
291 printf("video: %02X (%d)\n",c
,len
);
292 fread(mux
->buffer
+mux
->buffer_len
,len
,1,f
);
293 mux
->buffer_len
+=len
;
298 printf("error: %02X!\n",c
);
302 if(!width
) width
=320;
303 if(!height
) height
=240;
305 mux
->bih
->biWidth
=width
;
306 mux
->bih
->biHeight
=height
;
307 mux
->bih
->biSizeImage
=3*width
*height
;
309 muxer_write_index(avi
);
310 fseek(f2
,0,SEEK_SET
);
311 muxer_write_header(avi
);