Search in sources :

Example 1 with Filter

use of org.fagu.fmv.ffmpeg.filter.Filter 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());
        }
    }
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) ArrayList(java.util.ArrayList) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) GeneratedSource(org.fagu.fmv.ffmpeg.filter.GeneratedSource) Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) File(java.io.File) MediaInput(org.fagu.fmv.ffmpeg.operation.MediaInput)

Example 2 with Filter

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

the class GenericFilterExec method makeFilter.

/**
 * @see org.fagu.fmv.core.exec.FilterExec#makeFilter(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder, Cache)
 */
@Override
public Filter makeFilter(FFMPEGExecutorBuilder builder, Cache cache) {
    Filter filter = getFilter();
    // parameters
    ObjectInvoker.invoke(filter, attributeMap);
    FilterComplexBase filterComplex = filter instanceof FilterComplexBase ? (FilterComplexBase) filter : FilterComplex.create(filter);
    builder.filter(filterComplex);
    Set<Type> undeclaredTypes = populateWithIdentifiables(filterComplex, cache, builder);
    if (!undeclaredTypes.isEmpty()) {
        undeclaredTypes(undeclaredTypes, filterComplex, cache, builder);
    }
    return filterComplex;
}
Also used : Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterComplexBase(org.fagu.fmv.ffmpeg.filter.FilterComplexBase)

Example 3 with Filter

use of org.fagu.fmv.ffmpeg.filter.Filter 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;
}
Also used : FilterExec(org.fagu.fmv.core.exec.FilterExec) Type(org.fagu.fmv.ffmpeg.operation.Type) Filter(org.fagu.fmv.ffmpeg.filter.Filter) FilterInput(org.fagu.fmv.ffmpeg.filter.FilterInput) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) File(java.io.File) HashSet(java.util.HashSet) Identifiable(org.fagu.fmv.core.exec.Identifiable)

Example 4 with Filter

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

the class Libx264NotDisibleBy2FFExecFallback method prepare.

/**
 * @see org.fagu.fmv.ffmpeg.executor.FFExecFallback#prepare(org.fagu.fmv.ffmpeg.executor.FFEnv, java.io.IOException)
 */
@Override
public boolean prepare(FFEnv ffEnv, IOException ioException) throws IOException {
    FFExecutor<Object> executor = ffEnv.getExecutor();
    AbstractOperation<?, ?> operation = (AbstractOperation<?, ?>) ffEnv.getOperation();
    for (String line : executor.getOutputReadLine().getLines()) {
        if (line.startsWith("[libx264 @") && line.contains(" not divisible by 2")) {
            for (Filter filter : operation.getFilters()) {
                if (filter instanceof Scale) {
                    Scale scale = (Scale) filter;
                    Size size = scale.getSize();
                    ScaleMode scaleMode = scale.getScaleMode();
                    if (size != null && scaleMode != null) {
                        Size newSize = resize(size);
                        if (newSize == null) {
                            return false;
                        }
                        scale.set(size, scaleMode);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : AbstractOperation(org.fagu.fmv.ffmpeg.operation.AbstractOperation) Filter(org.fagu.fmv.ffmpeg.filter.Filter) Size(org.fagu.fmv.utils.media.Size) Scale(org.fagu.fmv.ffmpeg.filter.impl.Scale) ScaleMode(org.fagu.fmv.ffmpeg.filter.impl.ScaleMode)

Example 5 with Filter

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

the class Concat method addPTS.

// ****************************************************
/**
 * @param builder
 * @param setPTS
 * @param input
 */
private void addPTS(FFMPEGExecutorBuilder builder, SetPTS<?> setPTS, Object input) {
    setPTS.startAtFirstFrame();
    FilterComplex setPTSComplex = FilterComplex.create(setPTS);
    setPTSComplex.addInput((FilterInput) input, setPTS.getTypes().iterator().next());
    if (input instanceof Filter) {
        builder.filter((Filter) input);
    }
    builder.filter(setPTSComplex);
    super.addInput(setPTSComplex);
}
Also used : FilterComplex(org.fagu.fmv.ffmpeg.filter.FilterComplex) 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