Search in sources :

Example 6 with Filter

use of org.fagu.fmv.ffmpeg.filter.Filter in project fmv by f-agu.

the class GenericExecutable method populateWithIdentifiables.

// *******************************************************
/**
 * @param toFile
 * @param cache
 * @param builder
 */
protected List<FilterInput> populateWithIdentifiables(File toFile, Cache cache, FFMPEGExecutorBuilder builder) {
    List<FilterInput> filterInputs = new ArrayList<>();
    // executable
    for (Executable executable : executables) {
        File file = getProject().getFileCache().getFile(executable, cache);
        filterInputs.add(builder.addMediaInputFile(file));
    }
    // source
    for (Source source : sources) {
        filterInputs.add(source.createAndAdd(builder));
    }
    // filters
    for (FilterExec filterExec : getFilters()) {
        Filter filter = filterExec.makeFilter(builder, cache);
        builder.filter(filter);
        if (filter instanceof FilterComplexBase) {
            filterInputs.add((FilterComplexBase) filter);
        }
    }
    return filterInputs;
}
Also used : FilterExec(org.fagu.fmv.core.exec.FilterExec) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) ArrayList(java.util.ArrayList) FilterComplexBase(org.fagu.fmv.ffmpeg.filter.FilterComplexBase) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Example 7 with Filter

use of org.fagu.fmv.ffmpeg.filter.Filter in project fmv by f-agu.

the class AbstractOperation method add.

/**
 * @see org.fagu.fmv.ffmpeg.operation.Operation#add(Filter)
 */
@Override
public boolean add(Filter filter) {
    if (rawFilters.contains(filter)) {
        return false;
    }
    OperationListener operationListener = operationListener();
    operationListener.eventPreAddFilter(this, filter);
    addRawFilter(filter);
    if (filter instanceof FilterComplexBase) {
        if (!containsFilterComplex) {
            containsFilterComplex = true;
            List<Filter> newFilters = new ArrayList<>();
            for (Filter f : filters) {
                FilterComplex fc = FilterComplex.create(f);
                newFilters.add(fc);
                addRawFilter(fc);
            }
            filters = newFilters;
        }
        filters.add(filter);
    } else {
        if (containsFilterComplex) {
            FilterComplex fc = FilterComplex.create(filter);
            filters.add(fc);
            addRawFilter(fc);
        } else {
            filters.add(filter);
        }
    }
    if (filter instanceof LibLog) {
        libLogs.add((LibLog) filter);
    }
    operationListener.eventPostAddFilter(this, filter);
    return true;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) Filter(org.fagu.fmv.ffmpeg.filter.Filter) ArrayList(java.util.ArrayList) FilterComplexBase(org.fagu.fmv.ffmpeg.filter.FilterComplexBase)

Example 8 with Filter

use of org.fagu.fmv.ffmpeg.filter.Filter 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;
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) ArrayList(java.util.ArrayList) Label(org.fagu.fmv.ffmpeg.filter.Label) Filter(org.fagu.fmv.ffmpeg.filter.Filter)

Aggregations

Filter (org.fagu.fmv.ffmpeg.filter.Filter)8 ArrayList (java.util.ArrayList)4 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)4 File (java.io.File)3 FilterComplexBase (org.fagu.fmv.ffmpeg.filter.FilterComplexBase)3 FilterInput (org.fagu.fmv.ffmpeg.filter.FilterInput)3 Type (org.fagu.fmv.ffmpeg.operation.Type)3 FilterExec (org.fagu.fmv.core.exec.FilterExec)2 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)2 HashSet (java.util.HashSet)1 Executable (org.fagu.fmv.core.exec.Executable)1 Identifiable (org.fagu.fmv.core.exec.Identifiable)1 Source (org.fagu.fmv.core.exec.Source)1 GeneratedSource (org.fagu.fmv.ffmpeg.filter.GeneratedSource)1 Label (org.fagu.fmv.ffmpeg.filter.Label)1 Scale (org.fagu.fmv.ffmpeg.filter.impl.Scale)1 ScaleMode (org.fagu.fmv.ffmpeg.filter.impl.ScaleMode)1 AbstractOperation (org.fagu.fmv.ffmpeg.operation.AbstractOperation)1 MediaInput (org.fagu.fmv.ffmpeg.operation.MediaInput)1 Size (org.fagu.fmv.utils.media.Size)1