use of org.fagu.fmv.ffmpeg.executor.FFExecutor in project fmv by f-agu.
the class ChannelLayout method runnable.
/**
* @return
*/
private static Runnable runnable() {
return () -> {
LinesFFMPEGOperation operation = new LinesFFMPEGOperation();
operation.addParameter("-layouts");
try {
FFExecutor<List<String>> executor = new FFExecutor<>(operation);
Consumer<ChannelLayoutHelp> cacheConsumer = HELP_CACHE.consumer();
AvailableHelp<ChannelLayoutHelp> availableHelp = AvailableHelp.create();
Reader individualReader = l -> {
if (StringUtils.isBlank(l)) {
return false;
}
String name = StringUtils.substringBefore(l, " ").trim();
ChannelLayoutHelp channelLayoutHelp = new ChannelLayoutHelp(name, true);
channelLayoutHelp.text = StringUtils.substringAfter(l, " ").trim();
cacheConsumer.accept(channelLayoutHelp);
return true;
};
Reader standardReader = l -> {
if (StringUtils.isBlank(l)) {
return false;
}
String name = StringUtils.substringBefore(l, " ").trim();
ChannelLayoutHelp channelLayoutHelp = new ChannelLayoutHelp(name, false);
channelLayoutHelp.text = StringUtils.substringAfter(l, " ").trim();
cacheConsumer.accept(channelLayoutHelp);
return true;
};
availableHelp.title().unreadLine().reader(individualReader).unreadLines(3).reader(standardReader).parse(executor.execute().getResult());
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}
use of org.fagu.fmv.ffmpeg.executor.FFExecutor in project fmv by f-agu.
the class FullHelpExtract method extract.
/**
* @return
*/
public static Map<String, Group> extract() {
LinesFFMPEGOperation operation = new LinesFFMPEGOperation();
operation.addParameter("-h", "full");
try {
FFExecutor<List<String>> executor = new FFExecutor<>(operation);
Executed<List<String>> execute = executor.execute();
Pattern paramPattern = Pattern.compile("(\\s+)([\\-\\w]+)\\s+(?:\\<(\\w+)\\>\\s+)?([EDFVASXR\\.]{8})(.*)");
int countEmpty = 0;
String currentTitle = null;
Group currentGroup = null;
Param currentParam = null;
Map<String, Group> groupMap = new HashMap<>(256);
boolean start = false;
for (String line : execute.getResult()) {
boolean isEmpty = "".equals(line);
if (isEmpty) {
++countEmpty;
if (!start && countEmpty == 2) {
start = true;
}
continue;
} else {
countEmpty = 0;
}
if (!start) {
continue;
}
if (line.charAt(0) != ' ') {
currentTitle = StringUtils.substringBefore(line, " AVOptions:");
currentGroup = null;
continue;
}
//
Matcher matcher = paramPattern.matcher(line);
if (matcher.matches()) {
String paramName = matcher.group(2);
String paramType = matcher.group(3);
Flags paramFlags = Flags.parse(matcher.group(4));
String desc = matcher.group(5);
if (desc != null) {
desc = desc.trim();
}
if (currentGroup == null) {
currentGroup = new Group(currentTitle, desc);
groupMap.put(currentTitle, currentGroup);
}
if (matcher.group(1).length() == 2) {
currentParam = new Param(paramName, ParamType.valueOf(paramType.toUpperCase()), paramFlags, desc);
currentGroup.addParam(currentParam);
} else {
currentParam.addValue(new ParamValue(paramName, paramFlags, desc));
}
} else {
System.out.println(line);
}
}
return groupMap;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.fagu.fmv.ffmpeg.executor.FFExecutor in project fmv by f-agu.
the class PixelFormat method runnable.
/**
* @return
*/
private static Runnable runnable() {
return () -> {
LinesFFMPEGOperation operation = new LinesFFMPEGOperation();
operation.addParameter("-pix_fmts");
try {
FFExecutor<List<String>> executor = new FFExecutor<>(operation);
Consumer<PixelFormatHelp> cacheConsumer = HELP_CACHE.consumer();
final Pattern pattern = Pattern.compile("(\\d+)\\s+(\\d+)");
Function<String, PixelFormatHelp> factory = PixelFormatHelp::new;
Consumer<PixelFormatHelp> consumer = help -> {
Matcher matcher = pattern.matcher(help.getText());
if (matcher.matches()) {
help.nbComponents = Integer.parseInt(matcher.group(1));
help.bitsPerPixel = Integer.parseInt(matcher.group(2));
cacheConsumer.accept(help);
} else {
throw new RuntimeException("PixelFormat description unparsable: " + help.getText());
}
};
AvailableHelp<PixelFormatHelp> availableHelp = AvailableHelp.create();
availableHelp.title().legend().unreadLines(2).values(factory, consumer).parse(executor.execute().getResult());
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}
use of org.fagu.fmv.ffmpeg.executor.FFExecutor in project fmv by f-agu.
the class MovieScriptConverter method convert.
/**
* @see org.fagu.fmv.mymedia.classify.Converter#convert(org.fagu.fmv.media.Media,
* org.fagu.fmv.utils.file.FileFinder.InfosFile, java.io.File, org.fagu.fmv.mymedia.classify.ConverterListener)
*/
@Override
public void convert(Movie srcMedia, FileFinder<Movie>.InfosFile infosFile, File destFile, ConverterListener<Movie> listener) throws IOException {
openScript();
File srcFile = srcMedia.getFile();
MovieMetadatas infos = srcMedia.getMetadatas();
int audioFrequency = FFMpegUtils.minAudioSampleRate(infos, DEFAULT_AUDIO_SAMPLE_RATE);
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
builder.addMediaInputFile(srcFile).setMovieMetadatas(infos);
Rotation rotation = rotateMap.get(srcFile.getName());
if (rotation != null) {
if (rotation != Rotation.R_0) {
builder.filter(Rotate.create(rotation));
}
} else {
builder.filter(AutoRotate.create(infos));
}
Size newSize = FFReducer.applyScaleIfNecessary(builder, infos, getMaxSize(), getScaleLogger(), rotation);
writeLabel();
script.println("rem " + (newSize.isLandscape() ? "landscape" : newSize.isPortrait() ? "portrait" : "square"));
builder.filter(ResampleAudio.build().frequency(audioFrequency));
Optional<VolumeDetected> findFirst = infosFile.getInfos().stream().filter(o -> o instanceof VolumeDetected).map(o -> (VolumeDetected) o).findFirst();
if (findFirst.isPresent()) {
VolumeDetected volumeDetected = findFirst.get();
builder.filter(Volume.build().increaseToMax(volumeDetected));
}
File dest = new File(destFile.getParentFile(), FilenameUtils.getBaseName(destFile.getName()) + ".mp4");
OutputProcessor outputProcessor = builder.addMediaOutputFile(dest);
outputProcessor.qualityScale(0);
Transpose.addMetadataRotate(outputProcessor, Rotation.R_0);
outputProcessor.format("mp4");
// outputProcessor.overwrite();
FFExecutor<Object> executor = builder.build();
try {
script.println("if exist \"" + dest.getPath() + "\" goto :movie_" + currentVideo);
script.println("echo.");
script.println("echo Frame: " + infos.getVideoStream().countEstimateFrames().getAsInt());
script.println(executor.getCommandLine());
script.println();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.fagu.fmv.ffmpeg.executor.FFExecutor in project fmv by f-agu.
the class Filters method runnable.
/**
* @return
*/
private static Runnable runnable() {
return () -> {
LinesFFMPEGOperation operation = new LinesFFMPEGOperation();
operation.addParameter("-filters");
try {
FFExecutor<List<String>> executor = new FFExecutor<>(operation);
Consumer<FilterHelp> cacheConsumer = HELP_CACHE.consumer();
final Pattern PATTERN = Pattern.compile("([AVN\\|]+)-\\>([AVN\\|]+)\\s+(\\w+.*)");
Function<String, FilterHelp> factory = name -> new FilterHelp(name);
Consumer<FilterHelp> consumer = help -> {
Matcher matcher = PATTERN.matcher(help.getText());
if (matcher.matches()) {
help.inputType = IOType.parse(matcher.group(1));
help.outputType = IOType.parse(matcher.group(2));
help.description = matcher.group(3);
cacheConsumer.accept(help);
} else {
throw new RuntimeException("Filter description unparsable: " + help.getText());
}
};
AvailableHelp<FilterHelp> availableHelp = AvailableHelp.create();
availableHelp.title().legend(true).values(factory, consumer).parse(executor.execute().getResult());
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}
Aggregations