OSDN Git Service

add chlist output option.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 29 Oct 2010 13:00:17 +0000 (13:00 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 29 Oct 2010 13:00:17 +0000 (13:00 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@708 4e526526-5e11-4fc0-8910-f8fd03428081

jTsSplitter/trunk/src/jtssplitter/Chlist.java [new file with mode: 0644]
jTsSplitter/trunk/src/jtssplitter/Main.java
jTsSplitter/trunk/src/jtssplitter/Tsfile.java

diff --git a/jTsSplitter/trunk/src/jtssplitter/Chlist.java b/jTsSplitter/trunk/src/jtssplitter/Chlist.java
new file mode 100644 (file)
index 0000000..30cc3db
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package jtssplitter;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author yukikaze
+ */
+public class Chlist {
+    public void writeCHList(String tspath,String listpath){
+        FileWriter fw = null;
+        try {
+            Tsfile tsf = new Tsfile();
+            Integer[] programnum = tsf.getProgramNum_byte(tspath);
+            String str = "";
+            for (int i = 0; i < programnum.length; i++) {
+                str = str + programnum[i].toString() + "\n";
+            }
+            fw = new FileWriter(listpath);
+            fw.write(str);
+            fw.close();
+        } catch (IOException ex) {
+            Logger.getLogger(Chlist.class.getName()).log(Level.SEVERE, null, ex);
+        } finally {
+            try {
+                fw.close();
+            } catch (IOException ex) {
+                Logger.getLogger(Chlist.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        }
+    }
+}
index 338b710..e152b93 100644 (file)
@@ -33,11 +33,17 @@ public class Main {
             if (args.length > 2) {
                 ch = Integer.parseInt(args[2].trim(), 10);
             }
+            if (args[0].toUpperCase().equals("-CH")){
+                Chlist chl=new Chlist();
+                chl.writeCHList(args[1], args[3]);
+                System.exit(0);
+            }
         }
         Tsfile t1 = new Tsfile();
         File f=new File(inf);
         if (f.length()>1000*1000){
             t1.splitTS_byte(inf, outf, ch);
         }
+        System.exit(0);
     }
 }
index 6f38d13..846dcff 100644 (file)
@@ -247,6 +247,43 @@ public class Tsfile {
         }
         return pids;
     }
+    public Integer[] getProgramNum_byte(String fpath){
+            /**
+             * PIDを取得し、これと思われる必要なPIDを抜き出す。
+             * @return プログラム番号(return[0])とPIDのリスト(return[1-])
+             */
+            FileInputStream in = null;
+            ArrayList<Integer> retti = new ArrayList<Integer>();
+            byte[] tb = new byte[188];
+            ArrayList<PATData> pat = new ArrayList<PATData>();
+            try {
+            in = new FileInputStream(fpath);
+            int imax = 1000;
+            for (int i = 0; i < imax; i++) {
+                if (in.read(tb) == -1) {
+                    in.close();
+                    System.out.println("Program Table not found.");
+                    System.exit(1);
+                }
+                String last8;
+                Mpeg2TSPacket m2tp;
+                m2tp = new Mpeg2TSPacket();
+                m2tp.setPAT(pat);
+                m2tp.readTS_byte(tb);
+                pat = m2tp.getPAT();
+                for (int i2 = 0; i2 < pat.size(); i2++) {
+                    PATData patdd = pat.get(i2);
+                    if (!(retti.contains(patdd.Program_TABLE))){
+                        retti.add(patdd.Program_TABLE);
+                    }
+                }
+            }
+        } catch (IOException ex) {
+            Logger.getLogger(Tsfile.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        Integer[] rt=retti.toArray(new Integer[retti.size()]);
+        return rt;
+    }
     private int getFirstP_Table_byte(String fpath){
         /**
          * PIDを取得し、これと思われる必要なPIDを抜き出す。