Java VLCJ中的流式桌面
我正在尝试编写一个Java程序,它允许一个用户充当服务器并传输他们的桌面(视频和音频),然后其他用户充当客户端并观看他们桌面的实时流(类似于Twitch、Webex、Skype screenshare等)。我正在为此使用VLCJ,虽然我没有承诺使用它,所以如果有更好的解决方案,我会洗耳恭听。下面是我从下面提供的链接复制的代码:Java VLCJ中的流式桌面,java,video-streaming,vlc,vlcj,Java,Video Streaming,Vlc,Vlcj,我正在尝试编写一个Java程序,它允许一个用户充当服务器并传输他们的桌面(视频和音频),然后其他用户充当客户端并观看他们桌面的实时流(类似于Twitch、Webex、Skype screenshare等)。我正在为此使用VLCJ,虽然我没有承诺使用它,所以如果有更好的解决方案,我会洗耳恭听。下面是我从下面提供的链接复制的代码: package test.java; import uk.co.caprica.vlcj.discovery.NativeDiscovery; import uk.co
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)
我试图寻找一个解决方案,但我能找到的是:
虽然这个用户也有同样的错误,但我无法通过这个链接解决我的问题,尽管我确实使用了其中的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,任意选择)。未指定主机,因此它表示本地主机。您可以有类似于“dst=127.0.0.1:8080/”或任何您需要的内容
您必须选择/试验所需的特定转码/流媒体选项。这些选择没有一刀切的余地
注意:
实际上,您可以使用VLC本身为您生成这个字符串
启动VLC,然后选择要播放的媒体
不要按“播放”,而是使用小部件选择“流”。这将打开流式处理向导,您可以在其中选择所有选项
在向导结束时,在开始播放之前,它会显示您需要的字符串。打开VLC,媒体>流>捕获设备,将捕获模式设置为桌面,添加一个目标:RTP/MPEG传输流,地址=230.0.0.1,基本端口=5555,转码配置文件:视频-H.264+MP3(MP4),然后我看到了您提到的字符串。然而,我一碰到“流”,VLC就崩溃了。我不确定是什么导致了这个错误,可能是我选择的转码选项或目的地吗?我会继续尝试不同的组合。谢谢你迄今为止的帮助!(抱歉,上面的评论太快了)继我之前的评论之后:我已经用HTTP默认设置(路径=/,端口=8080)测试了每个默认转码选项,并且VLC在每个选项上都崩溃了,除了最后的仅音频选项[audio-Vorbis(OGG)]。我不确定这表明了什么,但我将对其他传输协议(RTP等)进行相同的测试,看看是否得到不同的结果。我在发布之前测试了我发布的内容。VLC崩溃是完全不同的事情。还要记住,stackoverflow是问答,它不是一个讨论论坛,所以在评论中跟进其他问题并不是真正要做的事情