use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class FFReducer method reduceVideo.
/**
* @param metadatas
* @param srcFile
* @param movieMetadatas
* @param destFile
* @param consolePrefixMessage
* @param logger
* @throws IOException
*/
public void reduceVideo(MovieMetadatas metadatas, File srcFile, MovieMetadatas movieMetadatas, File destFile, String consolePrefixMessage, Logger logger) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
builder.filter(AutoRotate.create(movieMetadatas));
org.fagu.fmv.mymedia.reduce.FFReducer.applyScaleIfNecessary(builder, movieMetadatas, Size.HD720, logger);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
OutputProcessor outputProcessor = builder.addMediaOutputFile(destFile);
outputProcessor.qualityScale(0);
// video
for (Stream stream : videoMetadatas.getVideoStreams()) {
logger.log("map[" + stream.index() + "] video: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// audio
for (Stream stream : audioStreams) {
logger.log("map[" + stream.index() + "] audio: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// subtitle
Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
for (Stream stream : subtitleStreams) {
logger.log("map[" + stream.index() + "] subtitle: " + stream);
outputProcessor.map().streams(stream).input(inputProcessor);
}
// -------------------------- codec -------------------------
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
// subtitle
if (videoMetadatas.contains(Type.AUDIO)) {
outputProcessor.codecCopy(Type.AUDIO);
}
// subtitle
if (videoMetadatas.contains(Type.SUBTITLE)) {
outputProcessor.codecCopy(Type.SUBTITLE);
}
outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
executor.addListener(org.fagu.fmv.mymedia.reduce.FFReducer.createLogFFExecListener(logger));
OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
Progress progress = executor.getProgress();
if (countEstimateFrames.isPresent() && progress != null) {
textProgressBar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).fileSize(srcFile.length()).build().makeBar(consolePrefixMessage);
} else {
StringJoiner joiner = new StringJoiner(", ");
if (progress == null) {
joiner.add("progress not found");
}
if (!countEstimateFrames.isPresent()) {
joiner.add("nb frames nout found");
}
logger.log("No progress bar: " + joiner.toString());
}
executor.execute();
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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();
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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;
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class ConsoleOutput method forOutput.
/**
* @param fileSource
* @param fromFile
* @return
*/
public static String forOutput(FileSource fileSource, File fromFile) {
StringBuilder buf = new StringBuilder(100);
buf.append(StringUtils.rightPad(Integer.toString(fileSource.getNumber()), 3)).append(' ').append(' ');
FileType fileType = fileSource.getFileType();
if (fileType != null) {
buf.append(fileType.name().charAt(0)).append(' ');
}
String meta = null;
if (fileSource.isImage()) {
ImageMetadatas imageMetadatas = fileSource.getImageMetadatas();
if (imageMetadatas != null) {
meta = imageMetadatas.getDimension().toString();
}
}
if (fileSource.isAudioOrVideo()) {
MovieMetadatas videoMetadatas = fileSource.getVideoMetadatas();
if (videoMetadatas != null) {
AudioStream audioStream = videoMetadatas.getAudioStream();
VideoStream videoStream = videoMetadatas.getVideoStream();
if (videoStream != null) {
Optional<Duration> duration = videoStream.duration();
String sd = duration.isPresent() ? duration.get().toString() : "";
meta = videoStream.size().toString() + " " + sd;
} else if (audioStream != null) {
Optional<Duration> duration = audioStream.duration();
meta = duration.isPresent() ? duration.get().toString() : "";
}
}
}
String subPath = null;
if (fromFile != null) {
subPath = StringUtils.substringAfter(fileSource.getFile().getPath(), fromFile.getPath() + File.separator);
} else {
subPath = fileSource.getFile().getName();
}
buf.append(StringUtils.rightPad(meta, 25)).append(' ').append(' ').append(subPath);
return buf.toString();
}
Aggregations