gpt4 book ai didi

java - 使用 vlcj 示例运行示例 RTSP (JAVA)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:46 27 4
gpt4 key购买 nike

我尝试将来自 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);
}

你能帮帮我吗?

最佳答案

听起来你实际上并没有将参数传递给程序,它期望从这一行传递参数:

String media = args[0];

如果您不想传递参数,只需将其更改为:

String media = "(location of rtsp to stream)";

...并删除上面已有的 if 语句。

关于java - 使用 vlcj 示例运行示例 RTSP (JAVA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23643016/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com