38 lines
1.4 KiB
Java
38 lines
1.4 KiB
Java
|
|
package org.jcodec.movtool;
|
||
|
|
|
||
|
|
import java.io.File;
|
||
|
|
import org.jcodec.containers.mp4.boxes.Box;
|
||
|
|
import org.jcodec.containers.mp4.boxes.MediaHeaderBox;
|
||
|
|
import org.jcodec.containers.mp4.boxes.MovieBox;
|
||
|
|
import org.jcodec.containers.mp4.boxes.MovieFragmentBox;
|
||
|
|
import org.jcodec.containers.mp4.boxes.NodeBox;
|
||
|
|
import org.jcodec.containers.mp4.boxes.TrakBox;
|
||
|
|
|
||
|
|
public class ChangeTimescale {
|
||
|
|
public static void main1(String[] args) throws Exception {
|
||
|
|
if (args.length < 2) {
|
||
|
|
System.out.println("Syntax: chts <movie> <timescale>");
|
||
|
|
System.exit(-1);
|
||
|
|
}
|
||
|
|
final int ts = Integer.parseInt(args[1]);
|
||
|
|
if (ts < 600) {
|
||
|
|
System.out.println("Could not set timescale < 600");
|
||
|
|
System.exit(-1);
|
||
|
|
}
|
||
|
|
new InplaceMP4Editor().modify(new File(args[0]), new MP4Edit() {
|
||
|
|
public void apply(MovieBox mov) {
|
||
|
|
TrakBox vt = mov.getVideoTrack();
|
||
|
|
MediaHeaderBox mdhd = NodeBox.<MediaHeaderBox>findFirstPath(vt, MediaHeaderBox.class, Box.path("mdia.mdhd"));
|
||
|
|
int oldTs = mdhd.getTimescale();
|
||
|
|
if (oldTs > ts)
|
||
|
|
throw new RuntimeException("Old timescale (" + oldTs + ") is greater then new timescale (" + ts + "), not touching.");
|
||
|
|
vt.fixMediaTimescale(ts);
|
||
|
|
mov.fixTimescale(ts);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void applyToFragment(MovieBox mov, MovieFragmentBox[] fragmentBox) {
|
||
|
|
throw new RuntimeException("Unsupported");
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|