Search code examples
javacapturevlcj

VLCJ save mediaplayer capture


I'm using VLCJ and I wish to save a video clip I'm playing using mediaPlayer.playMedia(); to my desktop. I know this can be accomplished by setting media options using a :sout string but I don't know which options to set and I'm having trouble understanding the example option strings on the web. Could someone help by explaining the following :sout option string?

String[] options = {":sout=#transcode{vcodec=mp4v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display}", ":input-slave=alsa://hw:0,0"};

I just need an options array that creates an mp4 video using the fileName destination. These options fail/error out for me.

Also, VLCJ seems to be dropping a ton of frames with this error

avcodec decoder error: more than 5 seconds of late video -> dropping frame

by using these options

String[] options = {":sout=#transcode{vcodec=mp1v,vb=2048,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{mux=mpeg1,dst=" + fileName + "},dst=display}", ":input-slave=dshow://hw:0,0" };

Solution

  • To save a raw stream, use media options similar to the following when you play the media:

    String mrl = "your-streaming-mrl";
    String[] opts = {"sout=#duplicate{dst=std{access=file,mux=raw,dst=output-file.ext}}"};
    

    Clearly you replace "your-streaming-mrl" and "output-file.ext" with whatever is appropriate.

    And then:

    mediaPlayer.playMedia(mrl, opts);
    

    You will need to wait (listen) for a media player "finished" event before your saved file is ready.

    You may also need to explicitly invoke release() on the media player before your saved file is ready.