use of org.fagu.fmv.utils.media.Size 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.utils.media.Size in project fmv by f-agu.
the class MovieScriptConverter method convert.
/**
* @see org.fagu.fmv.mymedia.classify.Converter#convert(org.fagu.fmv.media.Media,
* org.fagu.fmv.utils.file.FileFinder.InfosFile, java.io.File, org.fagu.fmv.mymedia.classify.ConverterListener)
*/
@Override
public void convert(Movie srcMedia, FileFinder<Movie>.InfosFile infosFile, File destFile, ConverterListener<Movie> listener) throws IOException {
openScript();
File srcFile = srcMedia.getFile();
MovieMetadatas infos = srcMedia.getMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
builder.addMediaInputFile(srcFile).setMovieMetadatas(infos);
Rotation rotation = rotateMap.get(srcFile.getName());
if (rotation != null) {
if (rotation != Rotation.R_0) {
builder.filter(Rotate.create(rotation));
}
} else {
builder.filter(AutoRotate.create(infos));
}
Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, getMaxSize(), getScaleLogger(), rotation);
writeLabel();
script.println("rem " + (newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
Optional<VolumeDetected> findFirst = infosFile.getInfos().stream().filter(o -> o instanceof VolumeDetected).map(o -> (VolumeDetected) o).findFirst();
if (findFirst.isPresent()) {
VolumeDetected volumeDetected = findFirst.get();
builder.filter(Volume.build().increaseToMax(volumeDetected));
}
File dest = new File(destFile.getParentFile(), FilenameUtils.getBaseName(destFile.getName()) + ".mp4");
OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
outputProcessor.qualityScale(0);
Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
outputProcessor.format("mp4");
// outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
try {
script.println("if exist \"" + dest.getPath() + "\" goto :movie_" + currentVideo);
script.println("echo.");
script.println("echo Frame: " + infos.getVideoStream().countEstimateFrames().getAsInt());
script.println(executor.getCommandLine());
script.println();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.
the class Movie method getDevice.
/**
* @see org.fagu.fmv.media.Media#getDevice()
*/
@Override
public String getDevice() {
List<String> keys = new ArrayList<>();
VideoStream videoStream = videoMetadatas.getVideoStream();
if (videoStream != null) {
String handlerName = videoStream.handlerName().orElse(null);
if (StringUtils.isNotEmpty(handlerName)) {
keys.add(handlerName);
}
Size size = videoStream.size();
if (size != null) {
keys.add(size.toString());
}
}
AudioStream audioStream = videoMetadatas.getAudioStream();
if (audioStream != null) {
String handlerName = audioStream.handlerName().orElse(null);
if (StringUtils.isNotEmpty(handlerName)) {
keys.add(handlerName);
}
OptionalInt sampleRate = audioStream.sampleRate();
if (sampleRate.isPresent()) {
keys.add(sampleRate.getAsInt() + "Hz");
}
}
return keys.stream().collect(Collectors.joining(" "));
}
use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.
the class FFReducer method createCropDetectFFExecListener.
/**
* @param logger
* @param cropDetect
* @param videoMetadatas
* @return
*/
private FFExecListener createCropDetectFFExecListener(Logger logger, CropDetect cropDetect, MovieMetadatas videoMetadatas) {
return new FFExecListener() {
/**
* @see org.fagu.fmv.soft.exec.FMVExecListener#eventPostExecute(org.fagu.fmv.soft.exec.FMVExecutor,
* org.apache.commons.exec.CommandLine, java.util.Map, org.apache.commons.exec.ExecuteResultHandler)
*/
@Override
public void eventPostExecute(FMVExecutor fmvExecutor, CommandLine command, Map environment, ExecuteResultHandler handler) {
CropDetection cropDetection = cropDetect.getCropSizeDetected();
SortedSet<CropSize> orderedCropSizes = cropDetection.getOrderedCropSizes();
if (!orderedCropSizes.isEmpty()) {
CropSize first = orderedCropSizes.first();
Size size = first.toSize();
if (!videoMetadatas.getVideoStreams().stream().anyMatch(s -> size.equals(s.size()))) {
logger.log("CropDetect: " + cropDetection.getTotalCount() + " lines parsed");
orderedCropSizes.stream().limit(10).forEach(cs -> logger.log("CropDetect: " + cs));
logger.log("CropDetect: Add crop filter: " + first.toCrop());
}
}
}
};
}
use of org.fagu.fmv.utils.media.Size in project fmv by f-agu.
the class Bootstrap method isUpperThan720p.
/**
* @param metadatas
* @param logger
* @return
*/
private boolean isUpperThan720p(MovieMetadatas metadatas, Logger logger) {
if (!metadatas.contains(Type.VIDEO)) {
logger.log("It's not a video");
return false;
}
VideoStream videoStream = metadatas.getVideoStream();
Size size = videoStream.size();
if (size.getHeight() > Size.HD720.getHeight()) {
logger.log("It's upper than 720p: " + size);
return true;
}
logger.log("It's not upper than 720p: " + size);
return false;
}
Aggregations