use of org.fagu.fmv.ffmpeg.utils.FrameRate in project fmv by f-agu.
the class Bootstrap method newProject.
/**
* @param printStream
* @return
*/
private static Project newProject(PrintStream printStream) {
try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
// name
printStream.print("Name: ");
String name = scanner.nextLine();
// save file
final File defaultSaveFile = new File(name);
printStream.print("SaveFolder: [" + defaultSaveFile.getAbsolutePath() + "] ");
File saveFile = null;
String ssavefile = scanner.nextLine();
if (StringUtils.isBlank(ssavefile)) {
saveFile = defaultSaveFile;
} else {
saveFile = new File(ssavefile);
}
saveFile = new File(saveFile, name + ".fmv");
saveFile.getParentFile().mkdirs();
// format
final String defaultFormat = "mp4";
printStream.print("Format: [" + defaultFormat + "] ");
String format = scanner.nextLine();
if (StringUtils.isBlank(format)) {
format = defaultFormat;
}
// size
final Size defaultSize = Size.HD720;
printStream.print("Size: [" + defaultSize + "] ");
Size size = null;
while (size == null) {
String ssize = scanner.nextLine();
if (StringUtils.isBlank(ssize)) {
size = defaultSize;
} else {
try {
size = Size.parse(ssize);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + ssize);
}
}
}
// rate
final FrameRate defaultRate = FrameRate.valueOf(30, 1);
printStream.print("Rate: [" + defaultRate + "] ");
FrameRate frameRate = null;
while (frameRate == null) {
String srate = scanner.nextLine();
if (StringUtils.isBlank(srate)) {
frameRate = defaultRate;
} else {
try {
frameRate = FrameRate.parse(srate);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + srate);
}
}
}
OutputInfos outputInfos = new OutputInfos();
outputInfos.setSize(size);
outputInfos.setFrameRate(frameRate);
// TODO
outputInfos.setAudioSampling(44100);
outputInfos.setFormat(format);
Project project = new Project(saveFile, outputInfos);
project.setName(name);
try {
project.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
return project;
}
}
use of org.fagu.fmv.ffmpeg.utils.FrameRate in project fmv by f-agu.
the class Stream method countEstimateFrames.
/**
* @return
*/
public OptionalInt countEstimateFrames() {
OptionalInt count = numberOfFrames();
if (count.isPresent()) {
return count;
}
FrameRate frameRate = frameRate().orElse(null);
if (frameRate == null) {
frameRate = averageFrameRate().orElse(null);
}
if (frameRate == null) {
return OptionalInt.empty();
}
Duration duration = duration().orElse(null);
if (duration == null) {
Optional<Object> totDurObj = movieMetadatas.getFormat().tag("totalduration");
if (totDurObj.isPresent()) {
int totDur = NumberUtils.toInt(String.valueOf(totDurObj.get()));
if (totDur > 0) {
duration = Duration.valueOf(totDur);
}
}
}
if (duration == null) {
duration = movieMetadatas.getFormat().duration().orElse(null);
}
if (duration == null) {
OptionalInt dts = durationTimeBase();
if (!dts.isPresent()) {
return OptionalInt.empty();
}
Fraction timeBase = timeBase().orElse(null);
if (timeBase == null) {
return OptionalInt.empty();
}
duration = Duration.valueOf(dts.getAsInt() * timeBase.doubleValue());
}
return OptionalInt.of((int) (frameRate.doubleValue() * duration.toSeconds()));
}
use of org.fagu.fmv.ffmpeg.utils.FrameRate in project fmv by f-agu.
the class FFReducer method isVideo.
/**
* @param metadatas
* @param logger
* @return
*/
private boolean isVideo(MovieMetadatas metadatas, Logger logger) {
if (!metadatas.contains(Type.VIDEO)) {
logger.log("Is audio: not contains video stream");
return false;
}
VideoStream videoStream = metadatas.getVideoStream();
OptionalInt numberOfFrames = videoStream.numberOfFrames();
if (numberOfFrames.isPresent() && numberOfFrames.getAsInt() == 1) {
logger.log("Is audio: number of frames unavailable: " + numberOfFrames);
return false;
}
if (Decoders.MJPEG.getName().equals(videoStream.codecName().get())) {
FrameRate frameRate = videoStream.frameRate().orElse(null);
if (frameRate != null && frameRate.floatValue() < 100) {
return true;
}
logger.log("Is audio: frameRate is null or too high: " + frameRate);
return false;
}
return true;
}
Aggregations