Mercurial > mplayer.hg
annotate TOOLS/vivodump.c @ 32459:1a605463f62b
Move vobsub.[ch] and unrar_exec.[ch] to the sub directory.
author | cigaes |
---|---|
date | Wed, 27 Oct 2010 16:58:23 +0000 |
parents | a86413775fbe |
children |
rev | line source |
---|---|
30416
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
1 /* |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
2 * This program is free software; you can redistribute it and/or modify |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
3 * it under the terms of the GNU General Public License as published by |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
4 * the Free Software Foundation; either version 2 of the License, or |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
5 * (at your option) any later version. |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
6 * |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
7 * This program is distributed in the hope that it will be useful, |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
10 * GNU General Public License for more details. |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
11 * |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
12 * You should have received a copy of the GNU General Public License along |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
13 * with this program; if not, write to the Free Software Foundation, Inc., |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
15 */ |
b573c7c7173b
Add standard license header to C tools missing them.
diego
parents:
29263
diff
changeset
|
16 |
2665 | 17 #include <stdio.h> |
2667 | 18 #include <stdlib.h> |
19 #include <string.h> | |
13783 | 20 #include <inttypes.h> |
2667 | 21 |
13783 | 22 #include "loader/wine/mmreg.h" |
23 #include "loader/wine/vfw.h" | |
24 | |
22627 | 25 #include "stream/stream.h" |
13783 | 26 #include "libmpdemux/muxer.h" |
22627 | 27 #include "libmpdemux/demuxer.h" |
2667 | 28 |
26963
8825552ee585
Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents:
26580
diff
changeset
|
29 /* linking hacks */ |
13783 | 30 char *info_name; |
31 char *info_artist; | |
32 char *info_genre; | |
33 char *info_subject; | |
34 char *info_copyright; | |
35 char *info_sourceform; | |
36 char *info_comment; | |
2665 | 37 |
26963
8825552ee585
Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents:
26580
diff
changeset
|
38 char* out_filename = NULL; |
8825552ee585
Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents:
26580
diff
changeset
|
39 char* force_fourcc=NULL; |
8825552ee585
Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents:
26580
diff
changeset
|
40 char* passtmpfile="divx2pass.log"; |
8825552ee585
Fix the linking of TOOLS/netstream and TOOLS/vivodump.
diego
parents:
26580
diff
changeset
|
41 |
2665 | 42 static const short h263_format[8][2] = { |
43 { 0, 0 }, | |
44 { 128, 96 }, | |
45 { 176, 144 }, | |
46 { 352, 288 }, | |
47 { 704, 576 }, | |
48 { 1408, 1152 }, | |
2696 | 49 { 320, 240 } |
2665 | 50 }; |
51 | |
52 unsigned char* buffer; | |
53 int bufptr=0; | |
54 int bitcnt=0; | |
55 unsigned char buf=0; | |
56 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
25309
diff
changeset
|
57 static unsigned int x_get_bits(int n){ |
2665 | 58 unsigned int x=0; |
59 while(n-->0){ | |
60 if(!bitcnt){ | |
61 // fill buff | |
62 buf=buffer[bufptr++]; | |
63 bitcnt=8; | |
64 } | |
65 //x=(x<<1)|(buf&1);buf>>=1; | |
66 x=(x<<1)|(buf>>7);buf<<=1; | |
67 --bitcnt; | |
68 } | |
69 return x; | |
70 } | |
71 | |
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) | |
76 | |
2696 | 77 int format; |
78 int width=320; | |
79 int height=240; | |
2667 | 80 |
2665 | 81 /* most is hardcoded. should extend to handle all h263 streams */ |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
25309
diff
changeset
|
82 static int h263_decode_picture_header(unsigned char *b_ptr) |
2665 | 83 { |
2696 | 84 int i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26963
diff
changeset
|
85 |
2696 | 86 for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26963
diff
changeset
|
87 |
2665 | 88 buffer=b_ptr; |
89 bufptr=bitcnt=buf=0; | |
90 | |
91 /* picture header */ | |
2696 | 92 if (get_bits(&s->gb, 22) != 0x20){ |
93 printf("bad picture header\n"); | |
2665 | 94 return -1; |
2696 | 95 } |
2665 | 96 skip_bits(&s->gb, 8); /* picture timestamp */ |
97 | |
2696 | 98 if (get_bits1(&s->gb) != 1){ |
99 printf("bad marker\n"); | |
2665 | 100 return -1; /* marker */ |
2696 | 101 } |
102 if (get_bits1(&s->gb) != 0){ | |
103 printf("bad h263 id\n"); | |
2665 | 104 return -1; /* h263 id */ |
2696 | 105 } |
2665 | 106 skip_bits1(&s->gb); /* split screen off */ |
107 skip_bits1(&s->gb); /* camera off */ | |
108 skip_bits1(&s->gb); /* freeze picture release off */ | |
109 | |
110 format = get_bits(&s->gb, 3); | |
111 | |
112 if (format != 7) { | |
113 printf("h263_plus = 0 format = %d\n",format); | |
114 /* H.263v1 */ | |
115 width = h263_format[format][0]; | |
116 height = h263_format[format][1]; | |
117 printf("%d x %d\n",width,height); | |
2696 | 118 // if (!width) return -1; |
2665 | 119 |
120 printf("pict_type=%d\n",get_bits1(&s->gb)); | |
121 printf("unrestricted_mv=%d\n",get_bits1(&s->gb)); | |
122 #if 1 | |
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)); | |
126 #else | |
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 */ | |
133 #endif | |
134 printf("qscale=%d\n",get_bits(&s->gb, 5)); | |
135 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
136 } else { | |
137 printf("h263_plus = 1\n"); | |
138 /* H.263v2 */ | |
2696 | 139 if (get_bits(&s->gb, 3) != 1){ |
140 printf("H.263v2 A error\n"); | |
2665 | 141 return -1; |
2696 | 142 } |
143 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
144 printf("custom source format\n"); | |
2665 | 145 return -1; |
2696 | 146 } |
2665 | 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) | |
152 // return -1; | |
153 skip_bits(&s->gb, 7); | |
154 skip_bits(&s->gb, 4); /* aspect ratio */ | |
155 width = (get_bits(&s->gb, 9) + 1) * 4; | |
156 skip_bits1(&s->gb); | |
157 height = get_bits(&s->gb, 9) * 4; | |
158 printf("%d x %d\n",width,height); | |
2696 | 159 //if (height == 0) |
160 // return -1; | |
2665 | 161 printf("qscale=%d\n",get_bits(&s->gb, 5)); |
162 } | |
163 | |
164 /* PEI */ | |
165 while (get_bits1(&s->gb) != 0) { | |
166 skip_bits(&s->gb, 8); | |
167 } | |
168 // s->f_code = 1; | |
169 // s->width = width; | |
170 // s->height = height; | |
171 return 0; | |
172 } | |
173 | |
2667 | 174 int postable[32768]; |
2665 | 175 |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
176 int main(int argc,char ** argv){ |
2665 | 177 int c; |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
178 FILE *f; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
179 FILE *f2; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
180 muxer_t* avi; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
181 muxer_stream_t* mux; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
182 //unsigned char* buffer=malloc(0x200000); |
2696 | 183 int i,len; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
184 int v_id=0; |
2696 | 185 int flag2=0; |
3233 | 186 int prefix=0; |
2667 | 187 |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
188 // check if enough args were given |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
189 if ( argc < 3 ){ |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
190 printf("Too few arguments given!\n" |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
191 "Usage: %s <input_file> <output_file>\n", argv[0]); |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
192 |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
193 return -1; |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
194 } |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
195 // input |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
196 if(!(f=fopen(argv[1],"rb"))){ |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
197 printf("Couldn't open input file.\n"); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
198 return -1; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
199 } |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
200 // output |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
201 if(!(f2=fopen(argv[2],"wb"))){ |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
202 printf("Couldn't open output file.\n"); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
203 return -1; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
204 } |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
205 |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
206 avi=muxer_new_muxer(MUXER_TYPE_AVI,f2); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
207 mux=muxer_new_stream(avi,MUXER_TYPE_VIDEO); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
208 |
2667 | 209 mux->buffer_size=0x200000; |
210 mux->buffer=malloc(mux->buffer_size); | |
211 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26963
diff
changeset
|
212 mux->h.dwScale=1; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26963
diff
changeset
|
213 mux->h.dwRate=10; |
2665 | 214 |
32123 | 215 mux->bih=malloc(sizeof(*mux->bih)); |
216 mux->bih->biSize=sizeof(*mux->bih); | |
2667 | 217 mux->bih->biPlanes=1; |
218 mux->bih->biBitCount=24; | |
219 mux->bih->biCompression=0x6f766976;// 7669766f; | |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
220 muxer_write_header(avi); |
2667 | 221 |
2696 | 222 /* |
223 c=fgetc(f); if(c) printf("error! not vivo file?\n"); | |
224 len=0; | |
225 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
226 len+=c; | |
227 printf("hdr1: %d\n",len); | |
228 for(i=0;i<len;i++) fgetc(f); | |
229 */ | |
230 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
231 while((c=fgetc(f))>=0){ |
2696 | 232 |
25309
8e73e469970c
Fix printf format string length modifiers, removes the warnings:
diego
parents:
24203
diff
changeset
|
233 printf("%08lX %02X\n",ftell(f),c); |
3233 | 234 |
235 prefix=0; | |
236 if(c==0x82){ | |
237 prefix=1; | |
238 //continue; | |
239 c=fgetc(f); | |
25309
8e73e469970c
Fix printf format string length modifiers, removes the warnings:
diego
parents:
24203
diff
changeset
|
240 printf("%08lX %02X\n",ftell(f),c); |
3233 | 241 } |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
242 |
2696 | 243 if(c==0x00){ |
244 // header | |
245 int len=0; | |
246 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
247 len+=c; | |
248 printf("header: 00 (%d)\n",len); | |
249 for(i=0;i<len;i++) fgetc(f); | |
250 continue; | |
251 } | |
252 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
253 if((c&0xF0)==0x40){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
254 // audio |
3233 | 255 len=24; |
256 if(prefix) len=fgetc(f); | |
257 printf("audio: %02X (%d)\n",c,len); | |
258 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
|
259 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
260 } |
2696 | 261 if((c&0xF0)==0x30){ |
262 // audio | |
3233 | 263 len=40; |
264 if(prefix) len=fgetc(f); | |
265 printf("audio: %02X (%d)\n",c,len); | |
266 for(i=0;i<len;i++) fgetc(f); | |
2696 | 267 continue; |
268 } | |
269 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
|
270 // end of frame: |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
271 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
|
272 h263_decode_picture_header(mux->buffer); |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
13801
diff
changeset
|
273 muxer_write_chunk(mux,mux->buffer_len,0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE); |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
274 mux->buffer_len=0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26963
diff
changeset
|
275 |
2696 | 276 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
|
277 } |
2696 | 278 flag2=0; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
279 if((c&0xF0)==0x10){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
280 // 128 byte |
3233 | 281 len=128; |
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; | |
286 v_id=c; | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
287 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
288 } |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
289 if((c&0xF0)==0x20){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
290 int len=fgetc(f); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
291 printf("video: %02X (%d)\n",c,len); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
292 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
|
293 mux->buffer_len+=len; |
2696 | 294 flag2=1; |
3233 | 295 v_id=c; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
296 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
297 } |
2696 | 298 printf("error: %02X!\n",c); |
3233 | 299 exit(1); |
2665 | 300 } |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
301 |
2696 | 302 if(!width) width=320; |
303 if(!height) height=240; | |
304 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
305 mux->bih->biWidth=width; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
306 mux->bih->biHeight=height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
307 mux->bih->biSizeImage=3*width*height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
308 |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
309 muxer_write_index(avi); |
2667 | 310 fseek(f2,0,SEEK_SET); |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
311 muxer_write_header(avi); |
2667 | 312 |
24203 | 313 return 0; |
2667 | 314 } |