我正在使用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));
}
}
然而,音乐比视频更早停止。
有没有更具体的结束时间?