Search in sources :

Example 1 with ReduceImageConverter

use of org.fagu.fmv.mymedia.classify.image.ReduceImageConverter in project fmv by f-agu.

the class Images method prepare.

/**
 * @param size
 */
public PreparedImages prepare(Size size) throws IOException {
    final int COUNT_TOTAL = getImages().size();
    File destFolder = new File(sourceFolder.getParent(), sourceFolder.getName() + "-img2mov");
    if (destFolder.exists()) {
        File[] listFiles = destFolder.listFiles(f -> f.getName().startsWith("img_"));
        if (listFiles.length == COUNT_TOTAL) {
            return new PreparedImages(Arrays.asList(listFiles));
        }
    }
    final AtomicInteger count = new AtomicInteger();
    ConverterListener<Image> converterListener = new ConverterListener<Image>() {

        /**
         * @see org.fagu.fmv.mymedia.classify.ConverterListener#eventPreConvert(org.fagu.fmv.media.Media,
         *      java.io.File)
         */
        @Override
        public void eventPreConvert(Image srcMedia, File destFile) {
            System.out.println("Convert (" + count.incrementAndGet() + "/" + COUNT_TOTAL + "): " + srcMedia.getFile());
        }
    };
    try (ReduceImageConverter converter = new ReduceImageConverter(destFolder)) {
        converter.setSize(size);
        try (Classifier<ImageFinder, Image> classifier = ClassifierFactories.imagesToMovie().create(imageFinder, destFolder)) {
            return new PreparedImages(classifier.classify(converter, converterListener));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) ConverterListener(org.fagu.fmv.mymedia.classify.ConverterListener) Image(org.fagu.fmv.im.Image) File(java.io.File) ReduceImageConverter(org.fagu.fmv.mymedia.classify.image.ReduceImageConverter)

Example 2 with ReduceImageConverter

use of org.fagu.fmv.mymedia.classify.image.ReduceImageConverter in project fmv by f-agu.

the class DefaultClassifierProvider method getConverter.

/**
 * @see org.fagu.fmv.mymedia.classify.ClassifierProvider#getConverter(java.lang.Class)
 */
@SuppressWarnings("unchecked")
@Override
public <M extends Media> List<Converter<M>> getConverter(Class<? extends M> mediaCls, File destFolder) {
    List<Converter<M>> list = new ArrayList<>();
    list.add((Converter<M>) new MoveConverter(destFolder));
    if (mediaCls == Image.class) {
        list.add((Converter<M>) new ReduceImageConverter(destFolder));
    } else if (mediaCls == Movie.class) {
        list.add((Converter<M>) new MovieScriptConverter(destFolder));
    }
    return list;
}
Also used : Movie(org.fagu.fmv.mymedia.classify.movie.Movie) MovieScriptConverter(org.fagu.fmv.mymedia.classify.movie.MovieScriptConverter) ArrayList(java.util.ArrayList) MovieScriptConverter(org.fagu.fmv.mymedia.classify.movie.MovieScriptConverter) ReduceImageConverter(org.fagu.fmv.mymedia.classify.image.ReduceImageConverter) ReduceImageConverter(org.fagu.fmv.mymedia.classify.image.ReduceImageConverter)

Aggregations

ReduceImageConverter (org.fagu.fmv.mymedia.classify.image.ReduceImageConverter)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Image (org.fagu.fmv.im.Image)1 ConverterListener (org.fagu.fmv.mymedia.classify.ConverterListener)1 Movie (org.fagu.fmv.mymedia.classify.movie.Movie)1 MovieScriptConverter (org.fagu.fmv.mymedia.classify.movie.MovieScriptConverter)1 ImageFinder (org.fagu.fmv.mymedia.file.ImageFinder)1