static void *open_avi(const char *filename, movie_info *info) { const avi_movie_info *aviinfo; avi_error avierr; avi_file *avi; /* open the file */ avierr = avi_open(filename, &avi); if (avierr != AVIERR_NONE) { fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr)); return NULL; } /* extract movie info */ aviinfo = avi_get_movie_info(avi); info->framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime; info->numframes = aviinfo->video_numsamples; info->width = aviinfo->video_width; info->height = aviinfo->video_height; info->samplerate = aviinfo->audio_samplerate; info->channels = aviinfo->audio_channels; return avi; }
static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples) { avi_file *avifile = reinterpret_cast<avi_file *>(file); // read the frame avi_error avierr = avi_read_video_frame(avifile, frame, bitmap); if (avierr != AVIERR_NONE) return FALSE; // read the samples const avi_movie_info *aviinfo = avi_get_movie_info(avifile); UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale); avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound); avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound); if (avierr != AVIERR_NONE) return false; samples = lastsample - firstsample; return true; }
static int read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples) { const avi_movie_info *aviinfo = avi_get_movie_info((avi_file *)file); UINT32 firstsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)frame * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; UINT32 lastsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)(frame + 1) * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale; avi_error avierr; /* read the frame */ avierr = avi_read_video_frame((avi_file *)file, frame, bitmap); if (avierr != AVIERR_NONE) return FALSE; /* read the samples */ avierr = avi_read_sound_samples((avi_file *)file, 0, firstsample, lastsample - firstsample, lsound); avierr = avi_read_sound_samples((avi_file *)file, 1, firstsample, lastsample - firstsample, rsound); if (avierr != AVIERR_NONE) return FALSE; *samples = lastsample - firstsample; return TRUE; }
static int generate_from_avi(const char *aviname) { UINT32 line12 = 0, line13 = 0, line14 = 0, framenum = 0, chapternum = 0; const avi_movie_info *info; bitmap_t *bitmap; avi_error avierr; avi_file *avi; int white = 0; int frame; /* open the file */ avierr = avi_open(aviname, &avi); if (avierr != AVIERR_NONE) { fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr)); return 1; } /* extract movie info */ info = avi_get_movie_info(avi); fprintf(stderr, "%dx%d - %d frames total\n", info->video_width, info->video_height, info->video_numsamples); if (info->video_height != 39) { fprintf(stderr, "Unknown VANC capture format: expected 39 rows\n"); return 1; } /* allocate a bitmap to hold it */ bitmap = bitmap_alloc(info->video_width, info->video_height, BITMAP_FORMAT_YUY16); if (bitmap == NULL) { fprintf(stderr, "Out of memory allocating %dx%d bitmap\n", info->video_width, info->video_height); return 1; } /* loop over frames */ for (frame = 0; frame < info->video_numsamples; frame++) { int field; UINT8 bits[24]; /* read the frame */ avierr = avi_read_video_frame_yuy16(avi, frame, bitmap); if (avierr != AVIERR_NONE) { fprintf(stderr, "Error reading AVI frame %d: %s\n", frame, avi_error_string(avierr)); break; } /* loop over two fields */ for (field = 0; field < 2; field++) { int prevwhite = white; int i; /* line 7 contains the white flag */ white = 0; if (*BITMAP_ADDR16(bitmap, 20 * field + 7, bitmap->width / 2) > 0x8000) white = 1; /* output metadata for *previous* field */ if (frame > 0 || field > 0) { int flags = 0; if (!prevwhite) flags |= 0x01; if (!white) flags |= 0x02; output_meta(flags, prevwhite, line12, line13, line14, framenum, chapternum); } /* line 12 contains stop code and other interesting bits */ line12 = 0; if (parse_line(bitmap, 20 * field + 12, 24, bits) == 24) for (i = 0; i < 24; i++) line12 = (line12 << 1) | bits[i]; /* line 13 and 14 contain frame/chapter/lead in/out encodings */ line13 = 0; if (parse_line(bitmap, 20 * field + 13, 24, bits) == 24) for (i = 0; i < 24; i++) line13 = (line13 << 1) | bits[i]; line14 = 0; if (parse_line(bitmap, 20 * field + 14, 24, bits) == 24) for (i = 0; i < 24; i++) line14 = (line14 << 1) | bits[i]; /* the two lines must match */ // if (line13 != 0 && line14 != 0 && line13 != line14) // line13 = line14 = 0; /* is this a frame number? */ if ((line13 & 0xf00000) == 0xf00000) framenum = line13 & 0x7ffff; if ((line13 & 0xf00fff) == 0x800ddd) chapternum = (line13 >> 12) & 0x7f; } } /* output metadata for *previous* field */ { int flags = 0; if (!white) flags |= 0x01; output_meta(flags, white, line12, line13, line14, framenum, chapternum); } bitmap_free(bitmap); return 0; }