Skip to content

Commit

Permalink
Stream input added
Browse files Browse the repository at this point in the history
  • Loading branch information
olir committed Mar 17, 2018
1 parent 7f41db0 commit 6cae763
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 35 deletions.
34 changes: 31 additions & 3 deletions src/main/java/de/screenflow/frankenstein/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.screenflow.frankenstein.vf.VideoSource;
import de.screenflow.frankenstein.vf.input.CameraInput;
import de.screenflow.frankenstein.vf.input.SlideShowInput;
import de.screenflow.frankenstein.vf.input.StreamInput;
import de.screenflow.frankenstein.vf.input.TestImageInput;
import de.screenflow.frankenstein.vf.input.VideoInput;

Expand All @@ -50,7 +51,10 @@ public class Configuration {

private String inputVideo = null;
public String outputVideo = null;

private String recordingVideo = null;
private String inputVideoStreamURL = null;


public int limitOutputWidth = 2880;

public int testScreenWidth = 1280;
Expand Down Expand Up @@ -88,7 +92,7 @@ public static Configuration cliCreateConfiguration(String[] args) {
configuration.setVisual(optionKeyIndex>=0);

optionKeyIndex = getOptionIndex(args, "source");
optionValue = getOptionValue(args, "source", "test", optionKeyIndex, "file", "test", "slides", "camera");
optionValue = getOptionValue(args, "source", "test", optionKeyIndex, "file", "test", "slides", "camera", "stream");
optionProperties = getOptionProperties(args, optionKeyIndex);
cliConfigureSource(configuration, optionValue, optionProperties);

Expand All @@ -105,11 +109,13 @@ private static void cliConfigureSource(Configuration configuration, String optio
Properties optionProperties) {
switch (optionValue) {
case "file":
configuration.source = new VideoInput(optionProperties.getProperty("file", "."));
configuration.source = new VideoInput(optionProperties.getProperty("file", null));
case "slides":
configuration.source = new SlideShowInput(optionProperties.getProperty("dir", "."));
case "camera":
configuration.source = new CameraInput(0);
case "stream":
configuration.source = new StreamInput(optionProperties.getProperty("stream", null), optionProperties.getProperty("file", null));
default:
case "test":
configuration.source = new TestImageInput(Integer.valueOf(optionProperties.getProperty("width", "1024")),
Expand Down Expand Up @@ -276,10 +282,32 @@ public void setInputVideo(String inputVideo) {
savePreferences();
}

public String getRecordingVideo() {
return recordingVideo;
}

public void setRecordingVideo(String recordingVideo) {
this.recordingVideo = recordingVideo;
iniProperties.setProperty("recordingvideopath", new File(recordingVideo).getParent());
savePreferences();
}

public String getInputVideoPath() {
return iniProperties.getProperty("inputvideopath");
}

public String getInputStreamURL() {
return inputVideoStreamURL;
}

public void setInputStreamURL(String inputVideoStreamURL) {
this.inputVideoStreamURL = inputVideoStreamURL;
}

public String getRecordingVideoPath() {
return iniProperties.getProperty("recordingvideopath", iniProperties.getProperty("inputvideopath"));
}

public interface ConfigHelper {
public File getFFmpegPath();

Expand Down
31 changes: 14 additions & 17 deletions src/main/java/de/screenflow/frankenstein/MovieProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void processStreamFrame(ProcessingListener l) {
} else {
if (l != null)
l.prematureEnd(1);
return;
}
}

Expand Down Expand Up @@ -182,7 +181,7 @@ public boolean process(ProcessingListener l) {
currentPos = configuration.getSource().seek(i, l);
frame = configuration.getSource().getFrame();
} else {
((VideoStreamSource)configuration.getSource()).pause();
((VideoStreamSource) configuration.getSource()).pause();
frame = configuration.getSource().getFrame();
}
if (frame != null && !frame.empty()) {
Expand Down Expand Up @@ -227,14 +226,12 @@ public boolean process(ProcessingListener l) {

if (configuration.doOutput) {
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 \""
+ of.getAbsolutePath() + '"',
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 \"" + of.getAbsolutePath() + '"',
new TimeTaskHandler(l, "Assembling Output")).run())
return false;
} else {
Expand All @@ -246,11 +243,11 @@ public boolean process(ProcessingListener l) {
return false;
}
} else {
System.out.println("Renaming temp file "+tempVideoFile.getAbsolutePath());
System.out.println("Renaming temp file " + tempVideoFile.getAbsolutePath());
tempVideoFile.renameTo(of);
}
if (!of.exists()) {
System.err.println("Missing output "+of.getAbsolutePath());
System.err.println("Missing output " + of.getAbsolutePath());
return false;
} else {
System.out.println("Video created: " + of.getAbsolutePath());
Expand All @@ -260,8 +257,9 @@ public boolean process(ProcessingListener l) {
tempMetadataFile.delete();
}
} finally {
// if (!configuration.doInput || !(configuration.getSource() instanceof VideoStreamSource))
// closeInput();
// if (!configuration.doInput || !(configuration.getSource()
// instanceof VideoStreamSource))
// closeInput();
closeOutput();
openOutput(null);
}
Expand All @@ -283,19 +281,18 @@ private File findFreeFile(File f) {
private String numberFileName(String name, int increment) {
int dotindex = name.lastIndexOf('.');
int nbrindex = name.indexOf('(');
if (nbrindex > -1 && name.indexOf(')', nbrindex+1) < 0) {
if (nbrindex > -1 && name.indexOf(')', nbrindex + 1) < 0) {
nbrindex = -1;
}
if (nbrindex<0)
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 @@ -17,9 +17,11 @@

import org.opencv.core.Mat;

import de.screenflow.frankenstein.vf.VideoStreamSource;

public interface ProcessingListener {
void videoStarted(int frames, double fps);
void nextFrameLoaded(Mat frame);
void nextFrameLoaded(VideoStreamSource s);
void nextFrameProcessed(Mat frame, int frameId);
void seekDone(int frameId);
void seeking(int i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import de.screenflow.frankenstein.vf.global.StereoEffect;
import de.screenflow.frankenstein.vf.input.CameraInput;
import de.screenflow.frankenstein.vf.input.SlideShowInput;
import de.screenflow.frankenstein.vf.input.StreamInput;
import de.screenflow.frankenstein.vf.input.TestImageInput;
import de.screenflow.frankenstein.vf.input.VideoInput;
import javafx.beans.property.StringProperty;
Expand All @@ -49,6 +50,7 @@
import javafx.scene.control.Slider;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.input.InputMethodEvent;

public class ConfigurationSceneController {

Expand All @@ -63,6 +65,7 @@ public class ConfigurationSceneController {
private Configuration configuration;
private FileChooser.ExtensionFilter inputFileFilter = new FileChooser.ExtensionFilter("Video Files", "*.mp4",
"*.avi", "*.wmv", "*.mks", "*.mpg", "*.mov");
private FileChooser.ExtensionFilter recordingFileFilter = new FileChooser.ExtensionFilter("Video Files", "*.mp4");

@FXML
RadioButton rVideoFileInput;
Expand Down Expand Up @@ -202,6 +205,15 @@ public class ConfigurationSceneController {
@FXML
RadioButton rCameraInput;

@FXML
RadioButton rStreamInput;

@FXML Tab tabVideoStreamInput;

@FXML TextField tfPropertyInputStream;

@FXML TextField tfPropertyRecordingFile;

/**
* Initialize method, automatically called by @{link FXMLLoader}
*/
Expand Down Expand Up @@ -292,6 +304,11 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
int newPerspective = newvalue.intValue();
configuration.perspective = newPerspective;
});

configuration.setInputStreamURL(tfPropertyInputStream.getText());
tfPropertyInputStream.textProperty().addListener((observable, oldValue, newValue) -> {
configuration.setInputStreamURL(tfPropertyInputStream.getText());
});
}

public void configure(FxMain main, Stage stage) {
Expand All @@ -315,6 +332,9 @@ public void doneButtonPressed(ActionEvent event) {
filters.add((VideoFilter) configuration.getSource());
} else if (rCameraInput.isSelected()) {
configuration.setSource(new CameraInput(0));
} else if (rStreamInput.isSelected()) {
configuration.setSource(new StreamInput(configuration.getInputStreamURL(), configuration.getRecordingVideo()));
configuration.doInput = true;
} else {
throw new Error("No Input Method.");
}
Expand Down Expand Up @@ -381,6 +401,7 @@ public void rActionVideoFileInput() {
addTab(tabVideoFileInput);
removeTab(tabSlideshow);
removeTab(tabTestVideoGenerator);
removeTab(tabVideoStreamInput);
}
}

Expand All @@ -396,6 +417,21 @@ public void rActionCameraInput() {
removeTab(tabVideoFileInput);
removeTab(tabSlideshow);
removeTab(tabTestVideoGenerator);
removeTab(tabVideoStreamInput);
}

@FXML
public void rActionStreamInput() {
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);
removeTab(tabTestVideoGenerator);
}

private File chooseInputVideo() {
Expand Down Expand Up @@ -429,6 +465,7 @@ private File chooseInputVideo() {
addTab(tabVideoFileInput);
removeTab(tabSlideshow);
removeTab(tabTestVideoGenerator);
removeTab(tabVideoStreamInput);
tfPropertyInputFile.setText(file.getAbsolutePath());
return file;
} else {
Expand All @@ -437,6 +474,49 @@ private File chooseInputVideo() {
}
}

private File chooseRecordingVideo() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Video Recording File");
fileChooser.getExtensionFilters().add(recordingFileFilter);
String lastVideoDir = configuration.getRecordingVideoPath();

if (configuration.getRecordingVideo() != null) {
File f = new File(configuration.getRecordingVideo());
if (!f.isDirectory())
f = f.getParentFile();
if (f == null || !f.isDirectory())
f = new File(".");
fileChooser.setInitialDirectory(f);
} else if (lastVideoDir != null)
fileChooser.setInitialDirectory(new File(lastVideoDir));
else
fileChooser.setInitialDirectory(new File("."));

File file = fileChooser.showSaveDialog(stage);
if (!file.getName().endsWith(".mp4")) {
file = new File(file.getParentFile(), file.getName().replaceAll("\\..*", ".mp4"));
}
if (file != null && !file.isDirectory()) {
configuration.setRecordingVideo(file.getAbsolutePath());
configuration.outputVideo = configuration.getRecordingVideo().substring(0,
configuration.getRecordingVideo().lastIndexOf('.')) + "_edit" + ".mp4";
tfPropertyOutputFile.setText(configuration.outputVideo);
main.setDocumentInTitle(file.getName());
if (rCloneLR.isSelected())
rNoNormalization.setSelected(true);
addTab(tabVideoStreamInput);
removeTab(tabVideoFileInput);
removeTab(tabSlideshow);
removeTab(tabTestVideoGenerator);
tfPropertyRecordingFile.setText(file.getAbsolutePath());
return file;
} else {
tfPropertyOutputFile.setText(configuration.outputVideo);
return null;
}
}


@FXML
public void rActionSlideshowGenerator() {

Expand Down Expand Up @@ -588,9 +668,9 @@ public void btnActionChangeInputFile() {
if (!rCloneLR.isSelected())
rCloneLR.setSelected(true);
}
removeTab(tabVideoFileInput);
removeTab(tabSlideshow);
addTab(tabTestVideoGenerator);
// removeTab(tabVideoFileInput);
// removeTab(tabSlideshow);
// addTab(tabTestVideoGenerator);
}

@FXML
Expand All @@ -607,6 +687,20 @@ public void btnActionChangeInputDir() {
addTab(tabTestVideoGenerator);
}

@FXML
public void btnActionChangeRecordingFile() {
File file = chooseRecordingVideo();
if (file == null) {
main.setDocumentInTitle(null);
rTestVideoGenerator.setSelected(true);
if (!rCloneLR.isSelected())
rCloneLR.setSelected(true);
}
// removeTab(tabVideoFileInput);
// removeTab(tabSlideshow);
// addTab(tabTestVideoGenerator);
}

// @FXML
public boolean tfActionChangeTestScreenWidth(String oldValue, String newValue) {

Expand Down Expand Up @@ -675,4 +769,5 @@ public void tbActionStereoEffectFilterEnabled() {
sliderStereoPerspective.setDisable(!stereoEffectFilterEnabled.isSelected());
}


}

0 comments on commit 6cae763

Please sign in to comment.