use of org.fagu.fmv.ffmpeg.metadatas.Stream in project fmv by f-agu.
the class StreamsTypeCountColumn 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) {
MovieMetadatas movieMetadatas = movieMetadatasOptSupplier.get().orElse(null);
if (movieMetadatas == null) {
return Optional.empty();
}
MapList<Type, Stream> typeMap = movieMetadatas.toTypeMap();
if (typeMap.isEmpty()) {
return Optional.empty();
}
StringJoiner joiner = new StringJoiner(", ");
Type[] values = { Type.VIDEO, Type.AUDIO, Type.SUBTITLE, Type.DATA, Type.ATTACHEMENTS, Type.UNKNOWN };
for (Type type : values) {
List<Stream> list = typeMap.get(type);
if (list != null) {
joiner.add(type.name().toLowerCase() + "(" + list.size() + ")");
}
}
return Optional.of(joiner.toString());
}
use of org.fagu.fmv.ffmpeg.metadatas.Stream in project fmv by f-agu.
the class FFHelper method encodeTox264_KeepChaptersAndSubtitles.
/**
* @param inMkvFile
* @param outMp4File
* @param locales
* @throws IOException
*/
public static void encodeTox264_KeepChaptersAndSubtitles(File inFile, File outFile, Collection<Locale> locales) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
for (Stream stream : videoMetadatas.getStreams()) {
// exclude some subtitles
// if(stream.is(Type.SUBTITLE) && ! locales.contains(stream.locale())) {
// continue;
// }
// if(stream.is(Type.AUDIO) && ! locales.contains(stream.locale())) {
// continue;
// }
outputProcessor.map().streams(stream).input(inputProcessor);
}
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23)).codecAutoSelectAAC().codecCopy(Type.SUBTITLE).overwrite();
FFExecutor<Object> executor = builder.build();
// System.out.println(executor.getCommandLine());
executor.execute();
}
use of org.fagu.fmv.ffmpeg.metadatas.Stream 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.Stream 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