【问题标题】:Live video streaming between Server and client - Using Java服务器和客户端之间的实时视频流 - 使用 Java
【发布时间】:2011-12-03 14:23:03
【问题描述】:

这是我正在进行的项目的一部分。我有两个桌面 java 应用程序,一个在服务器上运行(具有真实 IP),另一个是客户端。我只想从连接到服务器应用程序的网络摄像头流式传输实时视频,并在客户端应用程序上播放。我想从多个摄像头进行流式传输。

我一直在寻找 Xuggler、JMF、Red5、VLCj 之间的日子。我只是不知道应该从哪里开始,因为我是在编程中处理媒体的新手。

我应该从哪里开始的任何想法?

提前致谢

【问题讨论】:

标签: java video-streaming client-server


【解决方案1】:

我建议您使用 VLCJ,因为除了实时视频流之外,您还可以在应用程序中使用 VLC 媒体播放器的所有功能。此外,它适用于 Linux、Windows 和 Mac。如果你可以用 VLC 直播你的网络摄像头,那么你可以用 VLCJ 做同样的事情。

有关如何使用它的详细信息,请参阅 VLCJ wiki page。他们在 wiki 中提供了许多示例。这是使用 VLCJ 的 Http Streaming 的示例。复制自 VLCJ 示例。

/*
 * This file is part of VLCJ.
 *
 * VLCJ is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VLCJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VLCJ.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Copyright 2009, 2010, 2011 Caprica Software Limited.
 */

package uk.co.caprica.vlcj.test.streaming;

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 {

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

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

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

【讨论】:

  • 谢谢你。我可以在客户端应用程序中嵌入这个实时流吗?因为它是一个桌面应用程序。
  • @Mariam 如果您的客户端是桌面应用程序,您也可以使用 VLCJ 本身来接收和播放流。
  • 我可以使用这个库在服务器端流式传输视频吗?
  • 您好,即使我在尝试导入 VlcjTest 包时尝试实现相同的东西,它说找不到所需的包,您能帮帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 2012-11-22
  • 2014-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多