Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/

@ishaan-shringi

This comment has been minimized.

Copy link

@ishaan-shringi ishaan-shringi commented Aug 17, 2018

in my case it is not giving any output. gets stuck.

D:\dash>ffmpeg -i udp://124.1.1.1:7777 -acodec copy -vcodec copy -f dash ffmpeg_dump.mpd
ffmpeg version N-91565-g1940c27c82 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.1 (GCC) 20180722
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-
libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvids
tab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 22.100 / 58. 22.100
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 26.100 /  7. 26.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment