Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Create Docker image for the system
Browse files Browse the repository at this point in the history
  • Loading branch information
DenizUgur committed Jul 6, 2022
1 parent a86b3bf commit a865f91
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 29 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules/
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Docker

on:
push:
branches: [V2]

jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v3
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v3
with:
cache: cache
push: true
tags: ghcr.io/denizugur/capsc:latest

- name: Inspect image
run: echo ${{ steps.docker_build.outputs.digest }}
143 changes: 143 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Build OpenCV
FROM ubuntu:xenial AS ffmpeg-builder
ARG DEBIAN_FRONTEND=noninteractive

# Update apt cache
RUN apt-get update

# Install dependencies
RUN apt-get --no-install-recommends -y remove ffmpeg x264 libx264-dev
RUN apt-get --no-install-recommends -y install libopencv-dev
RUN apt-get --no-install-recommends -y install build-essential checkinstall cmake pkg-config yasm
RUN apt-get --no-install-recommends -y install libtiff5-dev libjpeg-dev libjasper-dev
RUN apt-get --no-install-recommends -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
RUN apt-get --no-install-recommends -y install python-dev python-numpy
RUN apt-get --no-install-recommends -y install libtbb-dev
RUN apt-get --no-install-recommends -y install libqt4-dev libgtk2.0-dev
RUN apt-get --no-install-recommends -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
RUN apt-get --no-install-recommends -y install x264 v4l-utils ffmpeg
RUN apt-get --no-install-recommends -y install libgtk2.0-dev
RUN apt-get --no-install-recommends -y install ca-certificates git

# Downlaod OpenCV Source
RUN git clone --branch 2.4.9 --depth 1 https://github.com/opencv/opencv.git

# Compile OpenCV
RUN mkdir opencv/build
RUN cd opencv/build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON .. && \
make -j`nproc`

# Install OpenCV
RUN cd opencv/build && \
make install && \
sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' && \
ldconfig

# Build our custom FFmpeg
ENV PATH="/bin:$PATH"
ENV PKG_CONFIG_PATH="$BASE/build/lib/pkgconfig"

# Install dependencies
RUN apt-get --no-install-recommends -y install \
autoconf \
automake \
build-essential \
cmake \
git-core \
libx264-dev \
libopencv-dev \
libass-dev \
libfreetype6-dev \
libgnutls28-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
libunistring-dev \
pkg-config \
texinfo \
wget \
yasm \
libx264-dev \
zlib1g-dev

# Copy custom FFmpeg source
COPY ./FFmpeg/FFmpeg /FFmpeg

# Compile FFmpeg
RUN mkdir -p build
RUN cd FFmpeg && \
./configure \
--prefix="/build" \
--pkg-config-flags="--static" \
--extra-cflags="-I/build/include -march=native" \
--extra-ldflags="-L/build/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--bindir="/usr/local/bin" \
--enable-gnutls \
--enable-libass \
--enable-libfreetype \
--enable-libfontconfig \
--enable-libvorbis \
--enable-gpl \
--enable-libx264 \
--enable-libopencv \
--enable-nonfree
RUN cd FFmpeg && make -j`nproc` && make install

RUN mkdir -p /libraries/usr/lib /libraries/lib
RUN ldd /usr/local/bin/ffmpeg | grep "/usr/lib" | awk 'NF == 4 { system("cp " $3 " /libraries/usr/lib") }'
RUN ldd /usr/local/bin/ffmpeg | grep -v "/usr/lib" | awk 'NF == 4 { system("cp " $3 " /libraries/lib") }'

# Prepare Node related stuff
FROM node:lts-slim AS node-builder

# Copy package descriptions
COPY ./dashjs/package*.json /dashjs/
COPY ./server/app/package*.json /server/app/

# Install dependencies
RUN npm --prefix /dashjs ci
RUN npm --prefix /server/app ci

# Copy source
COPY ./dashjs/. /dashjs/
COPY ./server/. /server/

# Link DASH.js globally
RUN cd /dashjs && npm link
RUN cd /server/app && npm link dashjs

# Build products
RUN npm --prefix /server/app run build
RUN npm i -g pkg
RUN cd /server && pkg -C GZip -t latest-linux-x64 gpac-dash.js

# Finalize the image
FROM ubuntu:xenial
EXPOSE 80

