use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.
the class Concat method beforeAddAround.
// ****************************************************
/**
* @param operation
* @param filterNaming
*/
@Override
protected void beforeAddAround(Operation<?, ?> operation, FilterNaming filterNaming) {
// copy pour acces concurrent
ArrayList<Object> arrayList = new ArrayList<>(inputs);
for (Object input : arrayList) {
Object inputObj = null;
Set<Type> types = Collections.emptySet();
if (input instanceof File) {
InputProcessor inputProcessor = builder.addMediaInputFile((File) input);
inputObj = inputProcessor;
types = getTypes(inputProcessor);
} else if (input instanceof InputProcessor) {
types = getTypes((InputProcessor) input);
inputObj = input;
} else if (input instanceof FilterComplex) {
inputObj = input;
types = ((FilterComplex) input).getTypes();
} else if (input instanceof Filter) {
throw new IllegalArgumentException("Filter forbidden: " + input.getClass().getName() + ". Wrap it with FilterComplex.create(...).");
}
if (startAtStartTime && inputObj != null) {
boolean startAt = true;
FilterInput filterInput = (FilterInput) inputObj;
for (MediaInput mediaInput : filterInput.getInputs()) {
if (mediaInput instanceof GeneratedSource) {
startAt = false;
break;
}
}
if (startAt) {
if (types.contains(Type.VIDEO) && (countVideo == null || countVideo != 0)) {
addPTS(builder, SetPTSVideo.build(), inputObj);
}
if (types.contains(Type.AUDIO) && (countAudio == null || countAudio != 0)) {
addPTS(builder, SetPTSAudio.build(), inputObj);
}
} else {
builder.filter((Filter) inputObj);
super.addInput((FilterInput) inputObj);
}
} else if (input instanceof FilterInput) {
builder.filter((Filter) inputObj);
super.addInput((FilterInput) input);
} else {
throw new IllegalArgumentException(input.getClass().getName());
}
}
}
use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.
the class Reduce method doIt.
/**
* @param sourceFile
* @throws IOException
*/
private static void doIt(File sourceFile) throws IOException {
String extension = FilenameUtils.getExtension(sourceFile.getName()).toLowerCase();
if (!"mkv".equals(extension)) {
extension = "mp4";
}
File destinationFile = new File(sourceFile.getParentFile(), FilenameUtils.getBaseName(sourceFile.getName()) + "-new." + extension);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
InputProcessor inputProcessor = builder.addMediaInputFile(sourceFile);
MovieMetadatas videoMetadatas = inputProcessor.getMovieMetadatas();
boolean doVideo = !videoMetadatas.getVideoStream().isTreatedByFMV();
boolean doAudio = doVideo;
Collection<AudioStream> audioStreams = StreamOrder.sort(videoMetadatas.getAudioStreams());
for (AudioStream audioStream : audioStreams) {
if ("vorbis".equals(audioStream.codecName().get())) {
doAudio |= true;
break;
}
if ("aac".equals(audioStream.codecName().get())) {
doAudio = false;
break;
}
}
if (!doVideo && !doAudio) {
return;
}
OutputProcessor outputProcessor = builder.addMediaOutputFile(destinationFile);
outputProcessor.qualityScale(0);
// video
for (Stream stream : videoMetadatas.getVideoStreams()) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// audio
for (Stream stream : audioStreams) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// subtitle
Collection<SubtitleStream> subtitleStreams = StreamOrder.sort(videoMetadatas.getSubtitleStreams());
for (Stream stream : subtitleStreams) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
// other stream
for (Stream stream : videoMetadatas.getStreams()) {
Type type = stream.type();
if (type != Type.AUDIO && type != Type.VIDEO && type != Type.SUBTITLE) {
outputProcessor.map().streams(stream).input(inputProcessor);
}
}
// ------------------------ disposition default ------------------------
//
int count = 0;
for (Stream stream : audioStreams) {
boolean beDefault = count == 1;
if (stream.isDefaultStream() != beDefault) {
outputProcessor.metadataStream(Type.AUDIO, count, "disposition:default", beDefault ? "1" : "0");
}
++count;
}
count = 0;
for (Stream stream : subtitleStreams) {
boolean beDefault = count == 1;
if (stream.isDefaultStream() != beDefault) {
outputProcessor.metadataStream(Type.SUBTITLE, count, "disposition:default", beDefault ? "1" : "0");
}
++count;
}
// video
if (doVideo) {
outputProcessor.codec(H264.findRecommanded().strict(Strict.EXPERIMENTAL).quality(23));
} else {
outputProcessor.codecCopy(Type.VIDEO);
}
// audio
if (doAudio) {
outputProcessor.codecAutoSelectAAC();
} else {
outputProcessor.codecCopy(Type.AUDIO);
}
// subtitle
if (videoMetadatas.contains(Type.SUBTITLE)) {
outputProcessor.codecCopy(Type.SUBTITLE);
}
// outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
}
use of org.fagu.fmv.ffmpeg.operation.Type in project fmv by f-agu.
the class Bootstrap method populateDefaultColumns.
// ****************************************************
/**
*/
private void populateDefaultColumns() {
columns.add(new NameColumn());
columns.add(new VideoHDColumn());
columns.add(new VideoSizeColumn());
columns.add(new VideoSizeNameColumn());
columns.add(new VideoSizeWidthColumn());
columns.add(new VideoSizeHeightColumn());
columns.add(new VideoRatioColumn());
columns.add(new VideoRatioFloatColumn());
columns.add(new VideoPixelsColumn());
columns.add(new VideoDurationColumn());
columns.add(new VideoCodecNameColumn());
columns.add(new VideoCodecLongNameColumn());
columns.add(new CategoryColumn(0));
columns.add(new CategoryColumn(1));
columns.add(new CategoryColumn(2));
columns.add(new SizeBytesColumn());
columns.add(new LastModifiedDateColumn());
columns.add(new AudioColumn());
columns.add(new AudioCodecNameColumn());
columns.add(new AudioCodecLongNameColumn());
columns.add(new VideoSubtitleColumn());
for (Type type : Type.values()) {
columns.add(new StreamTypeCountColumn(type));
}
columns.add(new FMVTreatedColumn());
columns.add(new PathColumn());
}
use of org.fagu.fmv.ffmpeg.operation.Type 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.operation.Type in project fmv by f-agu.
the class FilterGraphUI method getEdgeKey.
/**
* @param label
* @return
*/
private String getEdgeKey(Label label, FilterComplex filterComplex) {
StringBuilder buf = new StringBuilder();
buf.append(filterNaming.generate(label)).append('-');
for (Type type : filterComplex.getTypes()) {
buf.append(Character.toUpperCase(type.code()));
}
return buf.toString();
}
Aggregations