2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.grabmemcard;
13 import java.io.IOException;
14 import java.util.Date;
15 import java.util.GregorianCalendar;
17 import eu.svjatoslav.commons.file.CommonPathResolver;
18 import eu.svjatoslav.commons.file.FilePathParser;
19 import eu.svjatoslav.meviz.Module;
20 import eu.svjatoslav.meviz.encoder.BitrateParameter;
21 import eu.svjatoslav.meviz.encoder.EncodingOptions;
22 import eu.svjatoslav.meviz.encoder.EncodingPlan;
23 import eu.svjatoslav.meviz.encoder.EncodingTask;
24 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
25 import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
27 public class Main implements Module {
30 public String getDescription() {
31 return "Convenience helper to retrieve contents of inserted memory card.";
34 public File[] getDiskVideos(final File file) {
35 final String videosPath = file.getAbsolutePath()
36 + "/AVCHD/BDMV/STREAM/";
37 final File videosDirectory = new File(videosPath);
39 if (!videosDirectory.exists())
42 return videosDirectory.listFiles();
45 public String getDoubleDigit(final int value) {
46 String valueString = Integer.toString(value);
47 if (valueString.length() == 1)
48 valueString = "0" + valueString;
53 public String getModuleCommand() {
57 @SuppressWarnings("deprecation")
58 public File getTargetDirectory() {
59 final Date now = new Date();
60 final GregorianCalendar calendar = new GregorianCalendar();
62 final StringBuffer directoryName = new StringBuffer();
63 directoryName.append(calendar.get(GregorianCalendar.YEAR) + "."
64 + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
66 + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH))
69 directoryName.append(getDoubleDigit(now.getHours()) + ":"
70 + getDoubleDigit(now.getMinutes()) + ":"
71 + getDoubleDigit(now.getSeconds()));
73 final String targetDirectoryPath = CommonPathResolver
74 .getDesktopDirectory().getAbsolutePath()
76 + directoryName.toString() + "/";
78 System.out.println("Target directory path: " + targetDirectoryPath);
80 return new File(targetDirectoryPath);
84 public void run(final String[] args) throws IOException {
86 final File targetDirectory = getTargetDirectory();
87 targetDirectory.mkdirs();
89 final AbstractConverter converter = new AvconvVideo();
90 final EncodingPlan encodingPlan = new EncodingPlan();
92 final String userName = System.getProperty("user.name");
94 final File file = new File("/media/" + userName + "/");
96 for (final File insertedDisk : file.listFiles()) {
97 final File[] diskVideos = getDiskVideos(insertedDisk);
99 for (final File sourceFile : diskVideos) {
101 // compute target file path
102 final StringBuffer targetFilePath = new StringBuffer();
103 targetFilePath.append(targetDirectory.getAbsolutePath());
104 targetFilePath.append("/");
105 targetFilePath.append(FilePathParser
106 .getFileNameWithoutExtension(sourceFile));
107 targetFilePath.append(".mp4");
108 final File targetFile = new File(targetFilePath.toString());
110 final EncodingTask encodingTask = new EncodingTask(sourceFile,
111 targetFile, converter, "mp4");
112 encodingPlan.scheduleTask(encodingTask);
116 final EncodingOptions options = new EncodingOptions();
117 options.setVideoBitrate(BitrateParameter.bitrate.COPY);
119 encodingPlan.execute(options);
123 public void showCommandlineHelp() {
124 System.out.println("memory card grabber has no commandline options");