Search in sources :

Example 1 with LinesFFMPEGOperation

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);
        }
    };
}
Also used : Consumer(java.util.function.Consumer) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) Reader(org.fagu.fmv.ffmpeg.utils.AvailableHelp.Reader) LinesFFMPEGOperation(org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation) IOException(java.io.IOException)

Example 2 with LinesFFMPEGOperation

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) LinesFFMPEGOperation(org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation) IOException(java.io.IOException) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) List(java.util.List)

Example 3 with LinesFFMPEGOperation

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);
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) Function(java.util.function.Function) Consumer(java.util.function.Consumer) Matcher(java.util.regex.Matcher) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) LinesFFMPEGOperation(org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation) IOException(java.io.IOException)

Example 4 with LinesFFMPEGOperation

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);
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) Function(java.util.function.Function) Consumer(java.util.function.Consumer) AvailableHelp(org.fagu.fmv.ffmpeg.utils.AvailableHelp) Matcher(java.util.regex.Matcher) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) LinesFFMPEGOperation(org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation) IOException(java.io.IOException)

Example 5 with LinesFFMPEGOperation

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);
        }
    };
}
Also used : Consumer(java.util.function.Consumer) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) LinesFFMPEGOperation(org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)5 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)5 LinesFFMPEGOperation (org.fagu.fmv.ffmpeg.operation.LinesFFMPEGOperation)5 Consumer (java.util.function.Consumer)4 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 Function (java.util.function.Function)2 HashMap (java.util.HashMap)1 List (java.util.List)1 AvailableHelp (org.fagu.fmv.ffmpeg.utils.AvailableHelp)1 Reader (org.fagu.fmv.ffmpeg.utils.AvailableHelp.Reader)1