Skip to content

Commit

Permalink
New File Name Handling optimzed
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 16, 2018
1 parent 6979d3c commit 7f41db0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
34 changes: 29 additions & 5 deletions src/main/java/de/screenflow/frankenstein/MovieProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,29 +226,29 @@ public boolean process(ProcessingListener l) {
}

if (configuration.doOutput) {
new File(configuration.outputVideo).delete();
File of = findFreeFile(new File(configuration.outputVideo));

if (!configuration.doInput || !(configuration.getSource() instanceof VideoStreamSource)) {
if (configuration.doInput) {
if (!new Task(this,
ffmpeg.getAbsolutePath() + " -y -i " + tempVideoFile.getAbsolutePath() + " -i "
+ tempAudioFile.getAbsolutePath() + " -i " + tempMetadataFile.getAbsolutePath()
+ " -map_metadata 2" + " -c:a aac -c:v libx264 -q 17 \""
+ configuration.outputVideo + '"',
+ of.getAbsolutePath() + '"',
new TimeTaskHandler(l, "Assembling Output")).run())
return false;
} else {
if (!new Task(this,
ffmpeg.getAbsolutePath() + " -y -i " + tempVideoFile.getAbsolutePath() + " -i "
+ tempAudioFile.getAbsolutePath() + " -c:a aac -c:v libx264 -q 17 "
+ configuration.outputVideo,
+ of.getAbsolutePath(),
new TimeTaskHandler(l, "Processing Output")).run())
return false;
}
} else {
System.out.println("Renaming temp file "+tempVideoFile.getAbsolutePath());
tempVideoFile.renameTo(new File(configuration.outputVideo));
tempVideoFile.renameTo(of);
}
File of = new File(configuration.outputVideo);
if (!of.exists()) {
System.err.println("Missing output "+of.getAbsolutePath());
return false;
Expand All @@ -272,6 +272,30 @@ public void stopStream() {
streamStopped = true;
}

private File findFreeFile(File f) {
int i = 0;
while (f.exists()) {
f = new File(f.getParent(), numberFileName(f.getName(), ++i));
}
return f;
}

private String numberFileName(String name, int increment) {
int dotindex = name.lastIndexOf('.');
int nbrindex = name.indexOf('(');
if (nbrindex > -1 && name.indexOf(')', nbrindex+1) < 0) {
nbrindex = -1;
}
if (nbrindex<0)
nbrindex = dotindex;

if (dotindex >= 0)
return name.substring(0, nbrindex) + "(" + increment + ")" + "." + name.substring(dotindex + 1);
else
return name;
}


public static void stop() {
stopped = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public class ConfigurationSceneController {
@FXML
RadioButton rDelay;

@FXML RadioButton rCameraInput;
@FXML
RadioButton rCameraInput;

/**
* Initialize method, automatically called by @{link FXMLLoader}
Expand Down Expand Up @@ -383,8 +384,14 @@ public void rActionVideoFileInput() {
}
}

@FXML public void rActionCameraInput() {
configuration.outputVideo = "stream.mp4";
@FXML
public void rActionCameraInput() {
String lastVideoDir = configuration.getInputVideoPath();
if (lastVideoDir != null)
configuration.outputVideo = new File(new File(lastVideoDir), "stream.mp4").getAbsolutePath();
else
configuration.outputVideo = new File(new File("."), "stream.mp4").getAbsolutePath();

tfPropertyOutputFile.setText(configuration.outputVideo);
removeTab(tabVideoFileInput);
removeTab(tabSlideshow);
Expand Down Expand Up @@ -668,5 +675,4 @@ public void tbActionStereoEffectFilterEnabled() {
sliderStereoPerspective.setDisable(!stereoEffectFilterEnabled.isSelected());
}


}

0 comments on commit 7f41db0

Please sign in to comment.