我试图写一个Java程序,它允许一个用户充当服务器和流自己的桌面(视频&音频),然后其他用户作为客户和观看他们的桌面的实时数据流(类似于Twitch,Webex,Skype屏幕共享等)。我正在使用VLCJ,尽管我没有使用它的承诺,所以如果有更好的解决方案,我全是耳朵。这是从我提供的链接复制的代码:流桌面的VLCJ
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位。
OK,所以我尝试了以下步骤: – anvijost
打开VLC,Media> Stream> Capture Device,将Capture模式设置为Desktop,添加目标:RTP/MPEG传输流,地址= 230.0.0.1,基本端口= 5555,转码配置文件:视频 - H.264 + MP3(MP4),然后我看到你提到的字符串。但是,一旦我点击“Stream”,VLC就会崩溃。我不确定是什么导致了这个错误,它可能是我选择的转码选项还是目的地?我会继续尝试不同的组合。感谢您一直以来的帮助! (对不起,以上评论过早发布) – anvijost
Followup to my previous comment:我测试了每个默认转码选项,默认设置为HTTP(path = /,port = 8080),VLC随每个选项都崩溃,除了最终的仅音频选项[音频 - Vorbis(OGG)]。我不确定这是什么意思,但我会用其他传输协议(RTP等)进行相同的测试,看看我是否得到不同的结果。 – anvijost