gpt4 book ai didi

java - VLCJ 中的流式桌面

转载 作者:行者123 更新时间:2023-12-01 08:46:38 25 4
gpt4 key购买 nike

我正在尝试编写一个Java程序,它允许一个用户充当服务器并流式传输其桌面(视频和音频),然后其他用户充当客户端并观看其桌面的实时流(类似于Twitch, Webex、Skype 屏幕共享等)。我正在为此使用 VLCJ,尽管我没有 promise 使用它,所以如果有更好的解决方案,我会洗耳恭听。这是从我在下面提供的链接复制的代码:

package test.java;

import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import test.java.VlcjTest;

/**
* An example of how to stream a media file over HTTP.
* <p>
* The client specifies an MRL of <code>http://127.0.0.1:5555</code>
*/
public class StreamHttp extends VlcjTest {

//when running this it requires an MRL (Media Resource Locator)
//fancy term for saying the file you want to stream. This could be a url to another
//location that streams media or a filepath to a media file you want to stream
//on the system you are running this code on.
public static void main(String[] args) throws Exception {
new NativeDiscovery().discover();
if(args.length != 1) {
System.out.println("Specify a single MRL to stream");
System.exit(1);
}

//the media you are wanting to stream
String media = args[0];
//this is the IP address and port you are wanting to stream at
//this means clients will connect to http://127.0.0.1:5555
//to watch the stream
String options = formatHttpStream("127.0.0.1", 5555);

System.out.println("Streaming '" + media + "' to '" + options + "'");

//this creates a the actual media player that will make calls into the native
//vlc libraries to actually play the media you supplied. It does it in
//a headless fashion, as you are going to stream it over http to be watched
//instead of playing it locally to be watched.
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();

//this simply starts the player playing the media you gave it
mediaPlayer.playMedia(media, options);

// Don't exit
//basically you don't want the thread to end and kill the player,
//so it just hangs around and waits for it to end.
Thread.currentThread().join();
}

private static String formatHttpStream(String serverAddress, int serverPort) {
StringBuilder sb = new StringBuilder(60);
sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,");
sb.append("dst=");
sb.append(serverAddress);
sb.append(':');
sb.append(serverPort);
sb.append("}}");
return sb.toString();
}
}

我将“screen://”作为参数传递给该程序。当我运行代码时,我收到以下错误消息:

[000000000038b250] access_output_http access out: Consider passing --http-host=IP on the command line instead.
[000000001ccaa220] core mux error: cannot add this stream
[000000001cc72100] core decoder error: cannot create packetizer output (RV32)

我尝试寻找解决方案,但我所能找到的只是: Video Streaming in vlcj尽管该用户有相同的错误,但我无法从此链接解决我的问题,尽管我确实使用了其中的 StreamHttp 代码示例。我是一个相对缺乏经验的程序员,所以如果我错过了一个明显的解决方案,那么我深表歉意。我使用的是 Java 1.8、Windows 7 64 位。

最佳答案

你需要这样的东西:

String media = "screen://";
String[] options = {
":sout=#transcode{vcodec=FLV1,vb=4096,scale=0.500000}:http{mux=ffmpeg{mux=flv},dst=:5000/"
};

此处显示的关键内容是用于对视频进行转码的“sout”字符串,然后是另一个附加的“sout”字符串以进行流传输(在本例中通过 http)。

在此示例字符串中,对于 http 流,仅指定端口(5000,任意选择)。未指定主机,因此表示 localhost。您可以使用“dst=127.0.0.1:8080/”或任何您需要的内容。

您必须选择/试验您想要的特定转码/流媒体选项。没有一种方法适合所有这些选项。

脚注:

您实际上可以使用 VLC 本身来为您生成此字符串。

启动 VLC,然后选择您要播放的媒体。

不要按“播放”,而是使用小部件选择“流”。这将打开流媒体向导,您可以在其中选择所有选项。

在向导结束时,在您开始演奏之前,它会向您显示所需的字符串。

关于java - VLCJ 中的流式桌面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42614712/

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