Frage

I try to open a video stream from a RTSP server into a JAVA application. 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

https://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 ?

War es hilfreich?

Lösung

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.

Andere Tipps

This is a full example with java, include a Java class for streaming (no need to create other functions)

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top