Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3964941
  • 博文数量: 366
  • 博客积分: 9916
  • 博客等级: 中将
  • 技术积分: 7195
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-29 23:27
个人简介

简单!

文章分类

全部博文(366)

文章存档

2013年(51)

2012年(269)

2011年(46)

分类: Java

2012-11-04 20:10:26


  1. import java.io.*;
  2. import java.lang.*;
  3. import java.util.*;
  4. import java.text.*;
  5. import java.net.*;



  6. public class MediocreExecJavac {

  7.     public void runCmd(String command) {
  8.         try {
  9.             Runtime rt = Runtime.getRuntime();
  10.             Process proc = rt.exec(command);
  11.             InputStream stderr = proc.getErrorStream();
  12.             InputStreamReader isr = new InputStreamReader(stderr);
  13.             BufferedReader br = new BufferedReader(isr);
  14.             String line = null;
  15.  
  16.             while ( (line = br.readLine()) != null)
  17.                 System.out.println(line);

  18.             int exitVal = proc.waitFor();
  19.             System.out.println("Process exitValue: " + exitVal);
  20.         } catch (Throwable t) {
  21.             t.printStackTrace();
  22.         }
  23.     }

  24.     public boolean transfer(String infile,String outfile) {
  25.         String avitoflv = "ffmpeg -i "+infile+" -ar 22050 -ab 56 -f flv -y -s 320x240 "+outfile;
  26.         String flvto3gp = "ffmpeg -i " + infile + " -ar 8000 -ac 1 -acodec amr_nb -vcodec h263 -s 176x144 -r 12 -b 30 -ab 12 " + outfile;
  27.         String avito3gp = "ffmpeg -i " + infile + " -ar 8000 -ac 1 -acodec amr_nb -vcodec h263 -s 176x144 -r 12 -b 30 -ab 12 " + outfile;
  28.         String avitojpg = "ffmpeg -i " + infile + " -y -f image2 -ss 00:00:10 -t 00:00:01 -s 350x240 " + outfile;

  29.         try {
  30.             Runtime rt = Runtime.getRuntime();
  31.             Process proc = rt.exec(avitoflv);
  32.             InputStream stderr = proc.getErrorStream();
  33.             InputStreamReader isr = new InputStreamReader(stderr);
  34.             BufferedReader br = new BufferedReader(isr);
  35.             String line = null;

  36.             while ( (line = br.readLine()) != null)
  37.                 System.out.println(line);

  38.             int exitVal = proc.waitFor();
  39.             System.out.println("Process exitValue: " + exitVal);
  40.         } catch (Throwable t) {
  41.             t.printStackTrace();
  42.             return false;
  43.         }
  44.         return true;
  45.     }

  46.     public static String readFile(String fileName,int id) {
  47.         String dataStr = "";
  48.         FileInputStream fis = null;

  49.         try {
  50.             FileReader file = new FileReader(fileName);//建立FileReader对象,并实例化为fr
  51.             BufferedReader br=new BufferedReader(file);//建立BufferedReader对象,并实例化为br
  52.             String Line=br.readLine();//从文件读取一行字符串
  53.             dataStr=Line;
  54.             br.close();//关闭BufferedReader对象
  55.         } catch(Exception e) {

  56.         } finally {
  57.             try {
  58.                 if(fis!=null)
  59.                     fis.close();
  60.             } catch(Exception e) {}
  61.         }
  62.         return dataStr;
  63.     }

  64.     public String readtime(String file) {
  65.         String str="/root/Desktop/info.txt";
  66.         String timelen = "";
  67.         String cmd = "timelen "+file;

  68.         runCmd(cmd);
  69.         timelen=readFile(str,1);

  70.         return timelen;
  71.     }

  72.     public static void main(String args[]) {
  73.         MediocreExecJavac me = new MediocreExecJavac();
  74.         String infile = "/root/Desktop/a.mp4";
  75.         String outfile = "/root/Desktop/1.flv";

  76.         String timelen = me.readtime(infile);
  77.         System.out.println("timelen is :" + timelen);

  78.         if(me.transfer(infile,outfile)) {
  79.             System.out.println("the transfer is ok!");
  80.         } else {
  81.             System.out.println("the transfer is error!");
  82.         }
  83.     }
  84. }

阅读(22404) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~