# Install Node.js & NGINX
RUN apt-get update && \
apt-get install --no-install-recommends -y nginx figlet && \
rm -rf /var/lib/apt/lists/*

COPY --from=ffmpeg-builder /libraries/usr/lib /usr/lib/x86_64-linux-gnu/
COPY --from=ffmpeg-builder /libraries/lib /lib/x86_64-linux-gnu/
COPY --from=ffmpeg-builder /usr/local/bin/ff* /usr/local/bin/

# Setup NGINX
COPY ./config/nginx.prod.conf /etc/nginx/nginx.conf

# Prepare Dash.JS & Live Stream Host
COPY --from=node-builder /server/gpac-dash /usr/local/bin/
COPY --from=node-builder /server/app/build /opt/server

COPY ./scripts/entrypoint.sh /opt/entrypoint.sh
ENTRYPOINT [ "/opt/entrypoint.sh" ]
2 changes: 1 addition & 1 deletion FFmpeg/FFmpeg
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,34 @@ There are two main factors that determine the viewer experience during the live
## Table of Contents

- `demo/` contains the source code for our [demo page](http://streaming.university/demo/mmsys21-capsc/)
- `densifier/` contains an example web page for creating event density files for metadata-feeder to use.
- `development/` contains the development environment. It is needed by the simulator and provides example code for several metrics. This directory also contains GPAC-Dash server that streams chunks to the client.
- `metadata-feeder/` contains the Java server that feeds CAPSC the event densities.
- `server/` contains the web server. It is needed by the simulator and provides example code for several metrics. This directory also contains GPAC-Dash server that streams chunks to the client.
- `scripts/` contains some scripts to start development environment
- `simulator/` contains the utilities needed to benchmark CAPSC

## Demo

We have included a docker image for you to test our system live.

If you want to build the image yourself, execute the following:

```bash
docker build -t capsc .
```

To run the image, execute the following:

```bash
docker run -p 80:80 \ # web server will be accesible on port 80
--rm \ # remove the container after it is stopped
-it \ # Interactive mode. Needed for Ctrl^C to work.
-v "$PWD:/home" \ # You need to map a location to be able to use your video files
-w "/home" \ # If you want to use your own video files
--name capsc-demo \ # Optional: If you want to name the container
ghcr.io/denizugur/capsc \ # Chanege it to `capsc` if you built the image yourself
<path to input file> # A file to stream. Must be relative to current working directory
<true or false> # Set to true if you want to display the visualizations over the video
```

## Citation

```
Expand Down
5 changes: 1 addition & 4 deletions config/nginx.conf → config/nginx.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ events {
http {
server {
listen 80;
server_name 192.168.1.100;
server_name localhost;

location / {
types {
text/html html;
}
proxy_pass http://127.0.0.1:3000;
}

Expand Down
27 changes: 27 additions & 0 deletions config/nginx.prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
worker_processes auto;

events {
worker_connections 1024;
}

http {
server {
listen 80;
server_name localhost;

location / {
types {
text/html html;
text/css css;
text/javascript js;
}
root /opt/server;
index index.html;
}

location /content {
add_header Cache-Control no-cache;
proxy_pass http://127.0.0.1:8000;
}
}
}
2 changes: 1 addition & 1 deletion dashjs
Submodule dashjs updated 2 files
+18,235 −18,234 package-lock.json
+0 −1 package.json
10 changes: 0 additions & 10 deletions scripts/all.sh

This file was deleted.

52 changes: 52 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
INPUT_FILE=$1
VISUALIZATION=$2

if [ -z $INPUT_FILE ]; then
echo "No input file specified"
exit 1
fi

if [ -z $VISUALIZATION ]; then
VISUALIZATION=0
else
VISUALIZATION=3
fi

# Start NGINX
nginx

# Start GPAC
cd /opt
(gpac-dash -chunk-media-segments -cors &) >/dev/null 2>&1

# Show banner
figlet "A-CAPSC Demonstration"
echo "============================================================"
echo
echo "Please give us a moment to start up..."
echo "Streaming to: http://localhost/"

# Start DASH Stream
SOURCE=$(realpath /home/$INPUT_FILE)
TARGET=$(realpath /opt/content/)

mkdir -p $TARGET

GOP_SIZE=60
PRESET=ultrafast
V_SIZE=1280x720

ffmpeg \
-stream_loop -1 -re -i $SOURCE \
-c:v libx264 -keyint_min $GOP_SIZE -g $GOP_SIZE -pix_fmt yuv420p -r 30 \
-vf "sa=snooker:$VISUALIZATION" \
-map v:0 -s:0 $V_SIZE \
-init_seg_name init\$RepresentationID\$.\$ext\$ -media_seg_name chunk\$RepresentationID\$-\$Number%05d\$.\$ext\$ \
-adaptation_sets "id=0,streams=v" \
-use_template 1 -use_timeline 0 \
-frag_type every_frame \
-seg_duration 10 \
-streaming 1 -ldash 1 -tune zerolatency \
-preset $PRESET \
-f dash $TARGET/app.mpd >/dev/null 2>&1
2 changes: 1 addition & 1 deletion scripts/gpac.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
BASE=$(dirname "$0")
cd $BASE/../development
cd $BASE/../server
forever ./gpac-dash.js -chunk-media-segments -cors
2 changes: 1 addition & 1 deletion scripts/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FFMPEG_BIN=$BASE/../FFmpeg/bin
FFMPEG=$FFMPEG_BIN/ffmpeg

SOURCE=$(realpath $1)
TARGET=$(realpath $BASE/../development/content/$STREAM_NAME)
TARGET=$(realpath $BASE/../server/content/$STREAM_NAME)

if [ -z $STREAM_NAME ]; then
STREAM_NAME=app
Expand Down
12 changes: 6 additions & 6 deletions scripts/server.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
BASE=$(dirname "$0")
BASE=$(pwd)

# Start NGINX
nginx -c $BASE/../config/nginx.conf -s stop >> /dev/null
nginx -c $BASE/../config/nginx.conf
nginx -s stop >/dev/null 2>&1
nginx -c $BASE/config/nginx.dev.conf

# Start Next.js
echo http://localhost/tv
npm --prefix $BASE/../development/app run dev
# Start React
BROWSER=none npm --prefix $BASE/server/app run start
File renamed without changes.
4 changes: 2 additions & 2 deletions development/gpac-dash.js → server/gpac-dash.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ var onRequest = function (req, res) {

// we send the files as they come, except for segments for which we send fragment by fragment
if (filename === "") {
filename = `${__dirname}${parsed_url.path.slice(0, parsed_url.path.lastIndexOf("/"))}`;
filename = `${process.cwd()}${parsed_url.path.slice(0, parsed_url.path.lastIndexOf("/"))}`;
}
filename = `${__dirname}/${filename}`;
filename = `${process.cwd()}/${filename}`;
let existingM4s=false;
try {
fStat = fs.statSync(filename);
Expand Down

0 comments on commit a865f91

Please sign in to comment.