本文介绍了服务器和客户端之间的实时视频流 - 使用Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我一直在寻找Xuggler,JMF,Red5,VLCj之间的天。我只是不能从我应该开始,因为我是新的处理媒体在编程中。



从这里开始的任何想法?



提前感谢

$ b $我建议你使用VLCJ,因为除了实时视频流,你获得所有的VLC媒体播放器的功能可用于您的应用程序。此外,它可用于Linux,Windows和Mac。如果你可以使用VLC实时流式传输网络摄像头,那么你可以对VLCJ进行同样的操作。



有关详情,请参阅VLCJ 如何使用它。他们在wiki中提供了很多例子。这里是使用VLCJ的Http Streaming的示例。从VLCJ示例复制。

  / * 
*此文件是VLCJ的一部分。
*
* VLCJ是免费软件:您可以根据GNU通用公共许可证的条款重新分配和/或修改
*,由
*自由软件基金会,版本3的许可证,或
*(可选)任何更高版本。
*
* VLCJ分布在希望它将是有用的,
*,但没有任何保证;甚至没有
*适销性或适用于特定用途的默示保证。有关更多详细信息,请参阅
* GNU通用公共许可证。
*
*您应该已经收到GNU通用公共许可证
*和VLCJ的副本。如果没有,请参阅< http://www.gnu.org/licenses/> ;.
*
*版权所有2009,2010,2011 Caprica Software Limited。
* /

包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;

/ **
*有关如何通过HTTP流式传输媒体文件的示例。
*< p>
*客户端指定MRL为< code> http://127.0.0.1:5555< / code>
* /
public class StreamHttp extends VlcjTest {

public static void main(String [] args)throws Exception {
if(args.length! {
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);

//不退出
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();
}
}


this is part of a project I am working on. I have two desktop java application , one runs on the server (which has real IP), and the other is the client. I just want to stream a live video from a webcam connected to the server application , and play it on the client application. I want to do this streaming from more than one camera.

I have been looking searching for days between Xuggler, JMF, Red5, VLCj. I just can't figure from where I should start as I am new to dealing with media in programming.

Any ideas from where I should start with this ?

Thanks in advance

解决方案

I suggest you to go with VLCJ, because in addition to live video streaming, you get all features of VLC media player available to your application. Also, it is available for Linux,Windows, and Mac. If you can live stream your webcam with VLC, then you can do the same with VLCJ.

Refer VLCJ wiki page for details on how to use it. They provided many examples in the wiki. Here is an example of Http Streaming using VLCJ. Copied from VLCJ examples.

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

这篇关于服务器和客户端之间的实时视频流 - 使用Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 05:22
查看更多