Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozgurgul/c98dc2ef855cc3f6c8b623e3393c4350 to your computer and use it in GitHub Desktop.
Save ozgurgul/c98dc2ef855cc3f6c8b623e3393c4350 to your computer and use it in GitHub Desktop.
Use ffmpeg to connect to an ip cctv camera and create video files on the fly that can be viewed in an mpeg-dash compatible browser using dash.js and an html5 video element.

Live streaming mpeg-dash video using ffmpeg and dash.js

Use ffmpeg to connect to an ip cctv camera and create video files on the fly that can be viewed in an mpeg-dash compatible browser using dash.js and an html5 video element.

Prerequisites

A linux server, such as Ubuntu

Apache web server installed, running, and reachable via its ip address

Latest version of Ffmpeg installed

An ip camera that is reachable from the server

Configuring Server

Get root access.

sudo su

Make a new directory in /dev/shm. This is crucial because we will be constantly writing files and do not want to target the hard drive.

mkdir /dev/shm/mpeg-dash

Create a symlink from /dev/shm/mpeg-dash to the public directory where apache serves files.

ln -s /dev/shm/mpeg-dash /var/www/html

Create an html file that contains the necessary code to display the mpeg-dash video.

cat > /var/www/html/mpeg-dash/index.html << EOF
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src="https://cdn.dashjs.org/latest/dash.all.min.js"></script>
<style>
    video {
        width: 640px;
        height: 480px;
    }
</style>
<body>
    <div>
        <video data-dashjs-player autoplay controls src="manifest.mpd" type="application/dash+xml"></video>
    </div>
</body>
</html>
EOF

Generating Video

Run ffmpeg with the correct parameters to connect to your ip camera and generate the mpeg-dash video files.

ffmpeg -i rtsp://ip_cam_address:554/user=user_password=password_channel=1_stream=0.sdp -an -c:v copy -b:v 2000k -f dash -window_size 4 -extra_window_size 0 -min_seg_duration 2000000 -remove_at_exit 1 /var/www/html/mpeg-dash/manifest.mpd

View Video

Open an mpeg-dash compatible browser such as Chrome, Firefox, Safari, or IE11(Windows 8+ only).

Enter the address to the directory on your server. http://YOUR_SERVER_IP_ADDRESS/mpeg-dash/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment