繁体   English   中英

带VLCJ的Java http流视频-无法打开您的输入

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

我正在尝试使用VLCJ库用Java编写一个http视频流应用程序,但出现问题“您的输入无法打开”。

操作系统: 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字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM