vlcj 中的视频流 [英] Video Streaming in vlcj

查看:46
本文介绍了vlcj 中的视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to stream a video from server to the client. I have found the code for streaming the video from the server to the client side but get an error when running it:

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)

推荐答案

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

I think you are working from and old example, well actually I think you are working from an old test case. The vlcj project has moved to github from googlecode. So more than likely you are using an older version of the library.

其次,如果您查看编写该文档的人的第 2 部分图书馆,我想它会为你澄清一些事情.从本质上讲,您应该在大多数情况下使用 EmbeddedMediaPlayerComponent,在这种情况下,您可以将 url 传递给流或将文件路径传递给要播放的本地文件.

Secondly, if you check out Part 2 by the guy who wrote the library, I think it will clear some things up for you. Essentially you should be using EmbeddedMediaPlayerComponent in most instances, in which case you can either pass in the url to a stream or a file path to a local file to be played.

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

I am including the Part 2 source code below:

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();
    }
}

这篇关于vlcj 中的视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