Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions idea.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VM Options=--module-path "C:\Users\Yermak\Programs\JavaFX\javafx-sdk-15.0.1\lib" --add-modules javafx.controls,javafx.fxml,javafx.media,javafx.base,javafx.swing,javafx.graphics
Enviromnent var=FFMPEG=external/x64/windows
3 changes: 2 additions & 1 deletion src/main/java/uk/yermak/audiobookconverter/Chapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.apache.commons.lang3.StringUtils;
import uk.yermak.audiobookconverter.fx.ConverterApplication;

import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -64,7 +65,7 @@ public String getDetails() {

@Override
public long getDuration() {
return media.stream().mapToLong(MediaInfo::getDuration).sum();
return (long) (media.stream().mapToLong(MediaInfo::getDuration).sum() / ConverterApplication.getContext().getSpeed());
}

public String getDurationString() {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/ConversionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class ConversionContext {
private final ObservableList<MediaInfo> media = FXCollections.observableArrayList();
private final ObservableList<ArtWork> posters = FXCollections.observableArrayList();
private final SimpleObjectProperty<OutputParameters> outputParameters = new SimpleObjectProperty<>(Preset.DEFAULT_OUTPUT_PARAMETERS);
private final SimpleObjectProperty<Double> speed = new SimpleObjectProperty<>(1.0);

private final static ExecutorService executorService = Executors.newCachedThreadPool();

Expand Down Expand Up @@ -114,6 +116,14 @@ public ObservableList<MediaInfo> getMedia() {
return media;
}

public Double getSpeed() {
return speed.get();
}

public ObservableValue<Double> getSpeedObservable() {
return speed;
}

public void stopConversions() {
conversionQueue.forEach(ConversionJob::stop);
}
Expand Down Expand Up @@ -172,4 +182,12 @@ public void addOutputParametersChangeListener(ChangeListener<OutputParameters> c
public void setOutputParameters(OutputParameters outputParameters) {
this.outputParameters.set(outputParameters);
}

public void addSpeedChangeListener(ChangeListener<Double> changeListener) {
speed.addListener(changeListener);
}

public void setSpeed(Double speed) {
this.speed.set(speed);
}
}
14 changes: 13 additions & 1 deletion src/main/java/uk/yermak/audiobookconverter/FFMediaLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,19 @@ static void searchForPosters(List<MediaInfo> media) {
Set<File> searchDirs = new HashSet<>();
media.forEach(mi -> searchDirs.add(new File(mi.getFileName()).getParentFile()));

searchDirs.forEach(d -> findPictures(d).forEach(f -> ConverterApplication.getContext().addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(f.getPath())))));
List<File> pictures = new ArrayList<>();

ConversionContext context = ConverterApplication.getContext();
for (File d : searchDirs) {
pictures.addAll(findPictures(d));
}

//adding artificial limit of image count to address issue #153.
if (!pictures.isEmpty()) {
for (int i = 0; i < 10 || i < pictures.size(); i++) {
context.addPosterIfMissingWithDelay(new ArtWorkBean(Utils.tempCopy(pictures.get(i).getPath())));
}
}
}


Expand Down
15 changes: 15 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/Format.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.yermak.audiobookconverter;

import uk.yermak.audiobookconverter.fx.ConverterApplication;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -279,10 +281,18 @@ public List<Integer> bitrates() {
return List.of(8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 192, 224, 256, 320);
}

public List<Double> speeds() {
return List.of(0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0);
}

public Integer defaultBitrate() {
return 128;
}

public Double defaultSpeed() {
return 1.0;
}

public Integer defaultChannel() {
return 2;
}
Expand Down Expand Up @@ -353,6 +363,11 @@ public List<String> getReencodingOptions(MediaInfo mediaInfo, String progressUri
options.add("-f");
options.add(format);

if (ConverterApplication.getContext().getSpeed() != 1.0) {
options.add("-filter:a");
options.add("atempo=" + ConverterApplication.getContext().getSpeed());
}

options.add("-progress");
options.add(progressUri);
options.add(outputFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public void initialize() {
chaptersMode.addListener((observableValue, oldValue, newValue) -> importButton.setDisable(newValue || fileList.getItems().isEmpty()));
fileList.getItems().addListener((ListChangeListener<MediaInfo>) change -> importButton.setDisable(fileList.getItems().isEmpty()));

context.addSpeedChangeListener((observableValue, oldValue, newValue) -> {
if (chaptersMode.get()) {
Platform.runLater(() -> bookStructure.updateBookStructure());
}
});
}

private void initFileOpenMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private void playMedias(MediaInfo selected) {
mediaPlayer.volumeProperty().bindBidirectional(volume.valueProperty());
mediaPlayer.volumeProperty().set(1.0);

mediaPlayer.rateProperty().bind(context.getSpeedObservable());
mediaPlayer.rateProperty().set(context.getSpeed());

timelapse.valueProperty().addListener(observable -> {
if (timelapse.isValueChanging()) {
playTime.setText(Utils.formatTime(timelapse.getValue() * 1000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class OutputController {
@FXML
private ComboBox<String> splitFileBox;

@FXML
private ComboBox<String> speedBox;


@FXML
public ComboBox<String> cutoff;
Expand Down Expand Up @@ -76,6 +79,11 @@ private void initialize() {
}
});

speedBox.valueProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue == null) return;
ConverterApplication.getContext().setSpeed(Double.valueOf(newValue));
});

outputFormatBox.getItems().addAll(Format.values());
outputFormatBox.getSelectionModel().select(0);
outputFormatBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
Expand Down Expand Up @@ -125,6 +133,7 @@ private void initialize() {
refreshCutoffs();
refreshVbrQuality();
refreshCBR();
refreshSpeeds();

ConversionContext context = ConverterApplication.getContext();
media = context.getMedia();
Expand Down Expand Up @@ -220,6 +229,13 @@ private void refreshBitrates() {
bitRate.getSelectionModel().select(String.valueOf(format.defaultBitrate()));
}

private void refreshSpeeds() {
Format format = ConverterApplication.getContext().getOutputParameters().getFormat();
speedBox.getItems().clear();
speedBox.getItems().addAll(ConverterApplication.getContext().getOutputParameters().getFormat().speeds().stream().map(String::valueOf).collect(Collectors.toList()));
speedBox.getSelectionModel().select(String.valueOf(format.defaultSpeed()));
}

private void refreshFrequencies() {
OutputParameters outputParameters = ConverterApplication.getContext().getOutputParameters();
Format format = outputParameters.getFormat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
</items>
</ComboBox>

<Label text="Speed" textAlignment="LEFT" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<ComboBox fx:id="speedBox" GridPane.columnIndex="1" GridPane.rowIndex="3" GridPane.halignment="RIGHT"/>


<Pane prefWidth="50" GridPane.columnIndex="2" GridPane.rowIndex="0" GridPane.rowSpan="3"/>

Expand Down