2013-05-16 35 views
1

我需要你的建議,選擇正確的命令行工具 ,這將允許我處理用戶上傳的視頻。最好的服務器端視頻處理庫或軟件

通過處理我的意思是:

  • 轉換爲FLV,MP4,OGG等格式
  • 修改質量,碼率,幀率等
  • 控制文件大小和其他屬性
  • 可能需要處理批處理模式下的視頻

該處理將通過一些預定過程來完成,該過程將抓取文件然後處理。該工具必須具有命令行實用程序。

我只知道免費的FFMPEG庫。 有沒有其他(如果花錢然後罰款)工具,讓我做這些?

如果你知道的話,youtube會使用什麼?

謝謝

回答

1

ffmpeg是相當具有非常優秀的開源resouces好的庫。

我用它在Java(JAX-RS)REST API服務器端,其中實際的ffmpeg由該進程調用的:

@Path("/ffmpeg") 
public class FfmpegResource { 


    @GET 
     @Produces("text/plain") 

     public String getFfmpeg(@QueryParam("infil1") String infil1, 
       @QueryParam("infil2") String infil2, @QueryParam("otfil") String otfil, 
       @QueryParam("t") String time) {   
     String outfil = "dummy.mp4"; 

      List<String> command = new ArrayList<String>(); 
      command.add("vendor/bin/pars_submit"); 

      command.add(infil1);  

      command.add(infil2); 
      command.add(otfil); 
      command.add(time); 

System.out.println("Starting process " +command.toString()); 
      ProcessBuilder builder = new ProcessBuilder(command); 
      Map<String, String> environ = builder.environment(); 
      Process process = null; 
      try { 
       process = builder.start(); 

      InputStream is = process.getInputStream(); 

      InputStreamReader isr = new InputStreamReader(is); 
      BufferedReader br = new BufferedReader(isr); 
      String line; 
      while ((line = br.readLine()) != null) { 

       outfil=line; 
      } 

      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      finally { 
        if (process != null) { 
        process.destroy(); 
        process = null; //   int exitVal = process.waitFor(); 
//   System.out.println("Process exitValue: " + exitVal); 
        }         
       }           
      return outfil;        
       } 
} 

調用該腳本(pars_submit),做ffmpeg的工作:

#!/bin/bash 
shopt -s globstar 
uri=$1 
filnam="${uri##*/}" 
uri2=$2 
filnam2="${uri2##*/}" 
otfil=$3 
time=$4 
curl -#LO $uri 
curl -#LO $uri2 
ffmpeg -y -loop 1 -i "$filnam" -i "$filnam2" -t "$time" -r 1/2 -pass 1 -vcodec libx264 -b:v 200k -bt 50k -an -f mp4 -strict -2 -passlogfile mydummy /dev/null 
# echo "ffmpegP1 Exit status" $? 
ffmpeg -y -loop 1 -i "$filnam" -i "$filnam2" -t "$time" -r 1/2 -pass 2 -vcodec libx264 -b:v 200k -bt 50k -f mp4 -strict -2 -passlogfile mydummy -ar 44100 "$otfil" 
# echo "ffmpegp2 Exit status" $? 
# last test 
json=$(curl -X POST -H "X-Parse-Application-Id: 3KxPBTPSTe8f0iexGanSagCztLp6wSPzJkyMLAbR" -H "X-Parse-REST-API-Key: kVl5Z0CXmBSCoQRmE8XSLIDFuLGHMCIkLXXjkuI9" -H "Content-Type: video/mp4" --data-binary @"$otfil" https://api.parse.com/1/files/"$otfil") 
# echo "parse POST Exit status" $? 
echo $json