【问题标题】:Video Streaming in vlcjvlcj 中的视频流
【发布时间】:2012-07-05 11:36:21
【问题描述】:

我想将视频从服务器流式传输到客户端。我找到了将视频从服务器流式传输到客户端的代码,但运行时出错:

Streaming 'vlcj-speed-run.flv' to  ':sout=#duplicate{dst=std{access=http,mux=ts,dst=127.0.0.1:5000}}'

[018ec020] access_output_http access out: Consider passing --http-host=IP on the command line instead.

[018b4978] main mux error: cannot add this stream

[05493078] main decoder error: cannot create packetizer output (FLV1)

【问题讨论】:

  • 您运行的是什么操作系统?你有安装 VLC 吗?您应该提供重现问题的短代码 sn-p。
  • windows 7,源代码在这里code.google.com/p/vlcj/source/browse/trunk/vlcj/src/test/java/…,请帮助我,如何完成...,是的,我已经正确安装了 Vlc
  • 我认为问题出在媒体选项字符串上,我在这个博客上进行了搜索,他们中的许多人已经更改了媒体选项字符串并且对他们来说效果很好,请任何人告诉我在那里任何需要更改媒体选项字符串,我想将视频文件从服务器流式传输到客户端
  • 如果您正在运行该示例,我想您可能会感到困惑。它指向 127.0.0.1,它是本地主机(您的计算机)。本质上,您没有任何东西在听该响应。您需要将其指向有效的内容。
  • 但是可以将数据包发送到本地主机,我在网络上做了很多编程,我们将数据包发送到本地主机并接收到数据包,其实我想要一些有用的东西。可以做到我什至在 Stack Overflow 上也看到了这个例子,其中许多人正在将视频流式传输到本地主机。拜托,有人可以帮我吗? .实际上我是 vlcj 的新手,所以没有确认这种方式可以流式传输视频。

标签: video-streaming vlcj


【解决方案1】:

我认为您正在使用旧示例,实际上我认为您正在使用旧测试用例。 vlcj 项目已从 googlecode 移至 github。因此,您很可能使用的是旧版本的库。

其次,如果您查看编写库的人的Part 2,我认为它会为您解决一些问题。本质上,在大多数情况下,您应该使用 EmbeddedMediaPlayerComponent,在这种情况下,您可以将 url 传递给流或将文件路径传递给要播放的本地文件。

我在下面包含了第 2 部分的源代码:

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.sun.jna.NativeLibrary;
public class Tutorial2B {

  private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        new Tutorial2B(args);
      }
    });
  }

  private Tutorial2B(String[] args) {
    JFrame frame = new JFrame("vlcj Tutorial");

    mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

    frame.setContentPane(mediaPlayerComponent);

    frame.setLocation(100, 100);
    frame.setSize(1050, 600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
  }
}

StreamHttp.java的解释

import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import uk.co.caprica.vlcj.test.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 {
        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();
    }
}

【讨论】:

  • 但是在这里你又不是将视频流式传输到客户端,好吧,请听我想要的,实际上我想要一些东西,就像用户/客户端请求播放视频的 youtube 一样然后服务器将此视频流式传输到用户/客户端。其实我想要这个..请对此发表评论,可以使用我在上面评论中给出的墨水的源代码来完成。
  • 我不知道为什么我还在尝试,但我只是假设你的敌意是由于语言障碍而不是你的个性。您用来尝试播放流的客户端是什么?您是如何尝试连接到流的?
  • 好的,你能解释一下这段代码在做什么吗,简单地说,code.google.com/p/vlcj/source/browse/trunk/vlcj/src/test/java/…。为什么我们在这里给出 IP 地址和端口号.....
  • 我还应该补充一点,vlc 使用 ip 地址和端口来了解要监听的 ip 和端口。理论上,单个系统可以有多个 IP 地址,因此大多数像这样的应用程序都可以让您将其绑定到特定的 IP 地址。您可以使用0.0.0.0 告诉它监听系统分配给它的所有IP 地址。但是你仍然需要指定一个端口让它监听。
  • 非常感谢先生,您能否通过这段代码告诉我一件事,我可以让服务器将视频流式传输到客户端吗.. 通过这段代码可以实现吗,因为有一个为此目的使用此代码的人将视频从服务器端流式传输到客户端,以使客户端能够观看此视频(就像 Youtube 机制)。可能我完全错了。我是 vlcj 的新手,所以请与我合作..
猜你喜欢
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多