/* * Cosmo (image [ + audio]) -> Quicktime (image [ + audio]) * * Uses mvInsertTrackDataFields (as opposed to mvCopyFrames which * doesn't insert field info needed in mvGetTrackDataFieldInfo). */ #include #include #include #include #define MVPR(s) fprintf(stderr, "%s: %s\n", s, mvGetErrorStr(mvGetErrno())) #define EMV(func, s) if (func == DM_FAILURE) { MVPR(s); exit(1); } static unsigned char * j_find(unsigned char *cp, unsigned char marker) { for (;;cp++) { if (*cp == 0xff) { if (*(cp + 1) == marker) { return cp; } } } } main(int argc, char **argv) { MVid c_movie, c_itrack, c_atrack; MVid q_movie, q_itrack, q_atrack; DMparams *p; MVtimescale tscale; MVtime dur; double rate; size_t max; MVframe f, nframes; unsigned char *i_buf; char *c_file = argv[1]; char *q_file = argv[2]; if (argc != 3) { fprintf(stderr,"usage: %s from.cosmo to.qt\n",argv[0]); exit(1); } EMV(mvOpenFile(c_file, O_RDONLY, &c_movie), c_file); if (mvGetFileFormat(c_movie) != MV_FORMAT_SGI_3) { fprintf(stderr, "%s: not sgi format\n", c_file); exit(1); } EMV(mvFindTrackByMedium(c_movie, DM_IMAGE, &c_itrack), "find itrack"); if (strcmp(mvGetImageCompression(c_itrack), DM_IMAGE_JPEG)) { fprintf(stderr, "%s: not JPEG\n", c_file); exit(1); } dmParamsCreate(&p); EMV(mvSetMovieDefaults(p, MV_FORMAT_QT), "set movie defaults"); EMV(mvCreateFile(q_file, p, NULL, &q_movie), q_file); dmParamsDestroy(p); dmParamsCreate(&p); EMV(mvGetTrackDataParams(c_itrack, 0, p), "get track params"); EMV(mvAddTrack(q_movie, DM_IMAGE, p, NULL, &q_itrack), "add itrack"); dmParamsDestroy(p); if (mvFindTrackByMedium(c_movie, DM_AUDIO, &c_atrack) == DM_SUCCESS) { dmParamsCreate(&p); EMV(mvGetTrackDataParams(c_atrack, 0, p), "get atrack params"); EMV(mvAddTrack(q_movie, DM_AUDIO, p, NULL, &q_atrack), "add itrack"); } else { c_atrack = 0; } tscale = mvGetTrackTimeScale(c_itrack); rate = mvGetImageRate(c_itrack); dur = (long long)((double)tscale/rate); max = mvGetTrackMaxDataSize(c_itrack); if ((i_buf = malloc(max)) == NULL) { fprintf(stderr, "malloc(%d) failed\n", max); exit(1); } printf("%s, max image frame: %d bytes\n", c_file, max); nframes = mvGetTrackLength(c_itrack); printf("%s: %d frames\n", c_file, nframes); for (f = 0; f < nframes; f++) { MVtime mvtime = (long long)f * dur; int index, p; MVdatatype dt; MVframe fr; size_t nb, nb1, nb2; unsigned char *p2; EMV(mvGetTrackDataIndexAtTime(c_itrack, mvtime, tscale, &index, &fr), "get index"); EMV(mvGetTrackDataInfo(c_itrack, index, &nb, &p, &dt, &fr), "get info"); EMV(mvReadTrackData(c_itrack, index, nb, i_buf), "read data"); p2 = j_find(i_buf, 0xd9) + 2; nb1 = p2 - i_buf; nb2 = nb - nb1; EMV(mvInsertTrackDataFields(q_itrack, mvtime, dur, tscale, nb1, i_buf, nb2, p2, MV_FRAMETYPE_KEY, 0), "insert"); printf("%5d %d %d\n", f, nb1, nb2); } if (c_atrack) { printf("copying audio..."); fflush(stdout); EMV(mvCopyFramesAtTime(c_atrack, 0, dur * (long long)nframes, tscale, q_atrack, 0, tscale, DM_FALSE), "copy aud"); printf("....done\n"); } mvClose(q_movie); }