Search in sources :

Example 1 with TextProgressBar

use of org.fagu.fmv.textprogressbar.TextProgressBar in project fmv by f-agu.

the class Ripper method rip.

/**
 * @throws IOException
 */
public void rip() throws IOException {
    AppVersion.logMyVersion(logger::log);
    logger.log("===========================================================");
    String msg = "Analyzing DVD on " + dvdDrive + "...";
    logger.log(msg);
    String name = null;
    try (TextProgressBar bar = TextProgressBar.newBar().appendText(msg + "   ").append(new SpinnerPart()).buildAndSchedule()) {
        name = dvdName.nameOf(dvdDrive, logger);
    }
    displayAndLog("Name: " + name);
    msg = "Scanning titles...";
    logger.log(msg);
    MPlayerTitles mPlayerTitles = null;
    try (TextProgressBar bar = TextProgressBar.newBar().appendText(msg + "   ").append(new SpinnerPart()).buildAndSchedule()) {
        mPlayerTitles = titlesExtractor.extract(dvdDrive, logger);
    }
    Collection<MPlayerTitle> titles = selectTitlesPolicy.select(mPlayerTitles.getTitles());
    displayAndLog("Found " + titles.size() + " titles:");
    titles.forEach(t -> displayAndLog("   " + t.getNum() + "/" + t.getLength()));
    displayAndLog("Write to " + tmpDirectory);
    AtomicInteger currentTitle = new AtomicInteger();
    AtomicInteger currentEncoding = new AtomicInteger();
    final int prefixWidth = 30;
    int nbProgresses = titles.size() * 2;
    List<AtomicInteger> progressList = new ArrayList<>(nbProgresses);
    titles.forEach(t -> {
        // dump
        progressList.add(new AtomicInteger());
        // encode
        progressList.add(new AtomicInteger());
    });
    final String finalName = name;
    TextProgressBarBuilder builder = TextProgressBar.newBar().fixWidth(32).withText(StringUtils.abbreviate(finalName, prefixWidth) + " ");
    if (titles.size() == 1) {
        builder.fixWidth(20).with(s -> currentTitle.get() == 1 ? "reading DVD..." : currentEncoding.get() == 1 ? "encoding..." : "");
    } else {
        builder.fixWidth(19).with(s -> currentTitle.get() > 0 ? "reading DVD: " + currentTitle.get() + "/" + titles.size() : "");
        builder.fixWidth(15).with(s -> currentEncoding.get() > 0 ? "encoding: " + currentEncoding.get() + "/" + titles.size() : "");
    }
    textProgressBar = builder.append(ProgressPart.width(31).build()).fixWidth(6).leftPad().with(new PercentPart()).buildAndSchedule(() -> progressList.stream().mapToInt(AtomicInteger::get).sum() / nbProgresses);
    if (!tmpDirectory.exists() && !tmpDirectory.mkdirs()) {
        throw new IOException("Unable to make directory: " + tmpDirectory);
    }
    CountDownLatch encodingLatch = new CountDownLatch(titles.size());
    Iterator<AtomicInteger> progressIterator = progressList.iterator();
    for (MPlayerTitle title : titles) {
        AtomicInteger dumpProgress = progressIterator.next();
        AtomicInteger encodeProgress = progressIterator.next();
        currentTitle.incrementAndGet();
        String baseName = name + "-" + title.getNum();
        File vobFile = File.createTempFile(baseName + '-', ".vob", tmpDirectory);
        logger.log("Dumping title " + currentTitle + "/" + titles.size() + ": " + vobFile.getAbsolutePath());
        MPlayerDump mPlayerDump = mPlayerDumperBuilder.prepare(dvdDrive, logger).progress(dumpProgress::set).dump(title.getNum(), vobFile);
        File mp4File = new File(tmpDirectory, baseName + ".mp4");
        logger.log("Encoding title " + currentTitle + "/" + titles.size() + ": " + mp4File.getAbsolutePath());
        encode(vobFile, mp4File, mPlayerDump, encodeProgress, currentEncoding, encodingLatch);
    }
    currentTitle.set(-1);
    try {
        encodingLatch.await();
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    logger.log("End");
}
Also used : SpinnerPart(org.fagu.fmv.textprogressbar.part.SpinnerPart) MPlayerDump(org.fagu.fmv.soft.mplayer.MPlayerDump) MPlayerTitle(org.fagu.fmv.soft.mplayer.MPlayerTitle) ArrayList(java.util.ArrayList) PercentPart(org.fagu.fmv.textprogressbar.part.PercentPart) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) TextProgressBarBuilder(org.fagu.fmv.textprogressbar.TextProgressBar.TextProgressBarBuilder) MPlayerTitles(org.fagu.fmv.soft.mplayer.MPlayerTitles) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) File(java.io.File)

Example 2 with TextProgressBar

use of org.fagu.fmv.textprogressbar.TextProgressBar in project fmv by f-agu.

the class Bootstrap method basicProgress.

/**
 * @throws Exception
 */
