我尝试将RTSP服务器中的视频流打开到JAVA应用程序中。首先,我尝试运行此示例:
package uk.co.caprica.vlcj.test.streaming;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import uk.co.caprica.vlcj.test.VlcjTest;
/**
* An example of how to stream a media file using RTSP.
* <p>
* The client specifies an MRL of <code>rtsp://@127.0.0.1:5555/demo</code>
*/
public class StreamRtsp extends VlcjTest {
public static void main(String[] args) throws Exception {
if(args.length != 1) {
System.out.println("Specify a single MRL to stream");
System.exit(1);
}
String media = args[0];
String options = formatRtspStream("127.0.0.1", 5555, "demo");
System.out.println("Streaming '" + media + "' to '" + options + "'");
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
mediaPlayer.playMedia(media,
options,
":no-sout-rtp-sap",
":no-sout-standard-sap",
":sout-all",
":sout-keep"
);
// Don't exit
Thread.currentThread().join();
}
private static String formatRtspStream(String serverAddress, int serverPort, String id) {
StringBuilder sb = new StringBuilder(60);
sb.append(":sout=#rtp{sdp=rtsp://@");
sb.append(serverAddress);
sb.append(':');
sb.append(serverPort);
sb.append('/');
sb.append(id);
sb.append("}");
return sb.toString();
}
}
但我总是得到同样的结果: 指定要流式传输的单个MRL
http://i.stack.imgur.com/8iX0O.png
即使我删除了这一部分:
if(args.length != 1) {
System.out.println("Specify a single MRL to stream");
System.exit(1);
}
你能帮我吗?
答案 0 :(得分:1)
听起来你并没有真正地将一个参数传递给该程序,它希望从这一行:
String media = args[0];
如果您不想传递参数,只需将其更改为:
String media = "(location of rtsp to stream)";
...并删除上面的if语句。
答案 1 :(得分:0)
这是java的完整示例,包含用于流式传输的Java类(无需创建其他函数)
这是简单流式传输的示例:
StreamRTP rtp = new StreamRTP();
rtp.start("10.20.11.142", 5000, "sample.mp3");
您可以在此处找到该课程:https://github.com/maitmansour/vlcj-audio-rtp-streaming-example