Skip to content

Commit

Permalink
Unify ffmpeg commands for stream and download
Browse files Browse the repository at this point in the history
Previously, two ffmpeg commands were executed if the download flag was
set. These two commands had hardcoded the same parameters. Further,
since at least for the input they had the same task, they unnecessarily
caused a lot of load. By unifying into one command with two outputs, the
load on my test system dropped noticeably.
  • Loading branch information
oxzi committed Feb 7, 2022
1 parent c80c6ad commit c79d5db
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from datetime import datetime
import time

downloadProcess = None
browser = None
selenium_timeout = 30
connect_timeout = 5
Expand Down Expand Up @@ -236,21 +235,38 @@ def stream_intro():
p = subprocess.call(ffmpeg_args)

def stream():
ffmpeg_stream = 'ffmpeg -thread_queue_size "%s" -f x11grab -draw_mouse 0 -s %s -i :%d -thread_queue_size "%s" -f pulse -i default -ac 2 %s -f flv -flvflags no_duration_filesize "%s"' % (
args.ffmpeg_input_thread_queue_size, args.resolution, 122, args.ffmpeg_input_thread_queue_size, args.ffmpeg_stream_options, args.target)
logging.debug('Preparing to execute %r' % ffmpeg_stream)
ffmpeg_args = shlex.split(ffmpeg_stream)
logging.info("streaming meeting...")
p = subprocess.call(ffmpeg_args)
ffmpeg_outputs = []

def download():
downloadFile = "/video/meeting-%s.mkv" % fileTimeStamp
ffmpeg_stream = 'ffmpeg -thread_queue_size "%s" -f x11grab -draw_mouse 0 -s %s -i :%d -thread_queue_size "%s" -f pulse -i default -ac 2 %s "%s"' % (
args.ffmpeg_input_thread_queue_size, args.resolution, 122, args.ffmpeg_input_thread_queue_size, args.ffmpeg_download_options, downloadFile)
logging.debug('Preparing to execute %r' % ffmpeg_stream)
ffmpeg_args = shlex.split(ffmpeg_stream)
logging.info("saving meeting as %s" % downloadFile)
return subprocess.Popen(ffmpeg_args)
if args.download:
downloadFile = "/video/meeting-%s.mkv" % fileTimeStamp
ffmpeg_outputs.extend(shlex.split(args.ffmpeg_download_options))
ffmpeg_outputs.append(downloadFile)
logging.info("saving meeting as %s" % downloadFile)

if args.stream:
ffmpeg_outputs.extend(shlex.split(args.ffmpeg_stream_options))
ffmpeg_outputs.extend([
"-f", "flv",
"-flvflags", "no_duration_filesize",
args.target,
])
logging.info("streaming meeting...")

ffmpeg_cmd = [
"ffmpeg",
"-thread_queue_size", str(args.ffmpeg_input_thread_queue_size),
"-f", "x11grab",
"-draw_mouse", "0",
"-s", args.resolution,
"-i", ":122",
"-thread_queue_size", str(args.ffmpeg_input_thread_queue_size),
"-f", "pulse",
"-i", "default",
"-ac", "2",
] + ffmpeg_outputs

logging.debug('Preparing to execute %r' % ffmpeg_cmd)
p = subprocess.call(ffmpeg_cmd)

if args.startMeeting is False:
while bbb.is_meeting_running(args.id).is_meeting_running() != True:
Expand All @@ -266,11 +282,6 @@ def download():
stream_intro()
if args.stream or args.download:
bbb_browser()
if args.download:
downloadProcess = download()
if args.stream:
stream()
if downloadProcess:
downloadProcess.communicate(input=None)
if browser:
browser.quit()

0 comments on commit c79d5db

Please sign in to comment.