-1

I want to stream a video from server to the client. I have found the code for streaming the video from the server to the client side but get an error when running it:

Streaming 'vlcj-speed-run.flv' to  ':sout=#duplicate{dst=std{access=http,mux=ts,dst=127.0.0.1:5000}}'

[018ec020] access_output_http access out: Consider passing --http-host=IP on the command line instead.

[018b4978] main mux error: cannot add this stream

[05493078] main decoder error: cannot create packetizer output (FLV1)
Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
Ahsan
  • 11
  • 1
  • 1
  • 9
  • What OS are you running? Do you have VLC installed? You should provide a short code snippet that reproduces the problem. – Jacob Schoen Jul 05 '12 at 13:36
  • windows 7 and the source is here http://code.google.com/p/vlcj/source/browse/trunk/vlcj/src/test/java/uk/co/caprica/vlcj/test/streaming/StreamHttp.java , Please help me in that , how it can be done... , yes i have properly installed the Vlc – Ahsan Jul 05 '12 at 13:43
  • I think the problem is in the Media Option String , i have searched on this blog , many of them have changed the Media Option String and it works fine for them, Please can any body tell me is there any need to change the Media Option String , i want to stream the video file from server to the client – Ahsan Jul 05 '12 at 13:57
  • If you are running that example I think you may be confused. It points 127.0.0.1 which is localhost (your computer). Essentially you do not have anything listening for that response. You need to point it to something valid. – Jacob Schoen Jul 05 '12 at 14:09
  • But it can be possible to send the packets to the local host , i have done alot of programming on the Network , in which we send the packets to local host and also received that packets , Actually i want some thing helpful . It Can be done i have seen the example even on the Stack Overflow in which many of them are Streaming the video to the Local Host. Please , can any one help me in that ? . Actually i am new to the vlcj , so not confirmed is that way is fine to stream the video. – Ahsan Jul 05 '12 at 14:58
  • Okk Buddy Thanks , the error is now gone , Program now working without error but now can any one tell me that from where the client can see this Streamed video , actually i don't know about this .. Help me. – Ahsan Jul 05 '12 at 15:24

1 Answers1

2

I think you are working from and old example, well actually I think you are working from an old test case. The vlcj project has moved to github from googlecode. So more than likely you are using an older version of the library.

Secondly, if you check out Part 2 by the guy who wrote the library, I think it will clear some things up for you. Essentially you should be using EmbeddedMediaPlayerComponent in most instances, in which case you can either pass in the url to a stream or a file path to a local file to be played.

I am including the Part 2 source code below:

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

import com.sun.jna.NativeLibrary;
public class Tutorial2B {

  private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        new Tutorial2B(args);
      }
    });
  }

  private Tutorial2B(String[] args) {
    JFrame frame = new JFrame("vlcj Tutorial");

    mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

    frame.setContentPane(mediaPlayerComponent);

    frame.setLocation(100, 100);
    frame.setSize(1050, 600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
  }
}

Explanation of StreamHttp.java

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 {

    //when running this it requires an MRL (Media Resource Locator)
    //fancy term for saying the file you want to stream. This could be a url to another
    //location that streams media or a filepath to a media file you want to stream
    //on the system you are running this code on.
    public static void main(String[] args) throws Exception {
        if(args.length != 1) {
            System.out.println("Specify a single MRL to stream");
            System.exit(1);
        }

        //the media you are wanting to stream
        String media = args[0];
        //this is the IP address and port you are wanting to stream at
        //this means clients will connect to http://127.0.0.1:5555
        //to watch the stream
        String options = formatHttpStream("127.0.0.1", 5555);

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

        //this creates a the actual media player that will make calls into the native
        //vlc libraries to actually play the media you supplied. It does it in
        //a headless fashion, as you are going to stream it over http to be watched
        //instead of playing it locally to be watched.    
        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
        HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();

        //this simply starts the player playing the media you gave it
        mediaPlayer.playMedia(media, options);

        // Don't exit
        //basically you don't want the thread to end and kill the player, 
        //so it just hangs around and waits for it to end.
        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();
    }
}
Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
  • but again here you are not streaming the video to the client , ok plz just listen what i want actually i want some thing like exactly the youtube in which the user/client request for the video to play and then the server stream this video to the user/client . Actually i want this .. Plz comment on this , can it be done using the soure code of which i given the ink in the above comment. – Ahsan Jul 05 '12 at 15:47
  • I am not sure why I am still trying, but I'll just assume your hostility is due to a language barrier and not your personality. What is the client you are using to try to play the stream? How are you trying to connect to the stream? – Jacob Schoen Jul 05 '12 at 17:17
  • okk , can you please explain me what this code is doing , in simple words ,http://code.google.com/p/vlcj/source/browse/trunk/vlcj/src/test/java/uk/co/caprica/vlcj/test/streaming/StreamHttp.java . Why we are giving the Ip address and the Port No here..... – Ahsan Jul 05 '12 at 17:29
  • I should also add, that the ip address and port are used by vlc to know what ip and port to listen on. A single system could theoretically have multiple IP addresses, so most applications like this give you the ability to bind it to a particular one. You may be able to use `0.0.0.0` to tell it to listen on all ip addresses the system has assigned to it. But you still need to specify a port for it to listen on. – Jacob Schoen Jul 05 '12 at 18:02
  • Really Thanks sir , can you please tell me one thing through this code can i make this possible for server to stream the video to the client side .. Is that possible through this code , because there is a person which is using this code for that purpose to stream the video from the server side to the client side to make the client able to watch this video (Just Like Youtube Mechanism). May be i am totally wrong . I am new to vlcj so plz kindly co-operate with me .. – Ahsan Jul 05 '12 at 18:11
  • If you mean to embed it in you site to allow them to play it in their browser, you could but there are better options. You could upload it to YouTube (or similar service) and [embed it to your site](http://www.htmlgoodies.com/tutorials/web_graphics/article.php/3480061/How-To-Add-a-YouTube-Video-to-Your-Web-Site.htm). You could use Flash. You could use "HTML5" for newer browsers to [Embed Videos in your Website](http://www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/). There are just better options. – Jacob Schoen Jul 05 '12 at 18:22
  • VLC (which VLCj is just a java wrapper for) is not suited for this. As it just starts playing the stream on the server, not when the user decides to start it. You would have to do all kinds of hacks to make it work like YouTube. – Jacob Schoen Jul 05 '12 at 18:23
  • But can it be possible when the sever wants to play at the client side without any action of client.. – Ahsan Jul 05 '12 at 18:38
  • No it is not. Well technically it is possible, but not feasible. – Jacob Schoen Jul 05 '12 at 18:41
  • sir you really help me a lot , as you have said in your explanation of the code the client can connect to the server at the given ip address and port no to see that stream , i really want this can it be possible .. – Ahsan Jul 05 '12 at 18:44