Search in sources :

Example 1 with ConverterListener

use of org.fagu.fmv.mymedia.classify.ConverterListener 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);
    }
}
Also used : FFReducer(org.fagu.fmv.mymedia.reduce.FFReducer) HashMap(java.util.HashMap) Size(org.fagu.fmv.utils.media.Size) AutoRotate(org.fagu.fmv.ffmpeg.filter.impl.AutoRotate) ConverterListener(org.fagu.fmv.mymedia.classify.ConverterListener) Map(java.util.Map) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) PrintStream(java.io.PrintStream) Rotation(org.fagu.fmv.utils.media.Rotation) Rotate(org.fagu.fmv.ffmpeg.filter.impl.Rotate) FileFinder(org.fagu.fmv.utils.file.FileFinder) FFMpegUtils(org.fagu.fmv.ffmpeg.FFMpegUtils) FFExecutor(org.fagu.fmv.ffmpeg.executor.FFExecutor) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) IOException(java.io.IOException) File(java.io.File) Volume(org.fagu.fmv.ffmpeg.filter.impl.Volume) Transpose(org.fagu.fmv.ffmpeg.filter.impl.Transpose) Logger(org.fagu.fmv.mymedia.logger.Logger) Optional(java.util.Optional) ResampleAudio(org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio) Converter(org.fagu.fmv.mymedia.classify.Converter) FilenameUtils(org.apache.commons.io.FilenameUtils) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) IOException(java.io.IOException) Rotation(org.fagu.fmv.utils.media.Rotation) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) File(java.io.File) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Example 2 with ConverterListener

use of org.fagu.fmv.mymedia.classify.ConverterListener 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)

Aggregations

File (java.io.File)2 ConverterListener (org.fagu.fmv.mymedia.classify.ConverterListener)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 FFMpegUtils (org.fagu.fmv.ffmpeg.FFMpegUtils)1 FFExecutor (org.fagu.fmv.ffmpeg.executor.FFExecutor)1 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)1 AutoRotate (org.fagu.fmv.ffmpeg.filter.impl.AutoRotate)1 ResampleAudio (org.fagu.fmv.ffmpeg.filter.impl.ResampleAudio)1 Rotate (org.fagu.fmv.ffmpeg.filter.impl.Rotate)1 Transpose (org.fagu.fmv.ffmpeg.filter.impl.Transpose)1 Volume (org.fagu.fmv.ffmpeg.filter.impl.Volume)1 VolumeDetected (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)1 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)1 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)1