异常提到“环境”为空...
也许代替'exec',尝试使用processbuilder,如下面的运行ffmpeg的服务器端代码示例中包装在shellscript(pars_submit)中......注意builder.environment
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();
// for(Entry<String, String> entry : environ.entrySet()){
// System.out.println("ENV " +entry.getKey() + " " +entry.getValue());
// }
// builder.redirectErrorStream(true);
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) {
//System.out.println(line);
outfil=line;
}
// int exitVal = process.waitFor();
// System.out.println("Process exitValue: " + exitVal);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if (process != null) {
process.destroy();
process = null;
}
}
return outfil;
}
IMO - 使用完整的 JNI 接口和包装器来调用 ffmpeg.main(),android-ffmpeg 将更加可靠。查看所有 git 项目...搜索“android-ffmpeg”并查看它们如何调用 ffmpeg。不使用 CLI。
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: 3KxPB" -H "X-Parse-REST-API-Key: kVl5Z0CX" -H "Content-Type: video/mp4" --data-binary @"$otfil" https://api.parse.com/1/files/"$otfil")
# echo "parse POST Exit status" $?
echo $json