static int get_n_frs(Image_File *ifp) { int n_frames=0; char *pixels; ImageDesc *idp; Boolean moreframes = TRUE; #ifdef QUIP_DEBUG printf("get_n_frs: IN\n"); #endif /* QUIP_DEBUG */ idp = ifp->hdr->idp; pixels = (char *)malloc(idp->Size * sizeof(char)); /* get frames until the movie ends */ while (moreframes) { /* GetMPEGFrame returns FALSE after last frame is decoded */ moreframes = GetMPEGFrame(pixels); n_frames++; } free(pixels); if(verbose) printf("n_frames calculated: %d\n", n_frames); RewindMPEG (ifp->if_fp, idp); #ifdef QUIP_DEBUG printf("get_n_frs: OUT\n"); #endif /* QUIP_DEBUG */ return n_frames; }
static void malib_mpegfile_get_next_frame (MalibMpegFile* mpegfile, MalibFrame* frame) { unsigned int i; unsigned char* buf = mpegfile->pixels; struct timeval* tp = &(((MalibSource*) mpegfile) -> tp); /* the flag whether we need to create new image */ int need_increment = 0; g_return_if_fail (mpegfile && frame); /* GetMPEGFrame returns TRUE if more frames are still remaining */ MALIB_OBJECT_COUNT_REFERENCES (mpegfile, need_increment); if (need_increment) { int flag = GetMPEGFrame (buf); /* Mark timestamp at the moment of capturing */ gettimeofday (tp, NULL); if (flag != TRUE) { RewindMPEG (mpegfile->fp, &mpegfile->img); } } /* copy data from buf into frame->data with re-allocation */ for(i = 0; i < mpegfile->img.Size/4; i++) { *((int*)frame->data + i*3) = (int) *(buf+i*4); *((int*)frame->data + i*3+1) = (int) *(buf+i*4+1); *((int*)frame->data + i*3+2) = (int) *(buf+i*4+2); } /* copy timestamp into following frames */ frame->timestamp . tv_sec = tp -> tv_sec; frame->timestamp . tv_usec = tp -> tv_usec; }