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");
}
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);
}
}
}
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();
}
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();
}
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;
}
Aggregations