simplify output, remove metadata, add preview stream

This commit is contained in:
jb-alvarado 2022-01-27 21:57:43 +01:00
parent c620307d00
commit 5852267a39
7 changed files with 83 additions and 52 deletions

View File

@ -78,7 +78,7 @@ so the input for the final compression is unique.
- with `logo_filter = overlay=W-w-12:12` you can modify the logo position
- with `use_loudnorm` you can activate single pass EBU R128 loudness normalization
- `loud_*` can adjust the loudnorm filter
- `output_count` sets the outputs for the filtering, > 1 gives the option to use the same filters for multiple outputs. This outputs can be taken in 'ffmpeg_param', names will be vout2, vout3;
- `output_count` sets the outputs for the filtering, > 1 gives the option to use the same filters for multiple outputs. This outputs can be taken in 'stream_param', names will be vout2, vout3;
aout2, aout2 etc.
**INFO:** output is progressive!
@ -161,9 +161,23 @@ With `regex` you can format file names, to get a title from it.
```YAML
out:
mode: 'stream'
service_name: "Live Stream"
service_provider: "example.org"
ffmpeg_param: >-
preview: False
preview_param: >-
-s 512+288
-c:v libx264
-crf 24
-x264-params keyint=50:min-keyint=25:scenecut=-1
-maxrate 800k
-bufsize 1600k
-preset ultrafast
-profile:v Main
-level 3.1
-c:a aac
-ar 44100
-b:a 128k
-flags +global_header
-f flv rtmp://preview.local/live/stream
stream_param: >-
-c:v libx264
-crf 23
-x264-params keyint=50:min-keyint=25:scenecut=-1
@ -175,7 +189,6 @@ out:
-c:a aac
-ar 44100
-b:a 128k
stream_output: >-
-flags +global_header
-f flv rtmp://localhost/live/stream
```
@ -183,11 +196,12 @@ out:
The final ffmpeg post compression, Set the settings to your needs!
`mode` has the standard options **desktop**, **hls**, **live_switch**, **stream**. Self made outputs
can be define, by adding script in output folder with an **output()** function inside.
'preview' works only in streaming output and creates a separate preview stream.
For output mode hls, `stream_output` can look like:
For output mode hls, output can look like:
```YAML
stream_output: >-
[...]
-flags +cgop
-f hls
-hls_time 6

View File

@ -40,7 +40,7 @@ processing:
With 'use_loudnorm' you can activate single pass EBU R128 loudness normalization.
'loud_*' can adjust the loudnorm filter. 'output_count' sets the outputs for
the filtering, > 1 gives the option to use the same filters for multiple outputs.
This outputs can be taken in 'ffmpeg_param', names will be vout2, vout3;
This outputs can be taken in 'stream_param', names will be vout2, vout3;
aout2, aout2 etc.
width: 1024
height: 576
@ -113,11 +113,25 @@ out:
helptext: The final playout compression. Set the settings to your needs.
'mode' has the standard options 'desktop', 'hls', 'live_switch', 'stream'. Self made
outputs can be define, by adding script in output folder with an 'output' function
inside. 'stream_output' represent the file encoding output.
inside. 'preview' works only in streaming output and creates a separate preview stream.
mode: 'stream'
service_name: "Live Stream"
service_provider: "example.org"
ffmpeg_param: >-
preview: False
preview_param: >-
-s 512+288
-c:v libx264
-crf 24
-x264-params keyint=50:min-keyint=25:scenecut=-1
-maxrate 800k
-bufsize 1600k
-preset ultrafast
-profile:v Main
-level 3.1
-c:a aac
-ar 44100
-b:a 128k
-flags +global_header
-f flv rtmp://preview.local/live/stream
stream_param: >-
-c:v libx264
-crf 23
-x264-params keyint=50:min-keyint=25:scenecut=-1
@ -129,6 +143,5 @@ out:
-c:a aac
-ar 44100
-b:a 128k
stream_output: >-
-flags +global_header
-f flv rtmp://localhost/live/stream

View File

@ -38,8 +38,8 @@ from pathlib import Path
from subprocess import PIPE, Popen
from threading import Thread
from ..utils import (ff_proc, ffmpeg_stderr_reader, get_date, log, messenger,
play, playout, sync_op, terminate_processes)
from ..utils import (ff_proc, ffmpeg_stderr_reader, log, messenger, play,
playout, sync_op, terminate_processes)
def clean_ts():
@ -74,7 +74,6 @@ def output():
"""
this output is hls output, no pre-process is needed.
"""
year = get_date(False).split('-')[0]
sync_op.realtime = True
try:
@ -88,11 +87,7 @@ def output():
cmd = [
'ffmpeg', '-v', f'level+{log.ff_level.lower()}',
'-hide_banner', '-nostats'
] + node['src_cmd'] + node['filter'] + [
'-metadata', f'service_name={playout.name}',
'-metadata', f'service_provider={playout.provider}',
'-metadata', f'year={year}'
] + playout.ffmpeg_param + playout.stream_output
] + node['src_cmd'] + node['filter'] + playout.stream_param
messenger.debug(f'Encoder CMD: "{" ".join(cmd)}"')

View File

@ -25,8 +25,8 @@ from threading import Thread
from time import sleep
from ..filters.default import overlay_filter
from ..utils import (ff_proc, ffmpeg_stderr_reader, get_date, get_time, ingest,
log, lower_third, messenger, play, playout, pre,
from ..utils import (ff_proc, ffmpeg_stderr_reader, get_time, ingest, log,
lower_third, messenger, play, playout, pre,
pre_audio_codec, sync_op, terminate_processes)
COPY_BUFSIZE = 1024 * 1024 if system() == 'Windows' else 65424
@ -80,13 +80,19 @@ def output():
this output is for streaming to a target address,
like rtmp, rtp, svt, etc.
"""
year = get_date(False).split('-')[0]
overlay = []
filtering = []
node = None
dec_cmd = []
split_filter = ''
preview = []
live_on = False
streaming_queue = Queue(maxsize=0)
if playout.preview:
split_filter = ',split=2[v_out1][v_out2]'
preview = ['-map', '[v_out1]', '-map', '0:a'
] + playout.preview_param + ['-map', '[v_out2]', '-map', '0:a']
ff_pre_settings = [
'-pix_fmt', 'yuv420p', '-r', str(pre.fps),
'-c:v', 'mpeg2video', '-g', '1',
@ -100,11 +106,14 @@ def output():
messenger.info(
f'Using drawtext node, listening on address: {lower_third.address}'
)
overlay = [
'-vf',
"null,zmq=b=tcp\\\\://'{}',drawtext=text='':fontfile='{}'".format(
lower_third.address.replace(':', '\\:'), lower_third.fontfile)
filtering = [
'-filter_complex',
f"[0:v]null,zmq=b=tcp\\\\://'{lower_third.address}',"
+ f"drawtext=text='':fontfile='{lower_third.fontfile}'"
+ split_filter
]
elif playout.preview:
filtering = ['-filter_complex', '[0:v]split=2[v_out1][v_out2]']
rtmp_server_thread = Thread(name='ffmpeg_server',target=rtmp_server,
args=(streaming_queue, ff_pre_settings))
@ -115,11 +124,7 @@ def output():
enc_cmd = [
'ffmpeg', '-v', f'level+{log.ff_level.lower()}', '-hide_banner',
'-nostats', '-re', '-thread_queue_size', '160', '-i', 'pipe:0'
] + overlay + [
'-metadata', f'service_name={playout.name}',
'-metadata', f'service_provider={playout.provider}',
'-metadata', f'year={year}'
] + playout.ffmpeg_param + playout.stream_output
] + filtering + preview + playout.stream_param
messenger.debug(f'Encoder CMD: "{" ".join(enc_cmd)}"')

View File

@ -51,7 +51,7 @@ def output():
enc_cmd = [
'ffmpeg', '-v', f'level+{log.ff_level.lower()}', '-hide_banner',
'-nostats', '-re', '-thread_queue_size', '160', '-i', 'pipe:0'
] + playout.ffmpeg_param + ['-f', 'null', '-']
] + playout.stream_param[:-3] + ['-f', 'null', '-']
messenger.debug(f'Encoder CMD: "{" ".join(enc_cmd)}"')

View File

@ -24,7 +24,7 @@ from platform import system
from subprocess import PIPE, Popen
from threading import Thread
from ..utils import (ff_proc, ffmpeg_stderr_reader, get_date, log, lower_third,
from ..utils import (ff_proc, ffmpeg_stderr_reader, log, lower_third,
messenger, play, playout, pre, pre_audio_codec, sync_op,
terminate_processes)
@ -36,10 +36,16 @@ def output():
this output is for streaming to a target address,
like rtmp, rtp, svt, etc.
"""
year = get_date(False).split('-')[0]
overlay = []
filtering = []
node = None
dec_cmd = []
split_filter = ''
preview = []
if playout.preview:
split_filter = ',split=2[v_out1][v_out2]'
preview = ['-map', '[v_out1]', '-map', '0:a'
] + playout.preview_param + ['-map', '[v_out2]', '-map', '0:a']
ff_pre_settings = [
'-pix_fmt', 'yuv420p', '-r', str(pre.fps),
@ -54,21 +60,20 @@ def output():
messenger.info(
f'Using drawtext node, listening on address: {lower_third.address}'
)
overlay = [
'-vf',
"null,zmq=b=tcp\\\\://'{}',drawtext=text='':fontfile='{}'".format(
lower_third.address.replace(':', '\\:'), lower_third.fontfile)
filtering = [
'-filter_complex',
f"[0:v]null,zmq=b=tcp\\\\://'{lower_third.address}',"
+ f"drawtext=text='':fontfile='{lower_third.fontfile}'"
+ split_filter
]
elif playout.preview:
filtering = ['-filter_complex', '[0:v]split=2[v_out1][v_out2]']
try:
enc_cmd = [
'ffmpeg', '-v', f'level+{log.ff_level.lower()}', '-hide_banner',
'-nostats', '-re', '-thread_queue_size', '160', '-i', 'pipe:0'
] + overlay + [
'-metadata', f'service_name={playout.name}',
'-metadata', f'service_provider={playout.provider}',
'-metadata', f'year={year}'
] + playout.ffmpeg_param + playout.stream_output
] + filtering + preview + playout.stream_param
messenger.debug(f'Encoder CMD: "{" ".join(enc_cmd)}"')

View File

@ -235,7 +235,7 @@ def load_config():
lower_third.add_text = cfg['text']['add_text']
lower_third.over_pre = cfg['text']['over_pre']
lower_third.address = cfg['text']['bind_address']
lower_third.address = cfg['text']['bind_address'].replace(':', '\\:')
lower_third.fontfile = cfg['text']['fontfile']
lower_third.text_from_filename = cfg['text']['text_from_filename']
lower_third.style = cfg['text']['style']
@ -289,10 +289,9 @@ if stdin_args.output:
else:
playout.mode = _cfg['out']['mode']
playout.name = _cfg['out']['service_name']
playout.provider = _cfg['out']['service_provider']
playout.ffmpeg_param = shlex.split(_cfg['out']['ffmpeg_param'])
playout.stream_output = shlex.split(_cfg['out']['stream_output'])
playout.preview = _cfg['out']['preview']
playout.preview_param = shlex.split(_cfg['out']['preview_param'])
playout.stream_param = shlex.split(_cfg['out']['stream_param'])
# ------------------------------------------------------------------------------