Permalink
Browse files

added file splitter and joiner classes to the script engine

  • Loading branch information...
1 parent 45b4f64 commit 3e2a4d473bc06a4201273fd10399526e4e44224b @sankha93 committed May 15, 2012
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -28,7 +28,6 @@ dist.jar=${dist.dir}/Panther.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
-file.reference.jave-panther.jar=E:\\developer\\projects\\jave-panther\\dist\\jave-panther.jar
file.reference.JID3.jar=lib\\JID3.jar
file.reference.jsyntaxpane-0.9.5-b29.jar=lib\\jsyntaxpane-0.9.5-b29.jar
includes=**
@@ -38,7 +37,7 @@ javac.classpath=\
${libs.JUpdater.classpath}:\
${file.reference.jsyntaxpane-0.9.5-b29.jar}:\
${file.reference.JID3.jar}:\
- ${file.reference.jave-panther.jar}
+ ${libs.Jave.classpath}
# Space-separated list of extra javac options
javac.compilerargs=-target 1.5
javac.deprecation=false
@@ -0,0 +1,126 @@
+/*
+ * Panther is a program to encode your media files from one format to the other.
+ * Copyright (C) 2012 Sankha Narayan Guria
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package sngforge.panther.script;
+
+import it.sauronsoftware.jave.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+
+/**
+ * Script Engine class for joining files
+ *
+ * @author Sankha
+ */
+public class FileJoiner {
+
+ ArrayList files;
+ File outFile;
+
+ /*
+ * creates a new FileJoiner object
+ * @param outFile the output file
+ */
+ public FileJoiner(File outFile) {
+ this.outFile = outFile;
+ files = new ArrayList();
+ }
+
+ /*
+ * adds a file to the list of files you want to join
+ * @param file the file you want to join
+ */
+ public void addFile(File file) {
+ files.add(file);
+ }
+
+ /*
+ * removes a file from the list of files you want to join if you previously added it
+ * @param file you want to remove from list
+ */
+ public void removeFile(File file) {
+ files.remove(file);
+ }
+
+ /*
+ * starts the encoding process
+ */
+ public void encode() {
+ Utilities u = new Utilities();
+ Encoder e = new Encoder();
+ ArrayList list = new ArrayList();
+ for (int i = 0; i < files.size(); i++) {
+ File f = (File) files.get(i);
+ File fout = new File(System.getProperty("user.home") + "/.panther/" + f.getName() + ".mpg");
+ list.add(fout);
+ EncodingAttributes ae = new EncodingAttributes();
+ AudioAttributes aa = new AudioAttributes();
+ VideoAttributes va = new VideoAttributes();
+ ae.setAudioAttributes(aa);
+ ae.setVideoAttributes(va);
+ ae.setFormat("mpeg");
+ ae.setSameQuality(true);
+ try {
+ u.println("Processing File: " + f.getAbsolutePath());
+ e.encode(f, fout, ae, new ProgressListener());
+ } catch (Exception ex) {
+ System.err.println(ex);
+ u.println(ex.toString());
+ }
+ }
+ u.print("Stitching Files...");
+ File fout = new File(System.getProperty("user.home") + "/.panther/" + ".temp.mpg");
+ try {
+ FileOutputStream outStream = new FileOutputStream(fout);
+ for (int i = 0; i < list.size(); i++) {
+ FileInputStream fin = new FileInputStream((File) list.get(i));
+ // 1MB buffer size for very fast file joining
+ byte[] buffer = new byte[1024 * 1024];
+ int l;
+ while ((l = fin.read(buffer)) != -1) {
+ outStream.write(buffer, 0, l);
+ }
+ fin.close();
+ }
+ u.println(" Done!");
+ outStream.close();
+ } catch (Exception ex) {
+ System.err.println(ex);
+ u.println(ex.toString());
+ }
+ u.println("Creating file: " + outFile.getAbsolutePath());
+ try {
+ MultimediaInfo mi = e.getInfo((File) files.get(0));
+ String format = mi.getFormat();
+ EncodingAttributes ae = new EncodingAttributes();
+ AudioAttributes aa = new AudioAttributes();
+ VideoAttributes va = new VideoAttributes();
+ ae.setAudioAttributes(aa);
+ ae.setVideoAttributes(va);
+ ae.setFormat(format);
+ ae.setSameQuality(true);
+ e.encode(new File(System.getProperty("user.home") + "/.panther/" + ".temp.mpg"), outFile, ae, new ProgressListener());
+ } catch (Exception ex) {
+ System.err.println(ex);
+ u.println(ex.toString());
+ }
+
+ }
+}
@@ -0,0 +1,98 @@
+/*
+ * Panther is a program to encode your media files from one format to the other.
+ * Copyright (C) 2012 Sankha Narayan Guria
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package sngforge.panther.script;
+
+import it.sauronsoftware.jave.AudioAttributes;
+import it.sauronsoftware.jave.Encoder;
+import it.sauronsoftware.jave.EncodingAttributes;
+import it.sauronsoftware.jave.VideoAttributes;
+import java.io.File;
+import java.util.ArrayList;
+
+/**
+ * Script engine class for file splitter
+ *
+ * @author Sankha
+ */
+public class FileSplitter {
+
+ File inFile, outDir;
+ ArrayList timepoints;
+
+ /*
+ * constructs the FileSplitter object
+ * @param inFile the input file
+ * @param outDir the output directory
+ */
+ public FileSplitter(File inFile, File outDir) {
+ this.inFile = inFile;
+ this.outDir = outDir;
+ timepoints=new ArrayList();
+ }
+
+ /*
+ * adds a timepoint from where the file will be split
+ * @sec the time in seconds
+ */
+ public void addTimePoint(float sec) {
+ timepoints.add(sec);
+ }
+
+ /*
+ * removes a timepoint if you have previously add one
+ * @sec the time in seconds
+ */
+ public void removeTimePoint(float sec) {
+ timepoints.remove(sec);
+ }
+
+ /*
+ * starts the encoding process
+ */
+ public void encode() {
+ Utilities u = new Utilities();
+ Encoder e = new Encoder();
+ try {
+ MediaFile media = new MediaFile(inFile);
+ String format = media.getFormat();
+ float sec = media.getDuration();
+ timepoints.add(sec);
+ float offset = 0;
+ for (int i = 0; i < timepoints.size(); i++) {
+ StringBuilder sb = new StringBuilder(outDir.getAbsolutePath() + "/" + inFile.getName());
+ sb.insert(sb.lastIndexOf("."), "." + (i + 1));
+ EncodingAttributes ea = new EncodingAttributes();
+ AudioAttributes aa = new AudioAttributes();
+ VideoAttributes va = new VideoAttributes();
+ va.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
+ ea.setAudioAttributes(aa);
+ ea.setVideoAttributes(va);
+ ea.setFormat(format);
+ ea.setOffset(offset);
+ ea.setDuration((Float) timepoints.get(i));
+ u.println("Creating file: " + sb.toString());
+ e.encode(inFile, new File(sb.toString()), ea, new ProgressListener());
+ offset += (Float) timepoints.get(i);
+ }
+ } catch (Exception ex) {
+ u.println(ex.toString());
+ System.err.println(ex);
+ }
+ }
+}
@@ -0,0 +1,64 @@
+/*
+ * Panther is a program to encode your media files from one format to the other.
+ * Copyright (C) 2012 Sankha Narayan Guria
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package sngforge.panther.script;
+
+import it.sauronsoftware.jave.Encoder;
+import it.sauronsoftware.jave.MultimediaInfo;
+import java.io.File;
+
+/**
+ * Script engine class for getting different properties from a media file
+ * @author Sankha
+ */
+public class MediaFile {
+
+ MultimediaInfo mi;
+ Utilities u;
+
+ /*
+ * constructs the MediaFile object
+ * @param file the file whose properties is required
+ */
+ public MediaFile (File file){
+ Encoder e=new Encoder();
+ u=new Utilities();
+ try {
+ mi=e.getInfo(file);
+ } catch (Exception ex) {
+ System.err.println(ex);
+ u.println("Error: "+ex);
+ }
+ }
+
+ /*
+ * gets the format of the media file
+ * @param the format of the file
+ */
+ public String getFormat(){
+ return mi.getFormat();
+ }
+
+ /*
+ * gets the duration of the media file
+ * @param the duartion of the audio or video
+ */
+ public float getDuration(){
+ return mi.getDuration()/1000;
+ }
+}

0 comments on commit 3e2a4d4

Please sign in to comment.