从服务器端到客户端的视频流

时间:2012-07-05 17:24:01

标签: video video-streaming vlcj

  

可能重复:
  Video Streaming in vlcj

public class VlcTest extends VlcjTest {
  public static void main(String[] args) throws Exception {
    if(args.length != 1) {
      System.out.println("Specify a single MRL to stream");
      System.exit(1);
    }

    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

    String media = args[0];
    String [] options = formatHttpStream("127.0.0.1", 5080);

    System.out.println("Streaming '" + media + "' to '" + options + "'");

    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
    HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
    mediaPlayer.playMedia(media, options);
    // Don't exit
    Thread.currentThread().join();
  }

  private static String [] formatHttpStream(String serverAddress, int serverPort) {
    String [] sb={":sout = #duplicate{dst=std{access=http,mux=ts,dst=127.0.0.1:5080}}"};
    return sb;
  }
}

我想确认此代码是否能够将视频从服务器流式传输到客户端。我想要实现的流程是:

  1. 客户端向服务器发送流的请求
  2. 服务器创建与客户端的连接,以根据客户端IP地址和端口号发送视频。

1 个答案:

答案 0 :(得分:0)

没有这个代码不会做你想要的全部。有关原因,请参阅我之前问题的answer。特别是“StreamHttp.java部分的解释”