/* * copy a cut from a movie into a quicktime movie * expects one img tack and one aud track */ #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); } main(int argc, char **argv) { MVid srcmv, dstmv, srcimg, dstimg, srcaud, dstaud; DMparams *p; MVtime dur, srctime; MVtimescale tscale; double rate; int audio; char *srcname = argv[1]; long long in = (long long)atoi(argv[2]); long long out = (long long)atoi(argv[3]); char *dstname = argv[4]; if (argc != 5) { fprintf(stderr, "usage: %s src.mv in out new.mv\n", argv[0]); exit(1); } EMV(mvOpenFile(srcname, O_RDONLY, &srcmv), srcname); EMV(mvFindTrackByMedium(srcmv, DM_IMAGE, &srcimg), "find img track"); audio = mvFindTrackByMedium(srcmv, DM_AUDIO, &srcaud) == DM_SUCCESS; tscale = mvGetMovieTimeScale(srcmv); rate = mvGetImageRate(srcimg); #define DURFRAME (long long)((double)tscale/rate) dur = DURFRAME*(out - in); srctime = DURFRAME*in; p = mvGetParams(srcmv); dmParamsSetEnum(p, MV_FILE_FORMAT, MV_FORMAT_QT); EMV(mvCreateFile(dstname, p, NULL, &dstmv), dstname); p = mvGetParams(srcimg); EMV(mvAddTrack(dstmv, DM_IMAGE, p, NULL, &dstimg), "add img track"); if (audio) { p = mvGetParams(srcaud); EMV(mvAddTrack(dstmv, DM_AUDIO, p, NULL, &dstaud), "add aud"); } EMV(mvCopyFramesAtTime(srcimg, srctime, dur, tscale, dstimg, 0, tscale, DM_FALSE), "copy img"); if (audio) { EMV(mvCopyFramesAtTime(srcaud, srctime, dur, tscale, dstaud, 0, tscale, DM_FALSE), "copy aud"); } EMV(mvClose(dstmv), "mvclose"); }