Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 566a2cc

Browse files
committed
audioOut: enable parts specified
fixes #107
1 parent b886027 commit 566a2cc

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

.github/workflows/ci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: ci
22

3-
env:
4-
HOMEBREW_NO_INSTALL_CLEANUP: 1
5-
63
on:
74
push:
85
paths:
@@ -45,6 +42,8 @@ jobs:
4542
- name: install prereqs (macOS)
4643
if : runner.os == 'macOS'
4744
run: brew install ffmpeg
45+
env:
46+
HOMEBREW_NO_INSTALL_CLEANUP: 1
4847

4948
- name: Install winget
5049
if: runner.os == 'Windows'

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ JSON:
205205
* `camera_size`: camera resolution -- find from `v4l2-ctl --list-formats-ext` or camera spec sheet.
206206
* `camera_fps`: camera fps -- found from command above or camera spec sheet
207207

208-
Stream to multiple sites, in this example Facebook Live and YouTube Live simultaneously:
208+
Stream to multiple sites. This uses FFmpeg
209+
[-f tee](https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs#Teepseudo-muxer).
210+
For example, Facebook Live and YouTube Live simultaneously:
209211

210212
```sh
211213
python -m pylivestream.camera youtube facebook ./pylivestream.json

src/pylivestream/base.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ def startlive(self, sinks: list[str] | None = None):
103103
run(self.cmd)
104104
elif len(sinks) == 1:
105105
run(self.cmd)
106-
else: # multi-stream output tee
106+
else:
107+
"""
108+
multi-stream output tee
109+
https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs#Teepseudo-muxer
110+
https://trac.ffmpeg.org/wiki/EncodingForStreamingSites#Outputtingtomultiplestreamingserviceslocalfile
111+
"""
107112
cmdstem: list[str] = self.cmd[:-3]
108113
# +global_header is necessary to tee to multiple services
109114
cmd: list[str] = cmdstem + ["-flags:v", "+global_header", "-f", "tee"]
@@ -115,7 +120,8 @@ def startlive(self, sinks: list[str] | None = None):
115120
if self.vidsource == "file":
116121
# picks first video and audio stream, often correct
117122
cmd += ["-map", "0:v", "-map", "0:a:0"]
118-
else: # device (Camera)
123+
else:
124+
# device (Camera)
119125
# connect video device to video stream,
120126
# audio device to audio stream
121127
cmd += ["-map", "0:v", "-map", "1:a"]

src/pylivestream/ffmpeg.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self):
2121
# default 8, increasing can help avoid warnings
2222
self.QUEUE = ["-thread_queue_size", "8"]
2323

24+
# https://trac.ffmpeg.org/wiki/StreamingGuide#The-reflag
2425
self.THROTTLE = "-re"
2526

2627
def timelimit(self, t: str | int | float | None) -> list[str]:

src/pylivestream/stream.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,16 @@ def audioOut(self) -> list[str]:
212212
https://www.facebook.com/facebookmedia/get-started/live
213213
"""
214214

215-
if not (self.audio_bps and self.acap and self.audio_chan and self.audio_rate):
216-
return []
215+
o = []
216+
217+
if self.audio_codec:
218+
o += ["-codec:a", self.audio_codec]
219+
if self.audio_bps:
220+
o += ["-b:a", str(self.audio_bps)]
221+
if self.audio_rate:
222+
o += ["-ar", str(self.audio_rate)]
217223

218-
return [
219-
"-codec:a",
220-
self.audio_codec,
221-
"-b:a",
222-
str(self.audio_bps),
223-
"-ar",
224-
str(self.audio_rate),
225-
]
224+
return o
226225

227226
def video_bitrate(self) -> None:
228227
"""

0 commit comments

Comments
 (0)