Software Engineering

My part in its downfall

All the salient facts are true

Java video streaming part 2

Objective

Simple demo code for Java video streaming. Review the setup and configuration for different video streaming engines.

Target Audience

Java Developers new to modern video streaming frameworks and tooling

Source Documents

ffmpeg
Real Time Streaming Protocol(RTSP)
Java FX media support
Java FX media support restrictions
vlcj
Java Media Framework
Java Media Framework RTSP Support
Video Container
JavaFX Demo app for RTSP
Golang utility for ffmpeg transcode

Summary

Use ffmpeg to transcode a rtsp stream to a file for JavaFX video client. The main result for this second part is a simple demo application that renders multiple video streams from remote web-cams, it includes a golang utility to run the transcoding process

Result

JavaFX Demo app for RTSP
Golang utility for ffmpeg transcode

Discussion

A typical use case for a JavaFX streaming video client would be a home or buisness security application where you would have 2 or 3 rtsp cameras streaming video in a container format. Java FX media support restrictions outlines why you can not directly render this video with the JavaFX media engine. Java FX media support shows you the available containers, more about containers here (video container).
The Demo app for RTSP is an entry into how you would construct a home or buisness security application to stream rtsp sources. It uses vlcj which we outlined in part 1 and ffmpeg to transcode the RTSP source to a file via the Golang utility.

Below are some examples for using ffmpeg to transcode rtsp sources to a container compatible with vlc.

  1. transcode a rtsp source to udp
    ffmpeg -i {rtsp src url} -c:a acodec -c:v h264 -vf scale=1280x720 -an -pix_fmt yuv420p -c:a copy -f mpegts udp://@localhost:1234

  2. transcode a rtsp source to a file in segments
    ffmpeg -i {rtsp src url} -c:v h264 -vf scale=1280x720 -an -pix_fmt yuv420p -map 0 -f segment -segment_time 20 /home/ubu/aVidOut/Hessdalen1/output%d.mp4

  3. transcode a rtsp source to a file
    ffmpeg -i {rtsp src url} -c:v libx264 -preset medium -crf 22 -c:a copy /home/ubu/output.MP4

Source code highlights

1 Using Springs @Scope(“prototype”) to implement the Producer pattern from CDI at line 57, Springs prototype scope will inject a new object however the catch is it only a new object at the time it injects hence the need to create the object from ‘getBean(…)’ line 62

2 Using the Go Console User Interface GOCUI in the Golang utility for ffmpeg transcoding with ffmpeg

setup

1 setup the vlc dependencies as in part 1, if Debian after apt-get vlc you would set the native libary path as line 2
2 setup ffmpeg so its on the system path
3 set up the video output directory
4 set the transcode output paths in the go utility config properties
5 set the path to config.properties line 43
6 set the inputpaths for rendering in runtime.properties
7 build the golang ffmpeg utility [](//golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies)
8 build the java source as in part 1
9 run the transcoding process ffmpeg transcode
10 run the rendering application with
java -jar -Dvs.properties=/home/USER_HOME_DIR/aJavaFXSpectrum/v-stream/runtime.properties build/libs/v-stream-0.0.1-SNAPSHOT.jar

JavaFX Demo app for RTSP
Golang utility for ffmpeg transcode


Share

comments powered by Disqus