Skip to content

Commit

Permalink
pylivestream.camera
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 30, 2022
1 parent a9e03af commit edf0e80
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 34 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Both do the same thing.
* python -m pylivestream.screen
* python -m pylivestream.loopfile
* ScreenCapture2disk
* WebcamLivestream
* python -m pylivestream.camera
* python -m pylivestream.microphone
* `import pylivestream.api as pls` from within your Python script. For more information type `help(pls)` or `help(pls.stream_microphone)`
* pls.stream_file()
Expand Down Expand Up @@ -187,24 +187,24 @@ Due to the complexity of streaming and the non-specific error codes FFmpeg emits

* [pylivestream.ini](./src/pylivestream/pylivestream.ini) is setup for your computer and desired parameters
* `site` is `facebook`, `twitch`, `youtube`, etc.
* For `WebcamLivestream` and `pylivestream.screen`, more than one `site` can be specified for simultaneous multi-streaming
* For `pylivestream.camera` and `pylivestream.screen`, more than one `site` can be specified for simultaneous multi-streaming
* remember to setup a `*.key` file with the hexadecimal stream key for EACH site first, OR input the stream key into the "key:" field of your `*.ini` file.

[File-Streaming](./File-Streaming.md)

### Webcam

Note: your system may not have a webcam, particularly if it's a virtual machine.
Note: your system may not have a camera, particularly if it's a virtual machine.

Config:

* `webcam_res`: webcam resolution -- find from `v4l2-ctl --list-formats-ext` or webcam spec sheet.
* `webcam_fps`: webcam fps -- found from command above or webcam spec sheet
* `webcam_res`: camera resolution -- find from `v4l2-ctl --list-formats-ext` or camera spec sheet.
* `webcam_fps`: camea fps -- found from command above or camera spec sheet

Stream to multiple sites, in this example Facebook Live and YouTube Live simultaneously:

```sh
WebcamLivestream youtube facebook
python -m pylivestream.camera youtube facebook
```

### Screen Share Livestream
Expand Down
2 changes: 1 addition & 1 deletion Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Comments on dropouts / lag for livestreaming in general (not just with this prog
* Do Skype / Duo / FaceTime work excellently for you on your network? If not, live streaming will not work well.
* Try a wired (Ethernet) connection to the Internet. I have seen very expensive consumer WiFi APs that had bad performance in real world strenuous use (like live streaming).

## Blank desktop sharing video.
## Blank desktop sharing video

In general since this program generates command lines that are run by FFmpeg, try just using FFmpeg by itself to write to a video file.
This is a known issue with Wayland--instead use X11.
Expand Down
2 changes: 1 addition & 1 deletion archive/visual_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def main():
subprocess.check_call([sys.executable, "-m", "pylivestream.loopfile", "-y", str(VIDEO), HOST])
# %% Webcam
print("Webcam test - will fail if no webcam present on your system")
subprocess.check_call(["WebcamLivestream", "-y", HOST])
subprocess.check_call([sys.executable, "-m", "pylivestream.camera", "-y", HOST])


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[options.entry_points]
console_scripts =
ScreenCapture2disk = pylivestream.__main__:screencapture
WebcamLivestream = pylivestream.__main__:webcam
22 changes: 1 addition & 21 deletions src/pylivestream/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import signal
from argparse import ArgumentParser

from .api import (
capture_screen,
stream_webcam,
)
from .api import capture_screen


def screencapture():
Expand All @@ -18,20 +15,3 @@ def screencapture():
P = p.parse_args()

capture_screen(ini_file=P.ini, out_file=P.outfn, assume_yes=P.yes, timeout=P.timeout)


def webcam():
signal.signal(signal.SIGINT, signal.SIG_DFL)

p = ArgumentParser(description="livestream webcam")
p.add_argument(
"websites",
help="site to stream, e.g. localhost youtube periscope facebook twitch",
nargs="+",
)
p.add_argument("-i", "--ini", help="*.ini file with stream parameters")
p.add_argument("-y", "--yes", help="no confirmation dialog", action="store_true")
p.add_argument("-t", "--timeout", help="stop streaming after --timeout seconds", type=int)
P = p.parse_args()

stream_webcam(ini_file=P.ini, websites=P.websites, assume_yes=P.yes, timeout=P.timeout)
21 changes: 21 additions & 0 deletions src/pylivestream/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import signal
import argparse

from .api import stream_webcam


if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)

p = argparse.ArgumentParser(description="livestream webcam")
p.add_argument(
"websites",
help="site to stream, e.g. localhost youtube periscope facebook twitch",
nargs="+",
)
p.add_argument("-i", "--ini", help="*.ini file with stream parameters")
p.add_argument("-y", "--yes", help="no confirmation dialog", action="store_true")
p.add_argument("-t", "--timeout", help="stop streaming after --timeout seconds", type=int)
P = p.parse_args()

stream_webcam(ini_file=P.ini, websites=P.websites, assume_yes=P.yes, timeout=P.timeout)
2 changes: 1 addition & 1 deletion src/pylivestream/pylivestream.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ timelimit:
# vcap: dshow
# screenchan: video="UScreenCapture"
screenchan: desktop
webcamchan: video="Microsoft Camera Front"
webcamchan: video="Surface Camera Front"
# audiochan: audio="Internal Microphone"
# audiochan: audio="Microphone (Realtek High Definition Audio(SST))"
audiochan: audio="Microphone Array (Realtek High Definition Audio(SST))"
Expand Down
8 changes: 5 additions & 3 deletions src/pylivestream/tests/test_webcam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pylivestream as pls
import pytest
import sys
from pytest import approx
import subprocess
import os
Expand Down Expand Up @@ -28,15 +29,16 @@ def test_props(periscope_kbps):


@pytest.mark.timeout(TIMEOUT)
@pytest.mark.skipif(CI or WSL, reason="has no video hardware typically")
@pytest.mark.skipif(CI or WSL, reason="has no camera typically")
def test_stream():
S = pls.Webcam(inifn=None, websites="localhost", timeout=5, key="abc")

S.golive()


@pytest.mark.skipif(CI or WSL, reason="has no vidoe hardware typically")
@pytest.mark.skipif(CI or WSL, reason="has no camera typically")
def test_script():
subprocess.check_call(
["WebcamLivestream", "localhost", "--yes", "--timeout", "5"], timeout=TIMEOUT
[sys.executable, "-m", "pylivestream.camera", "localhost", "--yes", "--timeout", "5"],
timeout=TIMEOUT,
)

0 comments on commit edf0e80

Please sign in to comment.