use of org.fagu.fmv.ffmpeg.metadatas.AudioStream in project fmv by f-agu.
the class AudioColumn method value.
/**
* @see org.fagu.fmv.mymedia.movie.list.Column#value(Path, java.io.File, Supplier)
*/
@Override
public Optional<String> value(Path rootPath, File file, Supplier<Optional<MovieMetadatas>> movieMetadatasOptSupplier) {
List<AudioStream> audioStreams = movieMetadatasOptSupplier.get().map(MovieMetadatas::getAudioStreams).orElse(null);
if (CollectionUtils.isEmpty(audioStreams)) {
return Optional.empty();
}
StringJoiner joiner = new StringJoiner(", ");
for (AudioStream audioStream : audioStreams) {
String name = audioStream.title().orElse(audioStream.language().orElse(null));
if (name == null || "und".equals(name)) {
name = "?";
}
joiner.add(name);
}
String list = joiner.toString();
return Optional.of(audioStreams.size() + (list.isEmpty() ? "" : ": " + list));
}
use of org.fagu.fmv.ffmpeg.metadatas.AudioStream 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.AudioStream 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();
}
use of org.fagu.fmv.ffmpeg.metadatas.AudioStream in project fmv by f-agu.
the class TSTest method test.
@Test
@Ignore
public void test() throws IOException {
MovieMetadatas metadatas = MovieMetadatas.with(new File("d:\\tmp\\dvdout.ts")).extract();
List<Stream> streams = metadatas.getStreams();
System.out.println("count: " + streams.size());
for (Stream stream : streams) {
System.out.println(stream);
if (stream.is(Type.VIDEO)) {
VideoStream videoStream = (VideoStream) stream;
System.out.println(" " + videoStream);
} else if (stream.is(Type.AUDIO)) {
AudioStream audioStream = (AudioStream) stream;
System.out.println(" " + audioStream);
}
}
}
Aggregations