I'm reviving this thread since it's difficult to figure this out in Quicktime for Java (QTJ). The book "Quicktime for Java: a developer's notebook" (Chris Adamson) helped a lot. Here's the program (nasty, huh?):
Code:
package com.audeto.utils;
import quicktime.*;
import quicktime.app.view.QTFactory;
import quicktime.io.*;
import quicktime.std.image.*;
import quicktime.std.movies.media.*;
import quicktime.std.movies.*;
import quicktime.std.*;
import quicktime.qd.*;
import quicktime.util.QTPointer;
import quicktime.util.QTHandle;
import java.io.*;
public class AudioAdder {
public static void main(String args[]) {
if (args.length != 3) {
System.out
.println("Usage: java AudioAdder [movie_filename] [audio_filename] [out_filename]");
} else {
try {
QTSession.open();
System.out.println("QuickTime version: "
+ QTSession.getMajorVersion() + "."
+ QTSession.getMinorVersion());
// create the movie
QTFile qtfile = new QTFile(new File(args[0]));
DataRef urlMovie = new DataRef("file://" + qtfile.getPath());
Movie movie = Movie.fromDataRef(urlMovie,
StdQTConstants.newMovieActive);
// create the audio movie
QTFile audioFile = new QTFile(new File(args[1]));
DataRef urlAudio = new DataRef("file://" + audioFile.getPath());
Movie audioMovie = Movie.fromDataRef(urlAudio,
StdQTConstants.newMovieActive);
// retrieve the audio track from the audio movie
Track audioTrack = audioMovie.getIndTrackType(1,
StdQTConstants.audioMediaCharacteristic,
StdQTConstants.movieTrackCharacteristic);
if (audioTrack == null) {
System.out.println("Didn't find audio track");
return;
}
// create a new track within the movie
// max volume is 1
Track newTrack = movie.newTrack(0.0f, 0.0f, 1);
// create a new media within the new track
SoundMedia newMedia = new SoundMedia(newTrack, audioTrack
.getMedia().getTimeScale(), new DataRef(new QTHandle()));
newTrack.insertMedia(0, 0, audioTrack.getDuration(), 1);
newMedia.beginEdits();
// add the existing audio track to the newTrack
audioTrack.insertSegment(newTrack, 0, audioTrack.getDuration(),
0);
newMedia.endEdits();
// create the movie
QTFile outfile = new QTFile(new File(args[2]));
movie
.flatten(
StdQTConstants.flattenAddMovieToDataFork |
StdQTConstants.flattenForceMovieResourceBeforeMovieData,
outfile, StdQTConstants.kMoviePlayer,
IOConstants.smSystemScript,
StdQTConstants.createMovieFileDeleteCurFile,
StdQTConstants.movieInDataForkResID, null);
} catch (Exception e) {
e.printStackTrace();
QTSession.close();
System.exit(0);
}
QTSession.close();
// end else
}
System.out.println("complete.");
// end method
}
}