在這裏,我想編碼直播RTMP流使用的avconv工具Libav從Flash Media Server未來和廣播低比特率流後停止編碼。 Libav安裝在Ubuntu操作系統上。編碼流僅爲8分鐘。由於avconv工具是通過使用java運行時環境啓動的。 Java代碼在下面給出 -avconv工具8分鐘
public class RunnableStream implements Runnable
{
String inStream,outStream,width,height,bitRate,frameRate,fname,line,ar,audioBitRate,audioChannel;
public RunnableStream(String fname,String inStream,String outStream,String ar,String audioBitRate,String audioChannel,String width,String height,String bitRate,String frameRate)
{
this.fname=fname;
this.inStream=inStream;
this.outStream=outStream;
this.width=width;
this.height=height;
this.bitRate=bitRate;
this.frameRate=frameRate;
this.ar=ar;
this.audioBitRate=audioBitRate;
this.audioChannel=audioChannel;
}
public void run() {
Process pr;
try {
pr = Runtime.getRuntime().exec("avconv -async 15 -i "+inStream+" -shortest -s "+width +"*"+height +" -r " +frameRate+" -b:v "+bitRate+" -ab "+audioBitRate+" -ac "+audioChannel+" -ar "+ar+" -f flv "+outStream);
InputStream in1 = pr.getInputStream();
InputStream in = pr.getErrorStream();
int c1;
while ((c1 = in1.read()) != -1)
{
System.out.print((char)c1);
}
int c;
while ((c = in.read()) != -1)
{
System.out.print((char)c);
}
pr.waitFor();
in.close();
in1.close();
}catch(Exception e){e.printStackTrace();}
}
}
但是,當相同的編碼方案或命令被直接施加到命令提示那麼它可以爲atleast1小時運行。下面給出命令行語句 -
avconv -async 15 -i rtmp://IP/live/streamname -shortest -s 176*144 -r 10 -b:v 56k -ab 12k -ac 1 -ar 22050 -f flv rtmp://IP/live/streamname2
我明白爲時已晚,但也許這個項目將是對您有用:https://github.com/vbauer/avconv4java –