use of org.fagu.fmv.ffmpeg.filter.FilterComplex 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.FilterComplex 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.FilterComplex 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.FilterComplex in project fmv by f-agu.
the class FilterGraph method discover.
/**
* @param visitorSupplier
*/
public <T> void discover(Supplier<Visitor<T>> visitorSupplier) {
for (FilterComplex fcRoot : roots) {
Visitor<T> visitor = visitorSupplier.get();
discover(null, fcRoot, visitor, 0);
visitor.close();
}
}
use of org.fagu.fmv.ffmpeg.filter.FilterComplex in project fmv by f-agu.
the class Test method concatFade1.
public static void concatFade1(File in1VideoFile, File in2VideoFile, Duration fadeDuration, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor video1InputProcessor = builder.addMediaInputFile(in1VideoFile);
InputProcessor video2InputProcessor = builder.addMediaInputFile(in2VideoFile);
VideoStream videoStream1 = video1InputProcessor.getMovieMetadatas().getVideoStream();
VideoStream videoStream2 = video2InputProcessor.getMovieMetadatas().getVideoStream();
Time startTime_T1 = Time.valueOf(videoStream1.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_0_T1 = Duration.valueOf(startTime_T1.toSeconds());
Time startTime_T2 = Time.valueOf(videoStream2.duration().get().toSeconds() - fadeDuration.toSeconds());
Duration duration_T2_END = Duration.valueOf(startTime_T2.toSeconds());
// source 1
NullSourceVideo nullSourceVideo1 = NullSourceVideo.build().size(videoStream1.size()).duration(duration_T2_END);
AudioGenerator audioGenerator1 = AudioGenerator.build().silence().duration(duration_T2_END);
Concat concat1 = Concat.create(builder, video1InputProcessor, FilterComplex.create(nullSourceVideo1), FilterComplex.create(audioGenerator1));
FilterComplex fadeAudio1 = FilterComplex.create(FadeAudio.out().startTime(startTime_T1).duration(fadeDuration)).addInput(concat1);
// source 2
NullSourceVideo nullSourceVideo2 = NullSourceVideo.build().size(videoStream2.size()).duration(duration_0_T1);
AudioGenerator audioGenerator2 = AudioGenerator.build().silence().duration(duration_0_T1);
Concat concat2 = Concat.create(builder, FilterComplex.create(nullSourceVideo2), FilterComplex.create(audioGenerator2), video2InputProcessor);
FilterComplex fadeAudio2 = FilterComplex.create(FadeAudio.in().startTime(startTime_T1).duration(fadeDuration)).addInput(concat2);
// blend for fade / merge
// video
SetSAR setSAR = SetSAR.toRatio("1");
Format formatRGBA = Format.with(PixelFormat.RGBA);
FilterComplex vfc1 = FilterComplex.create(setSAR, formatRGBA).addInput(concat1);
FilterComplex vfc2 = FilterComplex.create(setSAR, formatRGBA).addInput(concat2);
Blend blend = Blend.build().mode(Mode.ADDITION).repeatLast(true).opacity(1).exprFade(startTime_T1, fadeDuration);
Format formatYUV = Format.with(PixelFormat.YUVA422P10LE);
FilterComplex vfcBlend = FilterComplex.create(blend, formatYUV).addInput(vfc1).addInput(vfc2);
builder.filter(vfcBlend);
// audio
FilterComplex audioMix = AudioMix.build().duration(MixAudioDuration.SHORTEST).addInput(fadeAudio1).addInput(fadeAudio2);
builder.filter(audioMix);
// out
OutputProcessor outputProcessor = builder.addMediaOutputFile(outFile);
outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
FilterGraphUI.show(builder.getFFMPEGOperation());
// executor.execute();
}
Aggregations