use of org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation 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.operation.LinesFFMPEGOperation 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.operation.LinesFFMPEGOperation 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.operation.LinesFFMPEGOperation 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);
}
};
}
use of org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation in project fmv by f-agu.
the class AudioSampleFormat method runnable.
/**
* @return
*/
private static Runnable runnable() {
return () -> {
LinesFFMPEGOperation operation = new LinesFFMPEGOperation();
operation.addParameter("-sample_fmts");
try {
FFExecutor<List<String>> executor = new FFExecutor<>(operation);
Consumer<AudioSampleFormatHelp> cacheConsumer = HELP_CACHE.consumer();
AvailableHelp<AudioSampleFormatHelp> availableHelp = AvailableHelp.create();
availableHelp.title().legend().reader(l -> {
if (StringUtils.isBlank(l)) {
return false;
}
String name = StringUtils.substringBefore(l, " ");
int depth = Integer.parseInt(StringUtils.substringAfter(l, " ").trim());
cacheConsumer.accept(new AudioSampleFormatHelp(name, depth));
return true;
}).parse(executor.execute().getResult());
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}
Aggregations