/* * concatenate several Movie Files into one * * The track parameters of the image and audio track in each movie must match. * * And, a good number of these parameters are actually checked by this program. */ #include #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); } extern int errno; main(int argc, char **argv) { MVid srcmv, newmv, srcimg, newimg, srca = 0, newa = 0; MVtime newtime = 0; char *newname = argv[argc - 1]; int wid, ht; DMinterlacing ilace; double rate; struct stat sb; if (argc < 4) { fprintf(stderr, "usage: %s a.mv b.mv .... new.mv\n", argv[0]); exit(1); } if (!(stat(newname, &sb) == -1 && errno == ENOENT)) { fprintf(stderr, "%s exists\n", newname); exit(1); } argc -= 2; argv++; for (;argc--; argv++) { MVtimescale tscale, new_tscale; MVtime dur; EMV(mvOpenFile(*argv, O_RDONLY, &srcmv), *argv); EMV(mvFindTrackByMedium(srcmv, DM_IMAGE, &srcimg), "find img track"); if (mvFindTrackByMedium(srcmv, DM_AUDIO, &srca) == DM_FAILURE) { printf("%s: no audio track...\n", *argv); } tscale = mvGetMovieTimeScale(srcmv); if (newtime == 0) { /* First time around */ DMparams *p = mvGetParams(srcmv); dmParamsSetEnum(p, MV_FILE_FORMAT, MV_FORMAT_QT); printf("creating %s\n", newname); EMV(mvCreateFile(newname, p, 0, &newmv), newname); p = mvGetParams(srcimg); EMV(mvAddTrack(newmv, DM_IMAGE, p, NULL, &newimg), "add img track"); if (srca) { p = mvGetParams(srca); EMV(mvAddTrack(newmv, DM_AUDIO, p, NULL, &newa), "add aud track"); } /* Use timescale of first movie in the list */ new_tscale = tscale; wid = mvGetImageWidth(srcimg); ht = mvGetImageHeight(srcimg); ilace = mvGetImageInterlacing(srcimg); rate = mvGetImageRate(srcimg); /* XXX orientation */ } else { if (mvGetImageWidth(srcimg) != wid || mvGetImageHeight(srcimg) != ht) { fprintf(stderr, "%s not %dx%d\n", *argv, wid, ht); exit(1); } if (mvGetImageInterlacing(srcimg) != ilace) { fprintf(stderr, "%s interlacing different\n", *argv); exit(1); } if (mvGetImageRate(srcimg) != rate) { fprintf(stderr, "%s rate not %f\n", *argv, rate); exit(1); } } dur = mvGetTrackDuration(srcimg, new_tscale); printf("%5d seconds %s\n", (int)(dur/(long long)new_tscale), *argv); EMV(mvCopyFramesAtTime(srcimg, 0, dur, new_tscale, newimg, newtime, new_tscale, DM_FALSE), "copy img"); if (newa) { EMV(mvCopyFramesAtTime(srca, 0, dur, new_tscale, newa, newtime, new_tscale, DM_FALSE),"copy a"); } newtime += dur; EMV(mvClose(srcmv), "mvclose"); } EMV(mvClose(newmv), "mvclose"); }