Mercurial > mplayer.hg
annotate TOOLS/vivodump.c @ 26704:41f8ba327cf5
Add license headers to av_opts
author | reimar |
---|---|
date | Sun, 11 May 2008 12:47:52 +0000 |
parents | 0abcf0f3d845 |
children | 8825552ee585 |
rev | line source |
---|---|
2665 | 1 #include <stdio.h> |
2667 | 2 #include <stdlib.h> |
3 #include <string.h> | |
13783 | 4 #include <inttypes.h> |
2667 | 5 |
13783 | 6 #include "loader/wine/mmreg.h" |
7 #include "loader/wine/vfw.h" | |
8 | |
22627 | 9 #include "stream/stream.h" |
13783 | 10 #include "libmpdemux/muxer.h" |
22627 | 11 #include "libmpdemux/demuxer.h" |
2667 | 12 |
13783 | 13 char *info_name; |
14 char *info_artist; | |
15 char *info_genre; | |
16 char *info_subject; | |
17 char *info_copyright; | |
18 char *info_sourceform; | |
19 char *info_comment; | |
2665 | 20 |
21 static const short h263_format[8][2] = { | |
22 { 0, 0 }, | |
23 { 128, 96 }, | |
24 { 176, 144 }, | |
25 { 352, 288 }, | |
26 { 704, 576 }, | |
27 { 1408, 1152 }, | |
2696 | 28 { 320, 240 } |
2665 | 29 }; |
30 | |
31 unsigned char* buffer; | |
32 int bufptr=0; | |
33 int bitcnt=0; | |
34 unsigned char buf=0; | |
35 | |
26575
1ca484e74f18
Mark all functions that are only used within the file as static.
diego
parents:
25309
diff
changeset
|
36 static unsigned int x_get_bits(int n){ |
2665 | 37 unsigned int x=0; |
38 while(n-->0){ | |
39 if(!bitcnt){ | |
40 // fill buff | |
41 buf=buffer[bufptr++]; | |
42 bitcnt=8; | |
43 } | |
44 //x=(x<<1)|(buf&1);buf>>=1; | |
45 x=(x<<1)|(buf>>7);buf<<=1; | |
46 --bitcnt; | |
47 } | |
48 return x; | |
49 } | |
50 | |
51 #define get_bits(xxx,n) x_get_bits(n) | |
52 #define get_bits1(xxx) x_get_bits(1) | |
53 #define skip_bits(xxx,n) x_get_bits(n) | |
54 #define skip_bits1(xxx) x_get_bits(1) | |
55 | |
2696 | 56 int format; |
57 int width=320; | |
58 int height=240; | |
2667 | 59 |
2665 | 60 /* 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
|
61 static int h263_decode_picture_header(unsigned char *b_ptr) |
2665 | 62 { |
2696 | 63 int i; |
64 | |
65 for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); | |
2665 | 66 |
67 buffer=b_ptr; | |
68 bufptr=bitcnt=buf=0; | |
69 | |
70 /* picture header */ | |
2696 | 71 if (get_bits(&s->gb, 22) != 0x20){ |
72 printf("bad picture header\n"); | |
2665 | 73 return -1; |
2696 | 74 } |
2665 | 75 skip_bits(&s->gb, 8); /* picture timestamp */ |
76 | |
2696 | 77 if (get_bits1(&s->gb) != 1){ |
78 printf("bad marker\n"); | |
2665 | 79 return -1; /* marker */ |
2696 | 80 } |
81 if (get_bits1(&s->gb) != 0){ | |
82 printf("bad h263 id\n"); | |
2665 | 83 return -1; /* h263 id */ |
2696 | 84 } |
2665 | 85 skip_bits1(&s->gb); /* split screen off */ |
86 skip_bits1(&s->gb); /* camera off */ | |
87 skip_bits1(&s->gb); /* freeze picture release off */ | |
88 | |
89 format = get_bits(&s->gb, 3); | |
90 | |
91 if (format != 7) { | |
92 printf("h263_plus = 0 format = %d\n",format); | |
93 /* H.263v1 */ | |
94 width = h263_format[format][0]; | |
95 height = h263_format[format][1]; | |
96 printf("%d x %d\n",width,height); | |
2696 | 97 // if (!width) return -1; |
2665 | 98 |
99 printf("pict_type=%d\n",get_bits1(&s->gb)); | |
100 printf("unrestricted_mv=%d\n",get_bits1(&s->gb)); | |
101 #if 1 | |
102 printf("SAC: %d\n",get_bits1(&s->gb)); | |
103 printf("advanced prediction mode: %d\n",get_bits1(&s->gb)); | |
104 printf("PB frame: %d\n",get_bits1(&s->gb)); | |
105 #else | |
106 if (get_bits1(&s->gb) != 0) | |
107 return -1; /* SAC: off */ | |
108 if (get_bits1(&s->gb) != 0) | |
109 return -1; /* advanced prediction mode: off */ | |
110 if (get_bits1(&s->gb) != 0) | |
111 return -1; /* not PB frame */ | |
112 #endif | |
113 printf("qscale=%d\n",get_bits(&s->gb, 5)); | |
114 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
115 } else { | |
116 printf("h263_plus = 1\n"); | |
117 /* H.263v2 */ | |
2696 | 118 if (get_bits(&s->gb, 3) != 1){ |
119 printf("H.263v2 A error\n"); | |
2665 | 120 return -1; |
2696 | 121 } |
122 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
123 printf("custom source format\n"); | |
2665 | 124 return -1; |
2696 | 125 } |
2665 | 126 skip_bits(&s->gb, 12); |
127 skip_bits(&s->gb, 3); | |
128 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1); | |
129 // if (s->pict_type != I_TYPE && | |
130 // s->pict_type != P_TYPE) | |
131 // return -1; | |
132 skip_bits(&s->gb, 7); | |
133 skip_bits(&s->gb, 4); /* aspect ratio */ | |
134 width = (get_bits(&s->gb, 9) + 1) * 4; | |
135 skip_bits1(&s->gb); | |
136 height = get_bits(&s->gb, 9) * 4; | |
137 printf("%d x %d\n",width,height); | |
2696 | 138 //if (height == 0) |
139 // return -1; | |
2665 | 140 printf("qscale=%d\n",get_bits(&s->gb, 5)); |
141 } | |
142 | |
143 /* PEI */ | |
144 while (get_bits1(&s->gb) != 0) { | |
145 skip_bits(&s->gb, 8); | |
146 } | |
147 // s->f_code = 1; | |
148 // s->width = width; | |
149 // s->height = height; | |
150 return 0; | |
151 } | |
152 | |
2667 | 153 int postable[32768]; |
2665 | 154 |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
155 int main(int argc,char ** argv){ |
2665 | 156 int c; |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
157 FILE *f; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
158 FILE *f2; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
159 muxer_t* avi; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
160 muxer_stream_t* mux; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
161 //unsigned char* buffer=malloc(0x200000); |
2696 | 162 int i,len; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
163 int v_id=0; |
2696 | 164 int flag2=0; |
3233 | 165 int prefix=0; |
2667 | 166 |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
167 // check if enough args were given |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
168 if ( argc < 3 ){ |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
169 printf("Too few arguments given!\n" |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
170 "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
|
171 |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
172 return -1; |
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
173 } |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
174 // input |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
175 if(!(f=fopen(argv[1],"rb"))){ |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
176 printf("Couldn't open input file.\n"); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
177 return -1; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
178 } |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
179 // output |
13801
245f5d4b4af7
Fixed the assumption user will always give 2+ args to the program.
al
parents:
13784
diff
changeset
|
180 if(!(f2=fopen(argv[2],"wb"))){ |
13784
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
181 printf("Couldn't open output file.\n"); |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
182 return -1; |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
183 } |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
184 |
7d3b84ddd2fd
Remove hardcoded filenames in favor of command line parameters, some error
diego
parents:
13783
diff
changeset
|
185 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
|
186 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
|
187 |
2667 | 188 mux->buffer_size=0x200000; |
189 mux->buffer=malloc(mux->buffer_size); | |
190 | |
191 mux->h.dwScale=1; | |
192 mux->h.dwRate=10; | |
2665 | 193 |
2667 | 194 mux->bih=malloc(sizeof(BITMAPINFOHEADER)); |
195 mux->bih->biSize=sizeof(BITMAPINFOHEADER); | |
196 mux->bih->biPlanes=1; | |
197 mux->bih->biBitCount=24; | |
198 mux->bih->biCompression=0x6f766976;// 7669766f; | |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
199 muxer_write_header(avi); |
2667 | 200 |
2696 | 201 /* |
202 c=fgetc(f); if(c) printf("error! not vivo file?\n"); | |
203 len=0; | |
204 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
205 len+=c; | |
206 printf("hdr1: %d\n",len); | |
207 for(i=0;i<len;i++) fgetc(f); | |
208 */ | |
209 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
210 while((c=fgetc(f))>=0){ |
2696 | 211 |
25309
8e73e469970c
Fix printf format string length modifiers, removes the warnings:
diego
parents:
24203
diff
changeset
|
212 printf("%08lX %02X\n",ftell(f),c); |
3233 | 213 |
214 prefix=0; | |
215 if(c==0x82){ | |
216 prefix=1; | |
217 //continue; | |
218 c=fgetc(f); | |
25309
8e73e469970c
Fix printf format string length modifiers, removes the warnings:
diego
parents:
24203
diff
changeset
|
219 printf("%08lX %02X\n",ftell(f),c); |
3233 | 220 } |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
221 |
2696 | 222 if(c==0x00){ |
223 // header | |
224 int len=0; | |
225 while((c=fgetc(f))>=0x80) len+=0x80*(c&0x0F); | |
226 len+=c; | |
227 printf("header: 00 (%d)\n",len); | |
228 for(i=0;i<len;i++) fgetc(f); | |
229 continue; | |
230 } | |
231 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
232 if((c&0xF0)==0x40){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
233 // audio |
3233 | 234 len=24; |
235 if(prefix) len=fgetc(f); | |
236 printf("audio: %02X (%d)\n",c,len); | |
237 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
|
238 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
239 } |
2696 | 240 if((c&0xF0)==0x30){ |
241 // audio | |
3233 | 242 len=40; |
243 if(prefix) len=fgetc(f); | |
244 printf("audio: %02X (%d)\n",c,len); | |
245 for(i=0;i<len;i++) fgetc(f); | |
2696 | 246 continue; |
247 } | |
248 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
|
249 // end of frame: |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 mux->buffer_len=0; |
2696 | 254 |
255 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
|
256 } |
2696 | 257 flag2=0; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
258 if((c&0xF0)==0x10){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
259 // 128 byte |
3233 | 260 len=128; |
261 if(prefix) len=fgetc(f); | |
262 printf("video: %02X (%d)\n",c,len); | |
263 fread(mux->buffer+mux->buffer_len,len,1,f); | |
264 mux->buffer_len+=len; | |
265 v_id=c; | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
266 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
267 } |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
268 if((c&0xF0)==0x20){ |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
269 int len=fgetc(f); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
270 printf("video: %02X (%d)\n",c,len); |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
271 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
|
272 mux->buffer_len+=len; |
2696 | 273 flag2=1; |
3233 | 274 v_id=c; |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
275 continue; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
276 } |
2696 | 277 printf("error: %02X!\n",c); |
3233 | 278 exit(1); |
2665 | 279 } |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
280 |
2696 | 281 if(!width) width=320; |
282 if(!height) height=240; | |
283 | |
2672
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
284 mux->bih->biWidth=width; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
285 mux->bih->biHeight=height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
286 mux->bih->biSizeImage=3*width*height; |
1ff47e4ff44d
works! copy video steram to .avi file playable with ivvideo.dll
arpi
parents:
2667
diff
changeset
|
287 |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
288 muxer_write_index(avi); |
2667 | 289 fseek(f2,0,SEEK_SET); |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8585
diff
changeset
|
290 muxer_write_header(avi); |
2667 | 291 |
24203 | 292 return 0; |
2667 | 293 } |