use of org.fagu.fmv.mymedia.classify.ConverterListener 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.mymedia.classify.ConverterListener in project fmv by f-agu.
the class Images method prepare.
/**
* @param size
*/
public PreparedImages prepare(Size size) throws IOException {
final int COUNT_TOTAL = getImages().size();
File destFolder = new File(sourceFolder.getParent(), sourceFolder.getName() + "-img2mov");
if (destFolder.exists()) {
File[] listFiles = destFolder.listFiles(f -> f.getName().startsWith("img_"));
if (listFiles.length == COUNT_TOTAL) {
return new PreparedImages(Arrays.asList(listFiles));
}
}
final AtomicInteger count = new AtomicInteger();
ConverterListener<Image> converterListener = new ConverterListener<Image>() {
/**
* @see org.fagu.fmv.mymedia.classify.ConverterListener#eventPreConvert(org.fagu.fmv.media.Media,
* java.io.File)
*/
@Override
public void eventPreConvert(Image srcMedia, File destFile) {
System.out.println("Convert (" + count.incrementAndGet() + "/" + COUNT_TOTAL + "): " + srcMedia.getFile());
}
};
try (ReduceImageConverter converter = new ReduceImageConverter(destFolder)) {
converter.setSize(size);
try (Classifier<ImageFinder, Image> classifier = ClassifierFactories.imagesToMovie().create(imageFinder, destFolder)) {
return new PreparedImages(classifier.classify(converter, converterListener));
}
}
}
Aggregations