initial commit

This commit is contained in:
Gregory Lirent 2024-04-19 14:19:18 +03:00
commit 869a18fe9f
Signed by: lirent
GPG Key ID: F616BE337EFFEE77
6 changed files with 198 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.ipaddr

20
bin/h264-retranslate Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
LOCAL_IP="$(cat $(readlink -f $(dirname $(dirname $0)))/.ipaddr)"
/usr/bin/ffmpeg -v quiet -rtbufsize 100m -listen 1 \
-f flv -i "rtmp://${LOCAL_IP}:$1/live/mystream" \
-an -c:v copy -preset ultrafast -tune zerolatency \
-f rtsp "rtsp://${LOCAL_IP}/$1" &
while true; do
FAIL=0
/usr/bin/ffprobe -v quiet "rtsp://${LOCAL_IP}/$1" || FAIL=1
if [[ $FAIL -eq 0 ]]; then
/usr/bin/systemd-notify WATCHDOG=1
fi
sleep $(( $WATCHDOG_USEC / 2 / 1000000 ))
done

36
install.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
WORK_DIR="$(readlink -f $(dirname $0))"
CERT_DIR="/usr/local/share/mediamtx/certs"
echo Please input the local ip of this machine, where video services would be started && read LOCAL_IP
echo "${LOCAL_IP}" > "${WORK_DIR}/.ipaddr"
mkdir -p /var/lib/mediamtx
mkdir -p "${CERT_DIR}"
ln -s "$WORK_DIR/mediamtx.yml" /etc
ln -s "$WORK_DIR/bin/h264-retranslate" /usr/local/bin
ln -s "$WORK_DIR/system/h264-node@.service" /etc/systemd/system
ln -s "$WORK_DIR/system/mediamtx.service" /etc/systemd/system
openssl req -x509 -nodes -days 3650 \
-newkey rsa:2048 \
-keyout "${CERT_DIR}/mediamtx.key" \
-out "${CERT_DIR}/mediamtx.crt" \
-subj "/C=RU/ST=0/L=0/O=0/OU=0/CN=0"
systemctl enable mediamtx.service
systemctl start mediamtx.service
#systemctl enable h264-node@1000
#systemctl enable h264-node@1001
#systemctl enable h264-node@1002
#systemctl enable h264-node@1003
#systemctl enable h264-node@1004
#systemctl start h264-node@1000
#systemctl start h264-node@1001
#systemctl start h264-node@1002
#systemctl start h264-node@1003
#systemctl start h264-node@1004

108
mediamtx.yml Normal file
View File

@ -0,0 +1,108 @@
logLevel: warn
logDestinations: [stdout]
readTimeout: 10s
writeTimeout: 10s
writeQueueSize: 512
udpMaxPayloadSize: 1472
externalAuthenticationURL:
authMethods: [basic]
authHTTPExclude:
- action: api
- action: metrics
- action: pprof
playback: no
api: yes
metrics: yes
pprof: no
playbackAddress: 0.0.0.0:9996
apiAddress: 0.0.0.0:9997
metricsAddress: 0.0.0.0:9998
pprofAddress: 0.0.0.0:9999
runOnConnect:
runOnConnectRestart: no
runOnDisconnect:
rtsp: yes
protocols: [udp, multicast, tcp]
encryption: "no"
rtspAddress: 0.0.0.0:554
rtspsAddress: 0.0.0.0:322
rtpAddress: 0.0.0.0:8000
rtcpAddress: 0.0.0.0:8001
multicastIPRange: 224.0.0.0/16
multicastRTPPort: 8002
multicastRTCPPort: 8003
serverKey: /usr/local/share/mediamtx/certs/mediamtx.key
serverCert: /usr/local/share/mediamtx/certs/mediamtx.crt
rtmp: yes
rtmpAddress: 0.0.0.0:1935
rtmpEncryption: "no"
rtmpsAddress: :1936
rtmpServerKey: /usr/local/share/mediamtx/certs/mediamtx.key
rtmpServerCert: /usr/local/share/mediamtx/certs/mediamtx.crt
hls: no
webrtc: no
srt: no
pathDefaults:
source: publisher
sourceFingerprint:
sourceOnDemand: no
maxReaders: 0
srtReadPassphrase:
fallback:
record: yes
playback: yes
recordPath: /var/lib/mediamtx/records/%path/%Y-%m-%d_%H-%M-%S-%f
recordFormat: fmp4
recordPartDuration: 100ms
recordSegmentDuration: 24h
recordDeleteAfter: 0s
publishUser:
publishPass:
publishIPs: []
readUser:
readPass:
readIPs: []
overridePublisher: yes
srtPublishPassphrase:
runOnInit:
runOnInitRestart: no
runOnDemand:
runOnDemandRestart: no
runOnDemandStartTimeout: 10s
runOnDemandCloseAfter: 10s
runOnUnDemand:
runOnReady:
runOnReadyRestart: no
runOnNotReady:
runOnRead:
runOnReadRestart: no
runOnUnread:
runOnRecordSegmentCreate:
runOnRecordSegmentComplete:
paths:
all_others:

14
system/h264-node@.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Retranslation of the RTMP stream '%I'
After=mediamtx.service
[Service]
Type=simple
NotifyAccess=all
WatchdogSec=30
Restart=always
ExecStart=/usr/local/bin/h264-retranslate %i
SuccessExitStatus=255
[Install]
WantedBy=multi-user.target

19
system/mediamtx.service Normal file
View File

@ -0,0 +1,19 @@
[Unit]
Description=MediaMTX
Requires=docker.service
After=docker.service
[Service]
TimeoutStartSec=0
Restart=on-failure
ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull bluenviron/mediamtx:latest
ExecStart=/usr/bin/docker run --rm --name %n --network=host \
-e TZ=Europe/Moscow \
-v /etc/mediamtx.yml:/mediamtx.yml \
-v /var/lib/mediamtx:/var/lib/mediamtx \
bluenviron/mediamtx:latest
[Install]
WantedBy=multi-user.target