Skip to content

Commit

Permalink
Tweak RTMP and add RestreamIO #1333
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Aug 28, 2024
1 parent a8c888b commit 9c55531
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
11 changes: 8 additions & 3 deletions app/wyzebridge/bridge_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

from wyzecam.api_models import WyzeCamera

LIVESTREAM_PLATFORMS = {
"YouTube": "rtmp://a.rtmp.youtube.com/live2/",
"Facebook": "rtmps://live-api-s.facebook.com:443/rtmp/",
"RestreamIO": "rtmp://live.restream.io/live",
"Livestream": "",
}


def env_cam(env: str, uri: str, default="", style="") -> str:
return env_bool(
Expand Down Expand Up @@ -61,9 +68,7 @@ def split_int_str(env_value: str, min: int = 0, default: int = 0) -> tuple[str,


def is_livestream(uri: str) -> bool:
services = {"youtube", "facebook", "livestream"}

return any(env_bool(f"{service}_{uri}") for service in services)
return any(env_bool(f"{service}_{uri}") for service in LIVESTREAM_PLATFORMS)


def migrate_path(old: str, new: str):
Expand Down
29 changes: 9 additions & 20 deletions app/wyzebridge/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Optional

from wyzebridge.bridge_utils import env_bool, env_cam
from wyzebridge.bridge_utils import LIVESTREAM_PLATFORMS, env_bool, env_cam
from wyzebridge.config import IMG_PATH, SNAPSHOT_FORMAT
from wyzebridge.logging import logger

Expand Down Expand Up @@ -158,27 +158,16 @@ def re_encode_video(uri: str, is_vertical: bool) -> list[str]:


def get_livestream_cmd(uri: str) -> str:
"""
Check if livestream is enabled and return ffmpeg tee cmd.

Parameters:
- uri (str): uri of the stream used to lookup ENV parameters.
flv = "|[f=flv:flvflags=no_duration_filesize:use_fifo=1:fifo_options=attempt_recovery=1\\\:drop_pkts_on_overflow=1\\\:recover_any_error=1]"

Returns:
- str: ffmpeg compatible str to be used for the tee command.
"""
cmd = ""
flv = "|[f=flv:flvflags=no_duration_filesize:use_fifo=1]"
if len(key := env_bool(f"YOUTUBE_{uri}", style="original")) > 5:
logger.info("📺 YouTube livestream enabled")
cmd += f"{flv}rtmp://a.rtmp.youtube.com/live2/{key}"
if len(key := env_bool(f"FACEBOOK_{uri}", style="original")) > 5:
logger.info("📺 Facebook livestream enabled")
cmd += f"{flv}rtmps://live-api-s.facebook.com:443/rtmp/{key}"
if len(key := env_bool(f"LIVESTREAM_{uri}", style="original")) > 5:
logger.info(f"📺 Custom ({key}) livestream enabled")
cmd += f"{flv}{key}"
return cmd
for platform, api in LIVESTREAM_PLATFORMS.items():
key = env_bool(f"{platform}_{uri}", style="original")
if len(key) > 5:
logger.info(f"📺 Livestream to {platform if api else key} enabled")
return f"{flv}{api}{key}"

return ""


def purge_old(base_path: str, extension: str, keep_time: Optional[timedelta]):
Expand Down

0 comments on commit 9c55531

Please sign in to comment.