From 9f548680ea1bbabbaf2291af5c7168d22eb40bcf Mon Sep 17 00:00:00 2001 From: j Date: Mon, 11 Oct 2021 16:06:55 +0100 Subject: [PATCH] add youtube restreaming, add systemd service files --- etc/systemd/system/cccc-youtube.service | 13 ++++++++++ etc/systemd/system/cccc.service | 14 +++++++++++ youtube.py | 32 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 etc/systemd/system/cccc-youtube.service create mode 100644 etc/systemd/system/cccc.service create mode 100755 youtube.py diff --git a/etc/systemd/system/cccc-youtube.service b/etc/systemd/system/cccc-youtube.service new file mode 100644 index 0000000..3322a34 --- /dev/null +++ b/etc/systemd/system/cccc-youtube.service @@ -0,0 +1,13 @@ +[Unit] +Description=cccc youtube restream + +[Service] +Type=simple +Restart=always +User=cccc +Group=cccc +WorkingDirectory=/opt/cccc +ExecStart=/opt/cccc/youtube.py + +[Install] +WantedBy=multi-user.target diff --git a/etc/systemd/system/cccc.service b/etc/systemd/system/cccc.service new file mode 100644 index 0000000..02d0116 --- /dev/null +++ b/etc/systemd/system/cccc.service @@ -0,0 +1,14 @@ +[Unit] +Description=cccc server + +[Service] +Type=simple +Restart=always +User=cccc +Group=cccc +WorkingDirectory=/opt/cccc +ExecStart=/opt/cccc/server.py +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/youtube.py b/youtube.py new file mode 100755 index 0000000..3b565aa --- /dev/null +++ b/youtube.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 +import os +import json +import subprocess + +config = { + 'RTMP_URL': "rtmp://a.rtmp.youtube.com/live2", + 'SRC': 'rtsp://192.168.1.64:554/Streaming/channels/103', + 'STREAM_KEY': 'not-set' +} +with open('youtube.json') as fd: + config.update(json.load(fd)) + +cmd = [ + 'ffmpeg', + '-hide_banner', + '-i', + config['SRC'], + '-f', 'lavfi', '-i', 'anullsrc=channel_layout=stereo:sample_rate=44100', + '-map', '0:v', + '-map', '1:a', + '-codec:a', 'libmp3lame', + '-threads', '4', + '-b:a', '11025', + '-bufsize', '1024k', + '-fflags', '+genpts', + '-c:v', 'copy', + '-f', 'flv', + '-reconnect', '1', + '{RTMP_URL}/{STREAM_KEY}'.format(**config) +] +subprocess.check_output(cmd)