use terminal when copying memory card
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 25 Dec 2015 20:41:50 +0000 (22:41 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 25 Dec 2015 20:41:50 +0000 (22:41 +0200)
src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java
src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java

index 816fba7..b5dbe08 100755 (executable)
@@ -29,16 +29,13 @@ public class EncodingTask {
 
        private boolean useTerminal;
 
-       private String targetFormat;
+       private final String targetFormat;
 
-       public EncodingTask(
-                       final File source,
-                       final File destination,
-                       final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter,
-                       String targetFormat) {
+       public EncodingTask(final File source, final File target, final AbstractConverter converter,
+                       final String targetFormat) {
 
                this.source = source;
-               target = destination;
+               this.target = target;
                this.converter = converter;
                this.targetFormat = targetFormat;
        }
@@ -73,11 +70,10 @@ public class EncodingTask {
 
                        System.out.println("Executing command: " + command);
 
-                       final Runtime run = Runtime.getRuntime();
-                       Process pr;
-                       pr = run.exec(new String[] { "/bin/bash", "-c", command });
+                       final Runtime runtime = Runtime.getRuntime();
+                       final Process process = runtime.exec(new String[] { "/bin/bash", "-c", command });
 
-                       pr.waitFor();
+                       process.waitFor();
 
                } catch (final Exception e) {
                        System.out.println(e.toString());
@@ -87,8 +83,7 @@ public class EncodingTask {
        }
 
        public String getCommand(final EncodingOptions encodingOptions) {
-               return converter.getCommand(source, target, encodingOptions,
-                               targetFormat);
+               return converter.getCommand(source, target, encodingOptions, targetFormat);
        }
 
        /**
index 920a95c..e538338 100755 (executable)
@@ -32,8 +32,7 @@ public class Main implements Module {
        }
 
        public File[] getDiskVideos(final File file) {
-               final String videosPath = file.getAbsolutePath()
-                               + "/AVCHD/BDMV/STREAM/";
+               final String videosPath = file.getAbsolutePath() + "/AVCHD/BDMV/STREAM/";
                final File videosDirectory = new File(videosPath);
 
                if (!videosDirectory.exists())
@@ -49,6 +48,13 @@ public class Main implements Module {
                return valueString;
        };
 
+       private EncodingOptions getEncodingOptions() {
+               final EncodingOptions options = new EncodingOptions();
+               options.setVideoBitrate(BitrateParameter.bitrate.COPY);
+               options.setAudioBitrate(BitrateParameter.bitrate.COPY);
+               return options;
+       }
+
        @Override
        public String getModuleCommand() {
                return "grabmemcard";
@@ -60,19 +66,14 @@ public class Main implements Module {
                final GregorianCalendar calendar = new GregorianCalendar();
 
                final StringBuffer directoryName = new StringBuffer();
-               directoryName.append(calendar.get(GregorianCalendar.YEAR) + "."
-                               + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
-                               + "."
-                               + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH))
-                               + " ");
-
-               directoryName.append(getDoubleDigit(now.getHours()) + ":"
-                               + getDoubleDigit(now.getMinutes()) + ":"
+               directoryName.append(
+                               calendar.get(GregorianCalendar.YEAR) + "." + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
+                                               + "." + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH)) + " ");
+
+               directoryName.append(getDoubleDigit(now.getHours()) + ":" + getDoubleDigit(now.getMinutes()) + ":"
                                + getDoubleDigit(now.getSeconds()));
 
-               final String targetDirectoryPath = CommonPathResolver
-                               .getDesktopDirectory().getAbsolutePath()
-                               + "/"
+               final String targetDirectoryPath = CommonPathResolver.getDesktopDirectory().getAbsolutePath() + "/"
                                + directoryName.toString() + "/";
 
                System.out.println("Target directory path: " + targetDirectoryPath);
@@ -80,6 +81,17 @@ public class Main implements Module {
                return new File(targetDirectoryPath);
        }
 
+       private File getTargetFile(final File targetDirectory, final File sourceFile) {
+               // compute target file path
+               final StringBuffer targetFilePath = new StringBuffer();
+               targetFilePath.append(targetDirectory.getAbsolutePath());
+               targetFilePath.append("/");
+               targetFilePath.append(FilePathParser.getFileNameWithoutExtension(sourceFile));
+               targetFilePath.append(".mp4");
+               final File targetFile = new File(targetFilePath.toString());
+               return targetFile;
+       }
+
        @Override
        public void run(final String[] args) throws IOException {
 
@@ -100,8 +112,8 @@ public class Main implements Module {
 
                                final File targetFile = getTargetFile(targetDirectory, sourceFile);
 
-                               final EncodingTask encodingTask = new EncodingTask(sourceFile,
-                                               targetFile, converter, "mp4");
+                               final EncodingTask encodingTask = new EncodingTask(sourceFile, targetFile, converter, "mp4");
+                               encodingTask.setUseTerminal(true);
                                encodingPlan.scheduleTask(encodingTask);
                        }
                }
@@ -109,25 +121,6 @@ public class Main implements Module {
                encodingPlan.execute(getEncodingOptions());
        }
 
-       private EncodingOptions getEncodingOptions() {
-               final EncodingOptions options = new EncodingOptions();
-               options.setVideoBitrate(BitrateParameter.bitrate.COPY);
-               options.setAudioBitrate(BitrateParameter.bitrate.COPY);
-               return options;
-       }
-
-       private File getTargetFile(final File targetDirectory, final File sourceFile) {
-               // compute target file path
-               final StringBuffer targetFilePath = new StringBuffer();
-               targetFilePath.append(targetDirectory.getAbsolutePath());
-               targetFilePath.append("/");
-               targetFilePath.append(FilePathParser
-                               .getFileNameWithoutExtension(sourceFile));
-               targetFilePath.append(".mp4");
-               final File targetFile = new File(targetFilePath.toString());
-               return targetFile;
-       }
-
        @Override
        public void showCommandlineHelp() {
                System.out.println("memory card grabber has no commandline options");