use of org.fagu.fmv.ffmpeg.filter.FilterInput 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.filter.FilterInput in project fmv by f-agu.
the class FilterGraph method of.
/**
* @param operation
* @param filterNaming
* @return
*/
public static FilterGraph of(Operation<?, ?> operation) {
FilterGraph filterGraph = new FilterGraph(operation.getFilterNaming());
List<FilterComplex> filterComplexs = operation.getFilterComplexs();
for (FilterComplex filterComplex : filterComplexs) {
// System.out.println(filterComplex);
Map<IOKey, In> inputMap = filterComplex.getInputMap();
if (inputMap.isEmpty()) {
for (MediaInput mediaInput : filterComplex.getInputs()) {
if (mediaInput instanceof GeneratedSource) {
filterGraph.roots.add(filterComplex);
for (OutputKey outputKey : filterComplex.getOutputKeys()) {
filterGraph.byOutMap.add(outputKey.getLabel(), filterComplex);
}
}
}
} else {
for (Entry<IOKey, In> entry : inputMap.entrySet()) {
FilterInput filterInput = entry.getValue().getFilterInput();
for (OutputKey inputKey : filterInput.getOutputKeys()) {
filterGraph.byInMap.add(inputKey.getLabel(), filterComplex);
}
if (filterInput instanceof InputProcessor) {
filterGraph.roots.add(filterComplex);
}
for (OutputKey outputKey : filterComplex.getOutputKeys()) {
filterGraph.byOutMap.add(outputKey.getLabel(), filterComplex);
}
}
}
}
return filterGraph;
}
use of org.fagu.fmv.ffmpeg.filter.FilterInput in project fmv by f-agu.
the class GenericFilterExec method populateWithIdentifiables.
// *************************************************************
/**
* @param filterComplex
* @param cache
* @param builder
* @return
*/
protected Set<Type> populateWithIdentifiables(FilterComplexBase filterComplex, Cache cache, FFMPEGExecutorBuilder builder) {
Set<Type> undeclaredTypes = new HashSet<>(filterComplex.getTypes());
for (Identifiable identifiable : getIdentifiableChildren()) {
if (identifiable.isExecutable()) {
File file = getProject().getFileCache().getFile((Executable) identifiable, cache);
InputProcessor inputProcessor = builder.addMediaInputFile(file);
addInputIntoFilter(filterComplex, inputProcessor, undeclaredTypes);
} else if (identifiable.isSource()) {
FilterInput filterInput = ((Source) identifiable).createAndAdd(builder);
addInputIntoFilter(filterComplex, filterInput, undeclaredTypes);
} else if (identifiable.isFilterExec()) {
Filter inFilter = ((FilterExec) identifiable).makeFilter(builder, cache);
addInputIntoFilter(filterComplex, (FilterComplexBase) inFilter, undeclaredTypes);
}
}
return undeclaredTypes;
}
use of org.fagu.fmv.ffmpeg.filter.FilterInput in project fmv by f-agu.
the class AudioMixExecutable method execute.
/**
* @see org.fagu.fmv.core.exec.Executable#execute()
*/
@Override
public void execute(File toFile, Cache cache) throws IOException {
if (!hasChildren()) {
return;
}
AudioMix audioMix = AudioMix.build();
FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
List<InputProcessor> inputProcessors = new ArrayList<>();
// executable
for (Executable executable : executables) {
File file = getProject().getFileCache().getFile(executable, cache);
InputProcessor inputProcessor = builder.addMediaInputFile(file);
// audioMix.addInput(inputProcessor);
inputProcessors.add(inputProcessor);
}
// source
for (Source source : sources) {
FilterInput filterInput = source.createAndAdd(builder);
if (filterInput instanceof InputProcessor) {
inputProcessors.add((InputProcessor) filterInput);
// MovieMetadatas movieMetadatas = ((InputProcessor)filterInput).getMovieMetadatas();
// if(movieMetadatas.contains(Type.AUDIO)) {
// audioMix.addInput(filterInput, audioStart);
// } else {
// throw new RuntimeException("Source is not an audio stream: " + source);
// }
} else {
throw new RuntimeException("Source is not a InputProcessor: " + source);
}
}
List<InputProcessor> videoInputProcessors = new ArrayList<>();
for (InputProcessor inputProcessor : inputProcessors) {
MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
if (movieMetadatas.contains(Type.AUDIO) && !movieMetadatas.contains(Type.VIDEO)) {
audioMix.addInput(inputProcessor, audioStart);
} else {
videoInputProcessors.add(inputProcessor);
audioMix.addInput(inputProcessor);
}
}
audioMix.duration(mixAudioDuration);
OutputProcessor outputProcessor = outputProcessor(builder, toFile, cache);
ObjectInvoker.invoke(outputProcessor, attributeMap);
builder.filter(audioMix);
Map map = outputProcessor.map();
map.allStreams().input(audioMix);
On videoStreams = map.types(Type.VIDEO);
videoInputProcessors.stream().forEach(videoStreams::input);
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.filter.FilterInput in project fmv by f-agu.
the class FilterGraphUI method addRoot.
// **************************************************
/**
*/
private void addRoot() {
Map<InputProcessor, Node> inputProcessorNodeMap = new HashMap<>();
operation.getInputProcessorStream().forEach(ip -> {
for (OutputKey outputKey : ip.getOutputKeys()) {
Node node = createRootNode(ip, outputKey);
inputProcessorNodeMap.put(ip, node);
}
});
for (FilterComplex rootFC : filterGraph.getRoots()) {
Map<IOKey, In> inputMap = rootFC.getInputMap();
if (!inputMap.isEmpty()) {
for (Entry<IOKey, In> entry : inputMap.entrySet()) {
FilterInput filterInput = entry.getValue().getFilterInput();
if (filterInput instanceof InputProcessor) {
Node node = inputProcessorNodeMap.get(filterInput);
Edge edge = graph.addEdge(node.getId() + "-" + rootFC.toString(), createOrGetNode(rootFC), node);
// edge.addAttribute("ui.label", values);
}
}
}
}
}
Aggregations