Java 使用 VLCJ 的 http 流媒体视频 - 您的输入无法打开

Java http Streaming Video with VLCJ - Your input can't be opened

我正在尝试使用 VLCJ 库 Java 编写一个 http 视频流应用程序,但我遇到了问题 "your input can't be opened"。

OS: Windows10 x64

我的源代码:https://github.com/caprica/vlcj/blob/master/src/test/java/uk/co/caprica/vlcj/test/streaming/StreamHttp.java

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.runtime.x.LibXUtil;
import java.io.File;

/**
 * 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 VideoStream extends  VlcjTest{

    public static void main(String[] args) throws Exception {
        System.setProperty("VLC_PLUGIN_PATH", "D:\Program Files\VideoLAN\VLC\plugins");
        File vlcInstallPath = new File("D:\Program Files\VideoLAN\VLC");
        NativeLibrary.addSearchPath(
                RuntimeUtil.getLibVlcLibraryName(), vlcInstallPath.getAbsolutePath());
        Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
        LibXUtil.initialise();
        String media = "D://demo.mp4";
        String options = formatHttpStream("127.0.0.1", 5555);
        System.out.println("Streaming '" + media + "' to '" + options + "'");

        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
        HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
        mediaPlayer.playMedia(media, options);

        // Don't exit
        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();
    }
}

结果:

[000000001a948be0] access_output_http access out: Consider passing --http-host=IP on the command line instead.
[000000001aa2def0] core input error: open of `D://demo.mp4' failed
[000000001aa2def0] core input error: Your input can't be opened
[000000001aa2def0] core input error: VLC is unable to open the MRL 'D://demo.mp4'. Check the log for details. 

问题在

String media = "D://demo.mp4";

如评论所建议。 //D: 之后,它将被视为协议名称。

以下变体之一应该适合您:

String media = "D:/demo.mp4";

前提是playMedia支持本地文件路径。或者

String media = new File("D:/demo.mp4").toURI().toURL();

如果它需要 URL 字符串。