use of org.fagu.fmv.soft.mplayer.MPlayerDump 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.soft.mplayer.MPlayerDump in project fmv by f-agu.
the class RipperTestCase method mockMPlayerDumpBuilder.
// ************************************
/**
* @return
* @throws IOException
*/
private MPlayerDumpBuilder mockMPlayerDumpBuilder() throws IOException {
MPlayerDump dump = mock(MPlayerDump.class);
MPlayerDumpBuilder builder = mock(MPlayerDumpBuilder.class);
AtomicReference<IntConsumer> progress = new AtomicReference<>();
doAnswer(invocation -> {
progress.set((IntConsumer) invocation.getArguments()[0]);
return builder;
}).when(builder).progress(any(IntConsumer.class));
doAnswer(invocation -> {
for (int i = 0; i < 100; ++i) {
Thread.sleep(30);
progress.get().accept(i);
}
return dump;
}).when(builder).dump(anyInt(), any(File.class));
return builder;
}
Aggregations