cccc/youtube.py

49 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/python3
import os
import json
import subprocess
2021-10-14 13:47:15 +00:00
config = {
2021-10-14 13:47:15 +00:00
'RTMP_URL': 'rtmp://a.rtmp.youtube.com/live2/{STREAM_KEY}',
2023-09-08 10:05:00 +00:00
'HLS_URL': 'https://a.upload.youtube.com/http_upload_hls?cid={STREAM_KEY}&copy=0&file=live.m3u8',
'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',
2021-10-14 13:47:15 +00:00
'-threads', '4',
'-i',
config['SRC'],
'-f', 'lavfi', '-i', 'anullsrc=channel_layout=stereo:sample_rate=44100',
'-map', '0:v',
'-map', '1:a',
]
2021-10-14 13:47:15 +00:00
if config.get('HLS'):
cmd += [
'-codec:a', 'aac',
'-b:a', '44100',
'-bufsize', '1024k',
'-c:v', 'copy',
'-f', 'hls', '-method', 'PUT', '-hls_time', '2', '-hls_list_size', '4',
'-reconnect', '1',
config['HLS_URL'].format(**config)
]
else:
cmd += [
'-codec:a', 'libmp3lame',
'-threads', '4',
'-b:a', '11025',
'-bufsize', '1024k',
'-fflags', '+genpts',
'-c:v', 'copy',
'-f', 'flv',
'-reconnect', '1',
config['RTMP_URL'].format(**config)
]
subprocess.check_output(cmd)