【问题标题】:Java http Streaming Video with VLCJ - Your input can't be opened带有 VLCJ 的 Java http Streaming Video - 无法打开您的输入
【发布时间】:2017-10-08 19:53:47
【问题描述】:

我正在尝试使用 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. 

【问题讨论】:

标签: java video-streaming vlcj


【解决方案1】:

问题出在

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

按照评论的建议。 D: 后面的 // 将被视为协议名称。

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

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

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

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

如果它需要一个 URL 字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 2012-01-14
    相关资源
    最近更新 更多