私は mp4parser ライブラリを使用しており、既にビデオのオーディオ トラックを特定のオーディオ ファイルに置き換えています。ただし、最終的なビデオでは、最大のトラックの長さ (ビデオと音楽の間) が保持されます。
mp4parser ライブラリによると、私がこのように使用する CroppedTrack を使用してトラックをトリミングすることが可能です
for (Movie m : inMoviesSound) {
double startTime = 0.000;
double endTime = nSecondsVideo;
boolean timeCorrected = false;
for (Track track : m.getTracks()) {
if (track.getSyncSamples() != null
&& track.getSyncSamples().length > 0) {
if (timeCorrected) {
throw new RuntimeException(
"The startTime has already been corrected by another track with SyncSample. Not Supported.");
}
startTime = correctTimeToNextSyncSample(track, startTime);
endTime = correctTimeToNextSyncSample(track, endTime);
timeCorrected = true;
}
}
for (Track track : m.getTracks()) {
long currentSample = 0;
double currentTime = 0;
long startSample = -1;
long endSample = -1;
for (int i = 0; i < track.getDecodingTimeEntries().size(); i++) {
TimeToSampleBox.Entry entry = track
.getDecodingTimeEntries().get(i);
for (int j = 0; j < entry.getCount(); j++) {
if (currentTime <= startTime) {
// current sample is still before the new starttime
startSample = currentSample;
}
if (currentTime <= endTime) {
// current sample is after the new start time and
// still before the new endtime
endSample = currentSample;
} else {
// current sample is after the end of the cropped
// video
break;
}
currentTime += (double) entry.getDelta()
/ (double) track.getTrackMetaData()
.getTimescale();
currentSample++;
}
}
result.addTrack(new CroppedTrack(track, startSample, endSample));
}
}
ただし、音楽はビデオよりも少し早く停止します。
終了時刻をより具体的にする方法はありますか?