| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#ifdef _WIN32 |
| 4 |
#include <windows.h> |
| 5 |
#else |
| 6 |
typedef long DWORD; |
| 7 |
#endif |
| 8 |
|
| 9 |
/*extremely crude app to dump vp3 frames from an avi file*/ |
| 10 |
/*filenames are hardcoded*/ |
| 11 |
|
| 12 |
#include "avilib.h" |
| 13 |
|
| 14 |
int main(int argc, const char **argv) |
| 15 |
{ |
| 16 |
|
| 17 |
FILE * f = fopen("outfile.vp3", "wb"); |
| 18 |
|
| 19 |
char * buffer; |
| 20 |
int olength; |
| 21 |
int length; |
| 22 |
avi_t *avifile; |
| 23 |
int chunksize; |
| 24 |
int frame; |
| 25 |
int frames; |
| 26 |
int keyframegap = 0; |
| 27 |
int maxkeyframegap = 0; |
| 28 |
|
| 29 |
DWORD initialticks; |
| 30 |
|
| 31 |
int framew = 0; |
| 32 |
int frameh = 0; |
| 33 |
double framerate = 0.0f; |
| 34 |
double fps_numerator, fps_denominator; |
| 35 |
|
| 36 |
avifile = AVI_open_input_file("vp31.avi", 1); |
| 37 |
frames = AVI_video_frames(avifile); |
| 38 |
framew = AVI_video_width(avifile); |
| 39 |
frameh = AVI_video_height(avifile); |
| 40 |
framerate = AVI_frame_rate(avifile); |
| 41 |
chunksize = AVI_max_video_chunk(avifile); |
| 42 |
/* avilib only reports the max video chunk size if the file has an |
| 43 |
idx table. We fall back to an arbitrary limit otherwise. Better |
| 44 |
would be just to handle the chunks dynamically */ |
| 45 |
if (chunksize <= 0) chunksize = 131072; |
| 46 |
buffer = malloc(chunksize); |
| 47 |
printf("Frames(%d) Video(%dx%d) %3.2f fps\n",frames,framew, frameh,framerate); |
| 48 |
printf("Video Compressor: %s", AVI_video_compressor(avifile)); |
| 49 |
fps_denominator = 1000000.0F; |
| 50 |
fps_numerator = framerate * fps_denominator; |
| 51 |
|
| 52 |
sprintf(buffer,"AVI2VP31R W%d H%d F%.0f:%.0f Ip A0:0\n", framew, frameh, fps_numerator, fps_denominator); |
| 53 |
fwrite(buffer, strlen(buffer), 1, f); |
| 54 |
|
| 55 |
for (frame = 0; frame < frames;) { |
| 56 |
int keyframe; |
| 57 |
olength = length; |
| 58 |
length = AVI_frame_size(avifile, frame++); |
| 59 |
if( !length ) { |
| 60 |
length = olength; |
| 61 |
} |
| 62 |
AVI_read_frame(avifile, (char *) buffer, &keyframe); |
| 63 |
fwrite("FRAME\n", 6, 1, f); |
| 64 |
fwrite(&length, sizeof(int), 1, f); |
| 65 |
fwrite(&keyframe, sizeof(int), 1, f); |
| 66 |
printf("Frame size(%d) IsKeyframe(%d)\n", length, keyframe); |
| 67 |
fwrite(buffer, 1, length, f); |
| 68 |
if (!keyframe){ |
| 69 |
keyframegap++; |
| 70 |
} else { |
| 71 |
if (keyframegap>maxkeyframegap) maxkeyframegap=keyframegap; |
| 72 |
keyframegap = 0; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
fclose(f); |
| 77 |
printf("Max keyframegap (%d)\n", maxkeyframegap); |
| 78 |
|
| 79 |
free(buffer); |
| 80 |
|
| 81 |
exit(0); |
| 82 |
} |