简体   繁体   English

使用vlcj示例运行示例RTSP(JAVA)

[英]Run example RTSP with vlcj example (JAVA)

I try to open a video stream from a RTSP server into a JAVA application. 我尝试从RTSP服务器打开视频流到JAVA应用程序。 First I tried to run this example : 首先,我尝试运行此示例:

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 using RTSP.
 * <p>
 * The client specifies an MRL of <code>rtsp://@127.0.0.1:5555/demo</code>
 */
public class StreamRtsp 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 = formatRtspStream("127.0.0.1", 5555, "demo");

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

    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
    HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
    mediaPlayer.playMedia(media,
      options,
      ":no-sout-rtp-sap", 
      ":no-sout-standard-sap", 
      ":sout-all", 
      ":sout-keep"
    );

    // Don't exit
    Thread.currentThread().join();
  }

  private static String formatRtspStream(String serverAddress, int serverPort, String id) {
    StringBuilder sb = new StringBuilder(60);
    sb.append(":sout=#rtp{sdp=rtsp://@");
    sb.append(serverAddress);
    sb.append(':');
    sb.append(serverPort);
    sb.append('/');
    sb.append(id);
    sb.append("}");
    return sb.toString();
  }
}

But I have always the same result : Specify a single MRL to stream 但我总是得到相同的结果:指定一个MRL来流式传输

http://i.stack.imgur.com/8iX0O.png http://i.stack.imgur.com/8iX0O.png

Even if I delete this section : 即使我删除此部分:

if(args.length != 1) {
          System.out.println("Specify a single MRL to stream");
          System.exit(1);
        }

Can you help me please ? 你能帮我吗 ?

Sounds like you're not actually passing an argument to the program, which it expects from this line: 听起来你实际上没有将参数传递给程序,它希望从这一行:

String media = args[0];

If you don't want to pass an argument, just change it to: 如果您不想传递参数,只需将其更改为:

String media = "(location of rtsp to stream)";

...and delete the if statement above it as you already have. ...并删除它上面的if语句。

This is a full example with java, include a Java class for streaming (no need to create other functions) 这是一个完整的java示例,包含一个用于流式传输的Java类(无需创建其他函数)

This is an example for a simple streaming : 这是简单流式传输的示例:

StreamRTP rtp = new StreamRTP();
rtp.start("10.20.11.142", 5000, "sample.mp3");

You can find the class here : https://github.com/maitmansour/vlcj-audio-rtp-streaming-example 你可以在这里找到这个课程: https//github.com/maitmansour/vlcj-audio-rtp-streaming-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM