From ce1d459da903fbf79b145b7a5077f5951d82756a Mon Sep 17 00:00:00 2001 From: cedricve Date: Thu, 7 Oct 2021 10:44:43 +0200 Subject: [PATCH] init --- .DS_Store | Bin 0 -> 8196 bytes .idea/.gitignore | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ .idea/virtual-rtsp.iml | 9 +++++++++ Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++ LICENSE | 21 ++++++++++++++++++++ README.md | 35 +++++++++++++++++++++++++++++++++ proxy.yml | 15 ++++++++++++++ samples/.DS_Store | Bin 0 -> 6148 bytes start-relay.sh | 36 ++++++++++++++++++++++++++++++++++ 11 files changed, 181 insertions(+) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/virtual-rtsp.iml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 proxy.yml create mode 100644 samples/.DS_Store create mode 100755 start-relay.sh diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..67a798c9d86f41cbe42c68980d107a1b12c9fda8 GIT binary patch literal 8196 zcmeHMNo*WN6#c*LBvp12w~b>vG=m2mN5OFt$IiZvwO!v$r zF^&uuKoGVYJ6w?95ODy3I3Tec2qJ(WVo^9C1e}n#aL9$_S67b}+p!c0iACv>s($^g z+W+_aRa0#Mz_zTh5ugSD7Y)O z5M?0BK$L+f1OJ5#(3ve7Tj1Q6+Gvb25M|)H%z)S*;?xCAgmhZcVC$eExB?IrSAd|= zobCaEPducFkWNb)xYC;P_JE-)hF1)f?xc?kbE1imPD?7?0i`=&_+$)kC>T7Q{NjN* zU_#Ppj4}{qV15Qf`78ksbQp(;EAQ`aiZtg_6Sn2~O-)~;QdGQX@e;;LSjn=IyOU#X zKI!Xz)@#!V?yk}CQ>Q2In>zEf zj10rw0m|k?`po<=Z7x)vD^6l{aeIT_pHH4M|B2x_XTRjo@q$kZ>`us5b>%Jy7b|rdmha9elR~Ll zPR=4s(>svRW_5`MiK8H+b%`d)Rn7sIIJ;ItBkX~FFbrvMAP%l zM=^zIv@nAnW-*6n@IibCAI7KfS$qy(z!&ixzJ>4M`}hHVf*0^J{2VXgkN6Y*jF%Nu z6s1V1QmU1>Qm?F+5h#Un8JZoDvX}Tdy8@L9ebp1?qS#j}mssb%{RjS)a`|?tD3J1s z8!A`aT(@Rj^Ol`^XJ8~zR{+|T01hxa3+Vx7gEu`FZ?ckjtdBr#o?NJ))Fq<$*hOJo z8|N`~5y4)vtLlkeOpurCZ4I%Qs!*j#cKwDJSBt2Qc;MU8KrDvL)@_`t#Z*yJw@V`y zLMG8l%ZU15e;=tY!)x$5ybT``Qon*r@ICwrm*EdACS+D&4WaWUj1fB5U<0njM%;{B zaXaoHtaji&Jb+zzJ0`IY2XGLF2&o2|cnn=UL1^^}uV-)?@5cx55j=~J;}iH~fZLbw z)j3G)nvFz!XFd{h$&6#W&T-Nd@H^Wn;;t#?H~UT5dMIT R&i`4zRHO4hK;!i@`~_*MB+38) literal 0 HcmV?d00001 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c321dcc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/virtual-rtsp.iml b/.idea/virtual-rtsp.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/virtual-rtsp.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6bdb008 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..823aca3 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3452feb --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/proxy.yml b/proxy.yml new file mode 100644 index 0000000..8b68211 --- /dev/null +++ b/proxy.yml @@ -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 diff --git a/samples/.DS_Store b/samples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 /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