转换flv

import java.io.File;
import java.util.List;
import java.util.ArrayList;

public class ChangeVedio {
 
 
//resourcePath为原来视频文件的路径
//filename:要转换成FLV的文件名
//realpath:实际存放FLV的路径
 public static boolean process(String resourcePath,String fileName,String realPath) { 
 
  int type = checkContentType(resourcePath);
 
        boolean status = false;

//如果符合转换文件类型
        if (type==0) {
       
            status = processFLV(resourcePath,fileName,realPath);     
        }
        return status;
    }

//检查文件的类型
    private static int checkContentType(String resourcePath) {
        String type = resourcePath.substring(resourcePath.lastIndexOf(".") + 1,
          resourcePath.length()).toLowerCase();
      

        if (type.equals("avi")) {
            return 0;
        } else if (type.equals("mpg")) {
            return 0;
        } else if (type.equals("wmv")) {
            return 0;
        } else if (type.equals("3gp")) {
            return 0;
        } else if (type.equals("mov")) {
            return 0;
        } else if (type.equals("mp4")) {
            return 0;
        } else if (type.equals("asf")) {
            return 0;
        } else if (type.equals("asx")) {
            return 0;
        } else if (type.equals("flv")) {
            return 0;
        } else if(type.equals("mpeg")){
         return 0;
        }else if(type.equals("mpe")){
         return 0;
        }
      
     
        else if (type.equals("wmv9")) {
            return 1;
        } else if (type.equals("rm")) {
            return 1;
        } else if (type.equals("rmvb")) {
            return 1;
        }     
        return 9;
    }
 
    private static boolean checkfile(String path){
     File file=new File(path);
     if(!file.isFile()){
      return false;
     }
     return true;
    }


    private static boolean processFLV(String resourcePath,String fileName,String realPath) {
   
      if(!checkfile(resourcePath)){
          System.out.println(resourcePath+" is not file");
          return false;
         }  
        try {
         Runtime runtime=Runtime.getRuntime();
            Process proce;
            String cmd="";
            String realPath1 = realPath+fileName+".jpg" ;
            String realPath2 = realPath ;
            Runtime runtime1=Runtime.getRuntime();     
            Process proce1;
        //   proce1 = runtime1.exec("c://encoder.bat "+resourcePath+" "+realPath2 + fileName);
 // proce1.waitFor();
  System.out.println(realPath1);
         //  proce=runtime.exec("ffmpeg -i "+resourcePath+" -y -f image2 -ss 4 -t 0.001 -s 350x240  "+realPath1+" ");
           // proce.waitFor();
           proce=runtime.exec("mencoder "+"D:\\ffmeg\\cc.rmvb"+" -o "+"d:aa.avi"+" -of lavf  -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4:cmp=6:vb_strategy=1 -vf scale=512:-3 -ofps 12 -srate 22050 ");
           //
            File flvFile = new File(realPath2 + fileName);
        
//如果转换成功,文件存在并且长度>0
            boolean success = flvFile.exists()&&flvFile.length()>0;
           System.out.println(success);
            return success;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    } 
  
    public static void main(String[] args) {
        if (process("c://q.avi","huge.flv","D://"))
        {               
            System.out.println("ok");
        }
 }
 
}

你可能感兴趣的:(C++,c,F#,C#,vb)