Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Oct 7, 2021
0 parents commit ce1d459
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/virtual-rtsp.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM golang:1.16.1-alpine AS BUILD

RUN apk --update add git

#RTSP SIMPLE SERVER
WORKDIR /tmp
RUN git clone https://github.com/aler9/rtsp-simple-server.git
WORKDIR /tmp/rtsp-simple-server

RUN go mod download
RUN go build -o /go/bin/rtsp-simple-server .

#RTSP SIMPLE PROXY
WORKDIR /tmp
RUN git clone https://github.com/aler9/rtsp-simple-proxy.git
WORKDIR /tmp/rtsp-simple-proxy

RUN go mod download
RUN go build -o /go/bin/rtsp-simple-proxy .

FROM jrottenberg/ffmpeg:4.0-alpine

ENV SOURCE_URL ''
ENV STREAM_NAME 'stream'
ENV RTSP_PROXY_SOURCE_TCP 'yes'
ENV FORCE_FFMPEG 'true'
ENV FFMPEG_INPUT_ARGS ''
ENV FFMPEG_OUTPUT_ARGS='-c copy'

RUN apk --update add gettext bash

COPY --from=BUILD /go/bin/rtsp-simple-server /bin/rtsp-simple-server
COPY --from=BUILD /go/bin/rtsp-simple-proxy /bin/rtsp-simple-proxy

ADD proxy.yml /tmp/proxy.yml
ADD start-relay.sh /

EXPOSE 8554
EXPOSE 8000
EXPOSE 8001

ENTRYPOINT [ "/bin/bash" ]
CMD ["/start-relay.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 stutzlab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Virtual RTSP

This project creates a virtual RTSP connection, based on a looping MP4. It is inspired by and build on top of [flaviostutz's work](https://github.com/flaviostutz/rtsp-relay).

The idea of a virtual RTSP is to simulate real-world IP cameras forwarding a RTSP H264 encoded stream. The project is build for demo purposes, when no RTSP connection is available.

## Build with Docker

To build the container you can simply build the Dockerfile using following command.

docker build -t kerberos/virtual-rtsp .

## Run Docker container

To run the container you can have to specify a couple of environment variables, and important load in a m4p which can be streamed (and looped) through a RTSP connection.

### Download MP4

We've published a couple of MP4s in the [v1.0.0 release](https://github.com/kerberos-io/virtual-rtsp/releases/tag/v1.0.0) which you can use to stream. The MP4s are IP camera footage recorded by real-world IP cameras (Axis/HIKVision).

Go ahead and download a mp4 from the [v1.0.0 release](https://github.com/kerberos-io/virtual-rtsp/releases/tag/v1.0.0).

mkdir samples && cd samples
wget https://github.com/kerberos-io/virtual-rtsp/releases/download/v1.0.0/cars.mp4

If the mp4 is downloaded, we can inject the mp4 into our container by using volumes and specifying the environment variable `-e SOURCE_URL`.

docker run -p 8554:8554 \
-e SOURCE_URL=file:///samples/cars.mp4 \
-v $(pwd)/samples:/samples \
kerberos/virtual-rtsp

## Deploy to Kubernetes

To be written
15 changes: 15 additions & 0 deletions proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server:
# supported protocols
protocols: [ tcp, udp ]
# port of the RTSP UDP/TCP listener
rtspPort: 8554
# port of the RTP UDP listener
rtpPort: 8000
# port of the RTCP UDP listener
rtcpPort: 8001

streams:
$STREAM_NAME:
url: $SOURCE_URL
# whether to receive this stream in udp or tcp
useTcp: $RTSP_PROXY_SOURCE_TCP
Binary file added samples/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions start-relay.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e

if [[ $SOURCE_URL == file://* ]]; then
export FFMPEG_INPUT_ARGS="$FFMPEG_INPUT_ARGS -re -stream_loop -1"
fi

if [[ $SOURCE_URL == rtsp://* ]] && [ "$FORCE_FFMPEG_SOURCE" == "false" ]; then
envsubst < /tmp/proxy.yml > /proxy.yml
echo "/proxy.yml"
cat /proxy.yml
echo "Starting rtsp proxy from $SOURCE_URL to rtsp://0.0.0.0:8554/$STREAM_NAME..."
rtsp-simple-proxy /proxy.yml

else

if [ "$SOURCE_URL" != "" ]; then
echo "Starting rtsp server..."
rtsp-simple-server &
sleep 2

echo "Start relaying from $SOURCE_URL to rtsp://0.0.0.0:8554/$STREAM_NAME"
while true; do
set -x
ffmpeg $FFMPEG_INPUT_ARGS -i $SOURCE_URL $FFMPEG_OUTPUT_ARGS -f rtsp rtsp://127.0.0.1:8554/$STREAM_NAME
set +x
echo "Reconnecting..."
sleep 1
done
else
echo "Won't restream a source feed to the server because SOURCE_URL was not defined"
echo "Starting rtsp server. You can publish feeds to it (ex.: ffmpeg -i somesource.mjpg -c copy -f rtsp rtsp://localhost:8554/myfeed)"
rtsp-simple-server
fi
fi

0 comments on commit ce1d459

Please sign in to comment.