use of org.fagu.fmv.ffmpeg.filter.Label in project fmv by f-agu.
the class FilterGraph method discover.
// ***************************************************
/**
* @param inLabel
* @param filterComplex
* @param outLabel
* @param visitor
* @param depth
*/
private <T> void discover(Label inLabel, FilterComplex filterComplex, Visitor<T> visitor, int depth) {
for (OutputKey outputKey : filterComplex.getOutputKeys()) {
Label outLabel = outputKey.getLabel();
Set<FilterComplex> inFilters = null;
if (inLabel != null) {
inFilters = byOutMap.get(inLabel);
}
Set<FilterComplex> outFilters = byInMap.get(outLabel);
visitor.visit(inLabel, inFilters, filterComplex, outFilters, outLabel, depth);
if (outFilters != null) {
for (FilterComplex childFC : outFilters) {
discover(outLabel, childFC, visitor, depth + 1);
}
}
}
}
use of org.fagu.fmv.ffmpeg.filter.Label in project fmv by f-agu.
the class FilterGraphUI method addTail.
/**
*/
private void addTail() {
// TODO autoMap by outputProcessor
AutoMap autoMap = operation.getAutoMap();
Set<Label> labels = autoMap.find(operation);
Node node = graph.addNode("output");
node.addAttribute("ui.label", "output");
node.addAttribute("ui.class", "root");
for (Label label : labels) {
// System.out.println(filterNaming.generate(label));
Set<FilterComplex> fcs = filterGraph.getByOut(label);
for (FilterComplex outFC : fcs) {
Node inNode = createOrGetNode(outFC);
graph.addEdge("output" + label, inNode, node);
}
}
}
use of org.fagu.fmv.ffmpeg.filter.Label in project fmv by f-agu.
the class AbstractOperation method toArguments.
/**
* @see org.fagu.fmv.ffmpeg.operation.Operation#toArguments()
*/
@Override
public List<String> toArguments() {
OperationListener operationListener = operationListener();
operationListener.eventPreToArguments(this);
List<String> arguments = new ArrayList<>();
// global
getGlobalParameters().toArguments(arguments);
// input
getInputParameters().toArguments(arguments);
// filter_complex
if (containsFilterComplexs()) {
List<FilterComplex> filterComplexs = getFilterComplexs();
arguments.add("-filter_complex");
StringBuilder fbuf = new StringBuilder();
Iterator<FilterComplex> it = filterComplexs.iterator();
boolean useLabels = autoMap.useLabels();
for (; ; ) {
FilterComplex f = it.next();
if (!useLabels) {
f.clearInput();
f.clearOutput();
}
fbuf.append(f.toString());
if (!it.hasNext()) {
break;
}
fbuf.append(';');
}
arguments.add(fbuf.toString());
if (!containsMap()) {
// auto-map
try {
for (Label label : autoMap.find(this)) {
arguments.add("-map");
arguments.add(filterNaming.generateBrackets(label));
}
} catch (RuntimeException e) {
throw new RuntimeException(arguments.toString(), e);
}
}
} else {
// filter
for (Type type : Type.values()) {
StringBuilder fbuf = new StringBuilder();
List<Filter> filterSimples = getFilterSimples(type);
if (!filterSimples.isEmpty()) {
Iterator<Filter> it = filterSimples.iterator();
for (; ; ) {
Filter f = it.next();
fbuf.append(f.toString());
if (!it.hasNext()) {
break;
}
fbuf.append(',');
}
String fstr = fbuf.toString();
if (StringUtils.isNotBlank(fstr)) {
arguments.add("-filter:" + type.code());
arguments.add(fstr);
}
}
}
}
// output
getOutputParameters().toArguments(arguments);
operationListener.eventPostToArguments(this);
return arguments;
}
use of org.fagu.fmv.ffmpeg.filter.Label in project fmv by f-agu.
the class AutoMaps method oneStreamByType.
/**
* @param types
* @return
*/
public static AutoMap oneStreamByType(Set<Type> types, FilterNaming filterNaming) {
return new AutoMap() {
@Override
public boolean useLabels() {
return true;
}
@Override
public Set<Label> find(Operation<?, ?> operation) {
FilterGraph filterGraph = FilterGraph.of(operation);
// filterGraph.discover(() -> Visitors.checkSameTypes());
MapSet<Label, Type> mapSet = MultiValueMaps.hashMapHashSet();
filterGraph.discover(() -> Visitors.lastLabelWithType(mapSet));
Map<Type, Label> chdirMap = new HashMap<>(4);
for (Entry<Label, Set<Type>> entry : mapSet.entrySet()) {
for (Type type : entry.getValue()) {
if (chdirMap.putIfAbsent(type, entry.getKey()) != null) {
throw new RuntimeException("Type " + type + " already defined in an other output filter: " + mapSet);
}
}
}
for (Type type : types) {
// missing some types ?
if (!chdirMap.containsKey(type)) {
InputParameters inputParameters = operation.getInputParameters();
for (IOEntity ioEntity : inputParameters.getIOEntities()) {
Processor<?> processor = inputParameters.getProcessor(ioEntity);
if (processor instanceof InputProcessor) {
try {
MovieMetadatas movieMetadatas = ((InputProcessor) processor).getMovieMetadatas();
if (movieMetadatas.contains(type)) {
chdirMap.put(type, Label.input(processor.getIndex(), type));
break;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
return new HashSet<>(chdirMap.values());
}
};
}
Aggregations