Mercurial > mplayer.hg
annotate TOOLS/vivodump.c @ 12440:56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
author | reimar |
---|---|
date | Fri, 07 May 2004 16:12:30 +0000 |
parents | c671e9adbe22 |
children | 4277e06630bf |
rev | line source |
---|---|
2665 | 1 #include <stdio.h> |
2667 | 2 #include <stdlib.h> |
3 #include <string.h> | |
4 | |
5 #include "wine/mmreg.h" | |
6 #include "wine/avifmt.h" | |
7 #include "wine/vfw.h" | |
8 | |
8585 | 9 #include "muxer.h" |
2665 | 10 |
11 static const short h263_format[8][2] = { | |
12 { 0, 0 }, | |
13 { 128, 96 }, | |
14 { 176, 144 }, | |
15 { 352, 288 }, | |
16 { 704, 576 }, | |
17 { 1408, 1152 }, | |
2696 | 18 { 320, 240 } |
2665 | 19 }; |
20 | |
21 unsigned char* buffer; | |
22 int bufptr=0; | |
23 int bitcnt=0; | |
24 unsigned char buf=0; | |
25 | |
26 unsigned int x_get_bits(int n){ | |
27 unsigned int x=0; | |
28 while(n-->0){ | |
29 if(!bitcnt){ | |
30 // fill buff | |
31 buf=buffer[bufptr++]; | |
32 bitcnt=8; | |
33 } | |
34 //x=(x<<1)|(buf&1);buf>>=1; | |
35 x=(x<<1)|(buf>>7);buf<<=1; | |
36 --bitcnt; | |
37 } | |
38 return x; | |
39 } | |
40 | |
41 #define get_bits(xxx,n) x_get_bits(n) | |
42 #define get_bits1(xxx) x_get_bits(1) | |
43 #define skip_bits(xxx,n) x_get_bits(n) | |
44 #define skip_bits1(xxx) x_get_bits(1) | |
45 | |
2696 | 46 int format; |
47 int width=320; | |
48 int height=240; | |
2667 | 49 |
2665 | 50 /* most is hardcoded. should extend to handle all h263 streams */ |
51 int h263_decode_picture_header(unsigned char *b_ptr) | |
52 { | |
2696 | 53 int i; |
54 | |
55 for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); | |
2665 | 56 |
57 buffer=b_ptr; | |
58 bufptr=bitcnt=buf=0; | |
59 | |
60 /* picture header */ | |
2696 | 61 if (get_bits(&s->gb, 22) != 0x20){ |
62 printf("bad picture header\n"); | |
2665 | 63 return -1; |
2696 | 64 } |
2665 | 65 skip_bits(&s->gb, 8); /* picture timestamp */ |
66 | |
2696 | 67 if (get_bits1(&s->gb) != 1){ |
68 printf("bad marker\n"); | |
2665 | 69 return -1; /* marker */ |
2696 | 70 } |
71 if (get_bits1(&s->gb) != 0){ | |
72 printf("bad h263 id\n"); | |
2665 | 73 return -1; /* h263 id */ |
2696 | 74 } |
2665 | 75 skip_bits1(&s->gb); /* split screen off */ |
76 skip_bits1(&s->gb); /* camera off */ | |
77 skip_bits1(&s->gb); /* freeze picture release off */ | |
78 | |
79 format = get_bits(&s->gb, 3); | |
80 | |
81 if (format != 7) { | |
82 printf("h263_plus = 0 format = %d\n",format); | |
83 /* H.263v1 */ | |
84 width = h263_format[format][0]; | |
85 height = h263_format[format][1]; | |
86 printf("%d x %d\n",width,height); | |
2696 | 87 // if (!width) return -1; |
2665 | 88 |
89 printf("pict_type=%d\n",get_bits1(&s->gb)); | |
90 printf("unrestricted_mv=%d\n",get_bits1(&s->gb)); | |
91 #if 1 | |
92 printf("SAC: %d\n",get_bits1(&s->gb)); | |
93 printf("advanced prediction mode: %d\n",get_bits1(&s->gb)); | |
94 printf("PB frame: %d\n",get_bits1(&s->gb)); | |
95 #else | |
96 if (get_bits1(&s->gb) != 0) | |
97 return -1; /* SAC: off */ | |
98 if (get_bits1(&s->gb) != 0) | |
99 return -1; /* advanced prediction mode: off */ | |
100 if (get_bits1(&s->gb) != 0) | |
101 return -1; /* not PB frame */ | |
102 #endif | |
103 printf("qscale=%d\n",get_bits(&s->gb, 5)); | |
104 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
105 } else { | |
106 printf("h263_plus = 1\n"); | |
107 /* H.263v2 */ | |
2696 | 108 if (get_bits(&s->gb, 3) != 1){ |
109 printf("H.263v2 A error\n"); | |
2665 | 110 return -1; |
2696 | 111 } |
112 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
113 printf("custom source format\n"); | |
2665 | 114 return -1; |
2696 | 115 } |
2665 | 116 skip_bits(&s->gb, 12); |
117 skip_bits(&s->gb, 3); | |
118 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1); | |
119 // if (s->pict_type != I_TYPE && | |
120 // s->pict_type != P_TYPE) | |
121 // return -1; | |
122 skip_bits(&s->gb, 7); | |
123 skip_bits(&s->gb, 4); /* aspect ratio */ | |
124 width = (get_bits(&s->gb, 9) + 1) * 4; | |
125 skip_bits1(&s->gb); | |
126 height = get_bits(&s->gb, 9) * 4; | |
127 printf("%d x %d\n",width,height); | |
2696 | 128 //if (height == 0) |
129 // return -1; | |
2665 | 130 printf("qscale=%d\n",get_bits(&s->gb, 5)); |
131 } | |
132 | |
133 /* PEI */ | |
134 while (get_bits1(&s->gb) != 0) { | |
135 skip_bits(&s->gb, 8); | |
136 } | |
137 // s->f_code = 1; | |
138 // s->width = width; | |
139 // s->height = height; | |
140 return 0; | |
141 } | |
142 | |
2667 | 143 int postable[32768]; |
2665 | 144 |
145 int main(){ | |
146 int c; | |
147 unsigned int head=-1; | |
148 int pos=0; | |
2667 | 149 int frames=0; |
3233 | 150 FILE *f=fopen("paulvandykforanangel.viv","rb"); |
2696 | 151 FILE *f2=fopen("GB1.avi","wb"); |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
152 muxer_t* avi=muxer_new_muxer(MUXER_TYPE_AVI,f2); |
8585 | 153 muxer_stream_t* mux=muxer_new_stream(avi,MUXER_TYPE_VIDEO); |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
154 //unsigned char* buffer=malloc(0x200000); |
2696 | 155 int i,len; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
156 int v_id=0; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
157 int flag=0; |
2696 | 158 int flag2=0; |
3233 | 159 int prefix=0; |
2667 | 160 |
161 mux->buffer_size=0x200000; | |
162 mux->buffer=malloc(mux->buffer_size); | |
163 | |
164 mux->h.dwScale=1; | |
165 mux->h.dwRate=10; | |
2665 | 166 |
2667 | 167 mux->bih=malloc(sizeof(BITMAPINFOHEADER)); |
168 mux->bih->biSize=sizeof(BITMAPINFOHEADER); | |
169 mux->bih->biPlanes=1; | |
170 mux->bih->biBitCount=24; | |
171 mux->bih->biCompression=0x6f766976;// 7669766f; | |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
172 muxer_write_header(avi); |
2667 | 173 |
2696 | 174 /* |
175 c=fgetc(f); if(c) printf("error! not vivo file?\n"); | |
176 len=0; | |
177 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
178 len+=c; | |
179 printf("hdr1: %d\n",len); | |
180 for(i=0;i<len;i++) fgetc(f); | |
181 */ | |
182 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
183 while((c=fgetc(f))>=0){ |
2696 | 184 |
3233 | 185 printf("%08X %02X\n",ftell(f),c); |
186 | |
187 prefix=0; | |
188 if(c==0x82){ | |
189 prefix=1; | |
190 //continue; | |
191 c=fgetc(f); | |
192 printf("%08X %02X\n",ftell(f),c); | |
193 } | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
194 |
2696 | 195 if(c==0x00){ |
196 // header | |
197 int len=0; | |
198 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
199 len+=c; | |
200 printf("header: 00 (%d)\n",len); | |
201 for(i=0;i<len;i++) fgetc(f); | |
202 continue; | |
203 } | |
204 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
205 if((c&0xF0)==0x40){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
206 // audio |
3233 | 207 len=24; |
208 if(prefix) len=fgetc(f); | |
209 printf("audio: %02X (%d)\n",c,len); | |
210 for(i=0;i<len;i++) fgetc(f); | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
211 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
212 } |
2696 | 213 if((c&0xF0)==0x30){ |
214 // audio | |
3233 | 215 len=40; |
216 if(prefix) len=fgetc(f); | |
217 printf("audio: %02X (%d)\n",c,len); | |
218 for(i=0;i<len;i++) fgetc(f); | |
2696 | 219 continue; |
220 } | |
221 if(flag2 || (((c&0xF0)==0x10 || (c&0xF0)==0x20) && (c&0x0F)!=(v_id&0xF))){ | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
222 // end of frame: |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
223 printf("Frame size: %d\n",mux->buffer_len); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
224 h263_decode_picture_header(mux->buffer); |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
225 muxer_write_chunk(mux,mux->buffer_len,0x10); |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
226 mux->buffer_len=0; |
2696 | 227 |
228 if((v_id&0xF0)==0x10) fprintf(stderr,"hmm. last video packet %02X\n",v_id); | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
229 } |
2696 | 230 flag2=0; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
231 if((c&0xF0)==0x10){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
232 // 128 byte |
3233 | 233 len=128; |
234 if(prefix) len=fgetc(f); | |
235 printf("video: %02X (%d)\n",c,len); | |
236 fread(mux->buffer+mux->buffer_len,len,1,f); | |
237 mux->buffer_len+=len; | |
238 v_id=c; | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
239 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
240 } |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
241 if((c&0xF0)==0x20){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
242 int len=fgetc(f); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
243 printf("video: %02X (%d)\n",c,len); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
244 fread(mux->buffer+mux->buffer_len,len,1,f); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
245 mux->buffer_len+=len; |
2696 | 246 flag2=1; |
3233 | 247 v_id=c; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
248 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
249 } |
2696 | 250 printf("error: %02X!\n",c); |
3233 | 251 exit(1); |
2665 | 252 } |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
253 |
2696 | 254 if(!width) width=320; |
255 if(!height) height=240; | |
256 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
257 mux->bih->biWidth=width; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
258 mux->bih->biHeight=height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
259 mux->bih->biSizeImage=3*width*height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
260 |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
261 muxer_write_index(avi); |
2667 | 262 fseek(f2,0,SEEK_SET); |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
263 muxer_write_header(avi); |
2667 | 264 |
265 } |