|
JSup is able to show video from many sources and can make the client to see videos from sources (cameras for example) that are only available from the server network.
These video capabilities are provided by using VLC media player that must be installed with JSup server and native clients, while web clients can display those videos with no need to install VLC.
JSupInterface.JSupVideo is a class that holds information about a video that can be shown in a Canvas to show cameras and other videos in a JSup application.
The info held by this class are:
- clientVideoPage: the web page that will be make available by the JSup server (via VLC) when the video will be requested, use an extension .ogg, .mp4 or .webm according to the videoFormat, for example "camera4.ogg". The clients (both native and web ones) will show the video by requesting this page from the http server opened by the JSup server instance.
- sourceVideoURL: this is the URL where the JSup server will get the video to be streamed to the clients. Can be any URL supported by VLC.
- videoFormat: the muxing to be used to stream the video from JSup server to clients. The video format can be implicit and defined only by the clientVideoPage exension. The video format also define the default transcoding options (codec and other parameter), see the next parameter.
- vlcTranscode: this string defines the transcoding that will be used from the JSup server to stream the video to the clients. If omitted a default one will be used based on the videoFormat parameter:
- OGG: " vcodec=theo,vb=1024,acodec=vorb,channels=1,ab=64,samplerate=44100"
- MP4: " vcodec=h264,vb=1024,acodec=mp4a,channels=1,ab=64,samplerate=44100"
- WEBM: " vcodec=VP80,vb=1024,scale=1,acodec=vorbis,channels=1,ab=64,samplerate=44100"
Please note that the WEBM format (with VP80 codec) could drain a lot of CPU, check the performance in your environment.
- resizeX / resizeY: the requested width and height for the transcoded video, if 0 the original will be kept (or automatic if only one of resizeX/Y is specified)
JSupVideo definition
These informations will be the same for server and client, so the definition of the JSup video must be put in a shared domain curly brackets JavaCode function called something like "{VideoDefinition}", included in the user domain also (this is important because both shared and user domains must define the JSupVideo objects in the same order to match their internal ids), and with a body like:
// mux/transcode automatico da estensione di <TT>clientVideoPage</TT>
public static final JSupVideo demoVideo = JSupVideo.define("Demo.mp4", "C:\\video\\demo video.mkv", 500, 300);
public static final JSupVideo camera4 = JSupVideo.define("camera4.ogg", "rtsp://user:password@192.168.1.64:554/Streaming/Channels/102", 500, 300);
// OGG
//public static final JSupVideo camera4 = JSupVideo.define("camera4.ogg", "rtsp://user:password@192.168.1.64:554/Streaming/Channels/102", JSupVideo.VideoFormat.OGG, 500, 300);
// MP4
//public static final JSupVideo camera4 = JSupVideo.define("camera4.mp4", "rtsp://user:password@192.168.1.64:554/Streaming/Channels/102", JSupVideo.VideoFormat.OGG, 500, 300);
//WEBM
//public static final JSupVideo camera4 = JSupVideo.define("camera4.webm", "rtsp://user:password@192.168.1.64:554/Streaming/Channels/102", JSupVideo.VideoFormat.WEBM, 500, 300);
The JSup videos will be streamed by the JSup server only when requested by clients. So when a client requests a video the server starts to stream the video, and, when no client request that video any more, the server will stop to stream it.
Play a JSupVideo in a window
A special JSup Graphic object have to be used to display a JSupVideo: select from the JSup menu Draw / Video canvas and draw the rectangle of the canvas.
Each canvas must a have its own video control object (interface JSupVideo.Control).
The control object must be defined in the window JavaCode common like:
static JSupVideo.Control camera4Control;
A pseudo Enable animation can be used to bind the Video canvas to the JSupVideo and obtain the control object, use a JavaCode like:
camera4Control = thisGraphObj.bindCanvasToVideo( camera4 );
return true;
Then the video can be played in the Action animation of a button with a JavaCode like:
crudeliaControl.startVideo();
The methods of the JSupVideo.Control interface are:
- startVideo() - the video is requested to the server and played in the Video canvas.
- stopVideo() - the video play is stopped and no more requested to the server .
- pauseVideo() - the video play is paused/resumed.
- isPlaying() - returns true if the video is currently playing (valid and not paused), false otherwise (is paused or the is not available).
- isValidVideoControl() - returns false if the video cannot be played (for example because VLC is not installed in the client)
Server/client Configuration
VLC (32 bit version) must be installed to stream (the server) and to play (the clients).
Both in the JSup server and native clients you have to specify the VLC installation dir in the JSup.cfg file defining the video.vlc.path system property:
#-------- the location of the libvlc.dll to be used for JSupVideo
-Dvideo.vlc.path=C:\Program Files (x86)\VideoLAN\VLC
In the JSup Application property dialog two properties must be defined:
video.streamserver.bindaddr=127.0.0.1
video.streamserver.port=7080
- bindaddr and port: define the IP address and TCP port where the VLC http server will be opened and the clients can connect to get the videos. An IP address of 127.0.0.1 (the default one) will enable only a local client (one that runs in the same PC where the JSup server runs).
Please note that the video.streamserver.port property is mandatory to have the JSupVideo system to work.
Problem solving
To avoid, when libvlc library is initialized on JSup startup, many error lines in the JSup output like:
main libvlc error: stale plugins cache: modified C:\Progr...
exec the following command in a administrative command prompt in the C:\Program Files (x86)\VideoLAN\VLC directory:
vlc-cache-gen.exe "c:\Program Files (x86)\VideoLAN\VLC\plugins"
|