use of org.fagu.fmv.utils.media.Rotation 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.Rotation in project fmv by f-agu.
the class FFReducer method applyScaleIfNecessary.
/**
* @param builder
* @param movieMetadatas
* @param maxSize
* @param logger
* @param rotation
* @return
*/
public static Size applyScaleIfNecessary(FFMPEGExecutorBuilder builder, MovieMetadatas movieMetadatas, Size maxSize, Logger logger, Rotation inRotation) {
VideoStream videoStream = movieMetadatas.getVideoStream();
Size size = videoStream.size();
Rotation rotation = inRotation;
if (rotation == null) {
rotation = videoStream.rotate();
}
if (rotation != null) {
size = rotation.resize(size);
}
if (size.getWidth() <= maxSize.getWidth() && size.getHeight() <= maxSize.getHeight()) {
return size;
}
StringBuilder log = new StringBuilder();
log.append("Need to resize ").append(size);
if (rotation != null) {
log.append(" (rotation of ").append(rotation.getValue()).append(')');
}
size = size.fitAndKeepRatioTo(maxSize);
if (rotation != null && !AutoRotate.isAutoRotateObsolete()) {
size = rotation.resize(size);
}
// fix [libx264 @ 037f8b00] height not divisible by 2 (1078x607)
size = Libx264NotDisibleBy2FFExecFallback.resize(size);
log.append(" to under ").append(maxSize).append(": ").append(size);
logger.log(log.toString());
// .forceOriginalAspectRatio(ForceOriginalAspectRatio.DECREASE)
builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
return size;
}
use of org.fagu.fmv.utils.media.Rotation in project fmv by f-agu.
the class Rotate method main.
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File srcFile = new File("D:\\tmp\\Auvergne\\phone-vv\\VID_20170813_183349.mp4");
Rotation rotation = Rotation.R_90;
File dest = new File(srcFile.getParentFile(), FilenameUtils.getBaseName(srcFile.getName()) + "-rotate-" + rotation + ".mp4");
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
MovieMetadatas infos = builder.addMediaInputFile(srcFile).getMovieMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
if (rotation != null && rotation != Rotation.R_0) {
builder.filter(org.fagu.fmv.ffmpeg.filter.impl.Rotate.create(rotation));
}
Logger logger = Loggers.systemOut();
Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, MAX_SIZE, logger, rotation);
logger.log((newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
outputProcessor.qualityScale(0);
Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
outputProcessor.format("mp4");
FFExecutor<Object> executor = builder.build();
logger.log(executor.getCommandLine());
}
use of org.fagu.fmv.utils.media.Rotation in project fmv by f-agu.
the class Bootstrap method findMovie.
// ---------------------------------------------------
/**
*/
private MovieFinder findMovie(File saveFile, File... srcFiles) throws IOException {
MovieFinder movieFinder = new MovieFinder(saveFile);
movieFinder.addInfoFile(new VolumeInfoFile());
movieFinder.addListener(new FileFinderListener<Movie>() {
private int count;
/**
* @see org.fagu.fmv.utils.file.FileFinderListener#eventFindPre(org.fagu.fmv.utils.file.FileFinder.FileFound)
*/
@Override
public void eventFindPre(FileFound fileFound) {
System.out.println(count + ": " + fileFound.getFileFound().getName());
++count;
}
/**
* @see org.fagu.fmv.utils.file.FileFinderListener#eventFindPost(FileFound, java.lang.Object)
*/
@Override
public void eventFindPost(FileFound fileFound, FileFinder<Movie>.InfosFile infosFile) {
Movie movie = infosFile.getMain();
MovieMetadatas videoMetadatas = movie.getMetadatas();
// Format format = videoMetadatas.getFormat();
VideoStream videoStream = videoMetadatas.getVideoStream();
Rotation rotate = videoStream.rotate();
// System.out.println(count + ": " + file.getName() + " " + infos); // .getFormat().creationDate()
System.out.println(" " + rotate + ", " + videoStream.handlerName());
}
});
for (File srcFile : srcFiles) {
movieFinder.find(srcFile);
}
return movieFinder;
}
Aggregations