private static void basicProgress() throws Exception {
    AtomicInteger value = new AtomicInteger();
    IntSupplier progressInPercent = value::get;
    try (TextProgressBar bar = TextProgressBar.newBar().fixWidth(25).withText("Basic progress").append(ProgressPart.width(32).build()).buildAndSchedule(progressInPercent)) {
        for (int i = 0; i < 100; i += 3) {
            value.set(i);
            Thread.sleep(100);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntSupplier(java.util.function.IntSupplier) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar)

Example 3 with TextProgressBar

use of org.fagu.fmv.textprogressbar.TextProgressBar in project fmv by f-agu.

the class VolumeInfoFile method toLine.

/**
 * @see org.fagu.fmv.mymedia.file.InfoFile#toLine(org.fagu.fmv.utils.file.FileFinder.FileFound,
 *      org.fagu.fmv.media.Media)
 */
@Override
public String toLine(FileFound fileFound, FileFinder<Media>.InfosFile infosFile) throws IOException {
    Media main = infosFile.getMain();
    MovieMetadatas metadatas = (MovieMetadatas) main.getMetadatas();
    FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
    builder.addMediaInputFile(fileFound.getFileFound());
    VolumeDetect volumeDetect = VolumeDetect.build();
    builder.filter(volumeDetect);
    builder.addMediaOutput(NullMuxer.build()).overwrite();
    FFExecutor<Object> executor = builder.build();
    if (metadatas != null) {
        OptionalInt countEstimateFrames = metadatas.getVideoStream().countEstimateFrames();
        Progress progress = executor.getProgress();
        if (countEstimateFrames.isPresent() && progress != null) {
            try (TextProgressBar bar = FFMpegProgressBar.with(progress).byFrame(countEstimateFrames.getAsInt()).build().makeBar("Detect volume")) {
                executor.execute();
            }
            System.out.println();
        }
    } else {
        executor.execute();
    }
    VolumeDetected volumeDetected = volumeDetect.getDetected();
    return volumeDetected.toString();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Progress(org.fagu.fmv.ffmpeg.operation.Progress) VolumeDetect(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) Media(org.fagu.fmv.media.Media) OptionalInt(java.util.OptionalInt) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) VolumeDetected(org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)

Example 4 with TextProgressBar

use of org.fagu.fmv.textprogressbar.TextProgressBar in project fmv by f-agu.

the class Sync method progressBar.

// ------------------------------------
/**
 * @param progressConsumer
 * @param srcItem
 * @throws IOException
 */
private void progressBar(ProgressConsumer progressConsumer, Item srcItem) throws IOException {
    AtomicLong progress = new AtomicLong();
    long startTime = System.currentTimeMillis();
    final int width = 30;
    try (TextProgressBar progressBar = TextProgressBar.newBar().append(s -> {
        StringBuilder buf = new StringBuilder();
        buf.append(StringUtils.rightPad(StringUtils.abbreviate(srcItem.getName(), width), width)).append("   ");
        long diffTime = System.currentTimeMillis() - startTime;
        String speedText = "";
        if (diffTime > 0) {
            long speed = (1000L * progress.get()) / diffTime;
            speedText = ByteSize.formatSize(speed) + "/s";
        }
        buf.append(StringUtils.rightPad(speedText, 10));
        return buf.toString();
    }).append(ProgressPart.width(42).build()).buildAndSchedule(() -> (int) ((100L * progress.get()) / srcItem.size()))) {
        progressConsumer.progress(progress);
    }
    System.out.println();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar)

Example 5 with TextProgressBar

use of org.fagu.fmv.textprogressbar.TextProgressBar in project fmv by f-agu.

the class Bootstrap method findImage.

// ---------------------------------------------------
/**
 * @param saveFile
 * @param srcFiles
 * @return
 * @throws IOException
 */
private ImageFinder findImage(File saveFile, File... srcFiles) throws IOException {
    ImageFinder imagesFinder = new ImageFinder(saveFile);
    // imagesFinder.addListener(new FileFinderListener<Image>() {
    // 
    // private int count;
    // 
    // /**
    // * @see org.fagu.fmv.utils.file.FileFinderListener#eventFind(java.io.File, java.lang.Object)
    // */
    // @Override
    // public void eventFind(File file, Image image) {
    // ImageMetadatas metadatas = image.getMetadatas();
    // String model = metadatas.getDeviceModel();
    // String device = metadatas.getDevice();
    // 
    // System.out.println(count + ": " + file.getName() + " : " + device + ", " + model);
    // ++count;
    // }
    // });
    FindProgress findProgress = new FindProgress() {

        private TextProgressBar textProgressBar = TextProgressBar.newBar().fixWidth(40).withText("Finding images").buildForPrinting();

        /**
         * @see org.fagu.fmv.utils.file.FindProgress#progress(int, int)
         */
        @Override
        public void progress(int done, int total) {
            textProgressBar.print((100 * done) / total);
        }
    };
    imagesFinder.find(Arrays.asList(srcFiles), findProgress);
    return imagesFinder;
}
Also used : ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) TextProgressBar(org.fagu.fmv.textprogressbar.TextProgressBar) FindProgress(org.fagu.fmv.utils.file.FindProgress)

Aggregations

TextProgressBar (org.fagu.fmv.textprogressbar.TextProgressBar)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 OptionalInt (java.util.OptionalInt)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IntSupplier (java.util.function.IntSupplier)1 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)1 VolumeDetect (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetect)1 VolumeDetected (org.fagu.fmv.ffmpeg.filter.impl.VolumeDetected)1 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)1 Progress (org.fagu.fmv.ffmpeg.operation.Progress)1 Media (org.fagu.fmv.media.Media)1 ImageFinder (org.fagu.fmv.mymedia.file.ImageFinder)1 MPlayerDump (org.fagu.fmv.soft.mplayer.MPlayerDump)1 MPlayerTitle (org.fagu.fmv.soft.mplayer.MPlayerTitle)1 MPlayerTitles (org.fagu.fmv.soft.mplayer.MPlayerTitles)1 TextProgressBarBuilder (org.fagu.fmv.textprogressbar.TextProgressBar.TextProgressBarBuilder)1