-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ce1d459
Showing
11 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |