【问题标题】:Best server side video processing library or software [closed]最佳服务器端视频处理库或软件[关闭]
【发布时间】:2013-05-16 18:28:07
【问题描述】:
我需要您对选择正确的命令行工具的建议
这将允许我处理用户上传的视频。
我的意思是处理:
- 转换为 flv、mp4、ogg 等格式
- 修改质量、比特率、帧率等
- 控制文件大小和其他属性
- 可能需要以批处理模式处理视频
这个处理将通过一些计划的进程来完成,这些进程会抓取文件然后进行处理。该工具必须具有命令行实用程序。
我只知道免费的 FFMPEG 库。
是否有其他工具(如果要花钱就可以了)可以让我做到这些吗?
如果你知道 youtube 用的是什么?
谢谢
【问题讨论】:
标签:
ffmpeg
video-streaming
html5-video
video-processing
【解决方案1】:
ffmpeg 是一个很好的库,有很好的开源资源。
我在 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;
}
}
调用这个执行 ffmpeg 工作的脚本(pars_submit):
#!/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