use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected 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.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.
the class FFReducer method createVolumeDetectFFExecListener.
/**
* @param logger
* @param volumeDetect
* @return
*/
private FFExecListener createVolumeDetectFFExecListener(Logger logger, VolumeDetect volumeDetect) {
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) {
if (volumeDetect.isDetected()) {
VolumeDetected detected = volumeDetect.getDetected();
logger.log("VolumeDetect: nb_sample= " + detected.countSample());
logger.log("VolumeDetect: max= " + detected.getMax());
logger.log("VolumeDetect: mean= " + detected.getMean());
logger.log("VolumeDetect: histogram= " + detected.getHistogram());
logger.log("VolumeDetect: Add volume filter: " + detected.toMaxVolume());
} else {
logger.log("volume not detected");
}
}
};
}
use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.
the class FFHelper method audioVolumeAdjustToMax.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void audioVolumeAdjustToMax(File inFile, File outFile) throws IOException {
VolumeDetected volumeDetected = audioVolumeDetect(inFile);
System.out.println(volumeDetected);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.addMediaInputFile(inFile);
Volume volume = Volume.build().increaseToMax(volumeDetected);
builder.filter(volume);
builder.addMediaOutputFile(outFile).videoCodecCopy().overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected in project fmv by f-agu.
the class VolumeInfoFile method toLine.
/**
* @see org.fagu.fmv.mymedia.file.InfoFile#toLine(org.fagu.fmv.utils.file.FileFinder.FileFound,
* org.fagu.fmv.media.Media)
*/
@Override
public String toLine(FileFound fileFound, FileFinder<Media>.InfosFile infosFile) throws IOException {
Media main = infosFile.getMain();
MovieMetadatas metadatas = (MovieMetadatas) main.getMetadatas();
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.addMediaInputFile(fileFound.getFileFound());
VolumeDetect volumeDetect = VolumeDetect.build();
builder.filter(volumeDetect);
builder.addMediaOutput(NullMuxer.build()).overwrite();
FFExecutor<Object> executor = builder.build();
if (metadatas != null) {
OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
Progress progress = executor.getProgress();
if (countEstimateFrames.isPresent() && progress != null) {
try (TextProgressBar bar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).build().makeBar("Detect volume")) {
executor.execute();
}
System.out.println();
}
} else {
executor.execute();
}
VolumeDetected volumeDetected = volumeDetect.getDetected();
return volumeDetected.toString();
}
Aggregations