2024年4月23日发(作者:)

} finally {

if (fc != null) {

try {

();

} catch (IOException e) {

tackTrace();

}

}

if (fos != null) {

try {

();

} catch (IOException e) {

tackTrace();

}

}

}

return null;

}

/**

* 剪切视频

* @param srcVideoPath

* @param dstVideoPath

* @param times

* @throws IOException

*/

public static void cutVideo(String srcVideoPath, String dstVideoPath, double[] times) throws IOException {

int dstVideoNumber = / 2;

String[] dstVideoPathes = new String[dstVideoNumber];

for (int i = 0; i < dstVideoNumber; i++) {

dstVideoPathes[i] = dstVideoPath + "cutOutput-" + i + ".mp4";

}

int timesCount = 0;

for (int idst = 0; idst < ; idst++) {

//Movie movie = new MovieCreator().build(new RandomAccessFile("/home/sannies/suckerpunch-distantplanet_h1080p/suckerpunch-distantplanet_", "r").getChannel());

Movie movie = (srcVideoPath);

List tracks = cks();

cks(new LinkedList());

// remove all tracks we will create new tracks from the old

double startTime1 = times[timesCount];

double endTime1 = times[timesCount + 1];

timesCount = timesCount + 2;

boolean timeCorrected = false;

// Here we try to find a track that has sync samples. Since we can only start decoding

// at such a sample we SHOULD make sure that the start of the new fragment is exactly

// such a frame

for (Track track : tracks) {

if (cSamples() != null && cSamples().length > 0) {

if (timeCorrected) {

// This exception here could be a false positive in case we have multiple tracks

// with sync samples at exactly the same positions. E.g. a single movie containing

// multiple qualities of the same video (Microsoft Smooth Streaming file)

throw new RuntimeException("The startTime has already been corrected by another track with SyncSample. Not Supported.");

}

startTime1 = correctTimeToSyncSample(track, startTime1, false);

endTime1 = correctTimeToSyncSample(track, endTime1, true);

timeCorrected = true;

}

}

for (Track track : tracks) {

long currentSample = 0;

double currentTime = 0;

double lastTime = -1;

long startSample1 = -1;

long endSample1 = -1;

for (int i = 0; i < pleDurations().length; i++) {

long delta = pleDurations()[i];

if (currentTime > lastTime && currentTime <= startTime1) {

// current sample is still before the new starttime

startSample1 = currentSample;

}

if (currentTime > lastTime && currentTime <= endTime1) {

// current sample is after the new start time and still before the new endtime

endSample1 = currentSample;

}

lastTime = currentTime;