use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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.MovieMetadatas in project fmv by f-agu.
the class FFHelper method oo.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void oo(File srcFile, File outFile) throws IOException {
final int DEFAULT_AUDIO_SAMPLE_RATE = 44100;
final int DEFAULT_AUDIO_BIT_RATE = 128000;
final int DEFAULT_AUDIO_CHANNEL = 2;
Size size = Size.valueOf(930, 500);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
// input
InputProcessor inputProcessor = builder.addMediaInputFile(srcFile);
// infos
MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(movieMetadatas, DEFAULT_AUDIO_SAMPLE_RATE);
int audioBitRate = FFMpegUtils.minAudioBitRate(movieMetadatas, DEFAULT_AUDIO_BIT_RATE);
int audioChannel = FFMpegUtils.minAudioChannel(movieMetadatas, DEFAULT_AUDIO_CHANNEL);
// filters (garder l'ordre des filters)
builder.filter(AutoRotate.create(movieMetadatas));
builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
builder.filter(Format.with(PixelFormat.YUV420P));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
// output
builder.mux(//
MP4Muxer.to(outFile).movflags(// , Movflags.FRAG_KEYFRAME, Movflags.EMPTY_MOOV
Movflags.FASTSTART)).codec(//
H264.findRecommanded().mostCompatible()).pixelFormat(// pour quicktime/safari
PixelFormat.YUV420P).codecAutoSelectAAC().audioChannel(//
audioChannel).audioBitRate(//
audioBitRate).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas in project fmv by f-agu.
the class FFHelper method extractThumbnails2GIF.
/**
* similar extractThumbnails2JPEGS(..) without 'format("image2")'
*
* @param inFile
* @param outFolder
* @param countFrame
* @return
* @throws IOException
*/
public static void extractThumbnails2GIF(File inFile, File outFile, int countFrame) throws IOException {
if (!"gif".equalsIgnoreCase(FilenameUtils.getExtension(outFile.getName()))) {
throw new IllegalArgumentException("Not a gif: " + outFile.getPath());
}
// extract images
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
// global
builder.hideBanner();
builder.logLevel(LogLevel.INFO);
// input
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
// infos
MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
VideoStream videoStream = movieMetadatas.getVideoStream();
// filter
SelectVideo selectVideo = SelectVideo.build().countFrame(videoStream, countFrame);
builder.filter(selectVideo);
// necessary ?
builder.filter(Format.with(PixelFormat.RGB8));
builder.filter(Format.with(PixelFormat.RGB24));
// output
builder.addMediaOutputFile(outFile).videoSync(VSync.PASSTHROUGH).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas 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.MovieMetadatas in project fmv by f-agu.
the class FileCache method scaleForMake.
/**
* @param inFile
* @throws IOException
*/
private void scaleForMake(File inFile) throws IOException {
OutputInfos outputInfos = project.getOutputInfos();
Size makeSize = outputInfos.getSize();
MovieMetadatas metadatas = MovieMetadatas.with(inFile).extract();
VideoStream videoStream = metadatas.getVideoStream();
if (videoStream == null) {
return;
}
Size videoSize = videoStream.size();
if (videoSize.equals(makeSize)) {
return;
}
File makeTmpFile = File.createTempFile(inFile.getName() + "-", "." + FilenameUtils.getExtension(inFile.getName()), inFile.getParentFile());
try {
makeTmpFile.delete();
if (!inFile.renameTo(makeTmpFile)) {
throw new IOException("Unable to rename " + inFile + " to " + makeTmpFile);
}
File toFile = inFile;
FFMPEGExecutorBuilder builder = FFUtils.builder(project);
// input
builder.addMediaInputFile(makeTmpFile);
// filter
builder.filter(Scale.to(makeSize, ScaleMode.fitToBox()));
// output
builder.addMediaOutputFile(toFile).format(outputInfos.getFormat()).overwrite();
FFExecutor<Object> build = builder.build();
build.execute();
} finally {
makeTmpFile.delete();
}
}
Aggregations