0
我正在寫一個Java程序來將視頻文件流式傳輸到我正在寫的Java客戶端。我有這樣的使用GST-launch命令的工作版本:Gstreamer-java UDP管道不會發送任何數據
$ gst-launch-0.10 -v filesrc location="beauty.mp4"
! decodebin2
! queue
! jpegenc
! rtpjpegpay
! udpsink host=127.0.0.1 port=5000 sync=true
,並使用此命令成功流傳輸到客戶端:
$ gst-launch-0.10 -v udpsrc uri="udp://127.0.0.1:5000"
! "application/x-rtp,
media=(string)video,
clock-rate=(int)90000,
encoding-name=(string)JPEG,
payload=(int)96,
ssrc=(uint)2156703816, c
lock-base=(uint)1678649553,
seqnum-base=(uint)31324"
! rtpjpegdepay
! jpegdec
! ffmpegcolorspace
! autovideosink
當試圖將其轉換成Java,不過,我似乎無法發送單個字節。下面是我有:
public static void main(String[] args) {
System.out.println("Starting testserver on port 45001...");
try {
startStreaming();
Thread.sleep(50000);
} catch(Exception e) {
e.printStackTrace();
}
}
private static void startStreaming() {
// create the pipeline here
Gst.init();
Pipeline pipe = new Pipeline("pipeline");
Element fileSrc = ElementFactory.make("filesrc", "source");
fileSrc.set("location", "videos/beauty.mp4");
Element decoder = ElementFactory.make("decodebin2", "decoder");
Element queue = ElementFactory.make("queue", "queue");
Element encoder = ElementFactory.make("jpegenc", "encoder");
Element payloader = ElementFactory.make("rtpjpegpay", "payloader");
Element sink = ElementFactory.make("udpsink", "sink");
sink.set("host", "127.0.0.1");
sink.set("port", "45001");
sink.set("sync", "true");
pipe.addMany(fileSrc, decoder, queue, encoder, payloader, sink);
Element.linkMany(fileSrc, decoder, queue, encoder, payloader, sink);
pipe.setState(State.PLAYING);
}
我第一次嘗試打這個流與類似構造的Java的管道,但沒有發生之後,我試圖用一個簡單的GST-launch命令讀取數據流:
$ gst-launch-0.10 udpsrc uri="udp://127.0.0.1:45001" ! fakesink dump=1
並沒有收到任何字節。什麼可能導致這種情況?我沒有得到任何運行時錯誤,並且此管道在命令行上工作得很好。