chrippa / livestreamer

Command-line utility that extracts streams from various services and pipes them into a video player of choice. No longer maintained, use streamlink or youtube-dl instead.
http://livestreamer.io/
BSD 2-Clause "Simplified" License
3.88k stars 586 forks source link

Cannot start from systemd #1677

Closed GilDev closed 2 years ago

GilDev commented 4 years ago

Hi,

I’m using Livestreamer on a Raspberry Pi 4 running latest Raspbian. I have a stream, which only plays for 30s before crashing with omxplayer or VLC, not sure why as it works great on desktop VLC, here’s the log:

[cli][info] Found matching plugin dash for URL https://sarralbe.hdr-tv.com/live/sarralbe/sarralbe.stream/manifest_w901625138.mpd
[cli][info] Available streams: 1100k (worst, best)
[cli][info] Opening stream: 1100k (dash)
[cli][info] Creating pipe streamlinkpipe-744
[cli][info] Starting player: vlc
Exception in thread Thread-DASHStreamWorker:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1336, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 692, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.7/http/client.py", line 1336, in getresponse
    response.begin()
  File "/usr/lib/python3.7/http/client.py", line 306, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.7/http/client.py", line 275, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/streamlink/plugin/api/http_session.py", line 164, in request
    *args, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3/dist-packages/streamlink/stream/segmented.py", line 59, in run
    for segment in self.iter_segments():
  File "/usr/lib/python3/dist-packages/streamlink/stream/dash.py", line 97, in iter_segments
    if not self.reload():
  File "/usr/lib/python3/dist-packages/streamlink/stream/dash.py", line 111, in reload
    res = self.session.http.get(self.mpd.url, exception=StreamError)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3/dist-packages/streamlink/plugin/api/http_session.py", line 175, in request
    raise err
streamlink.exceptions.StreamError: Unable to open URL: https://sarralbe.hdr-tv.com/live/sarralbe/sarralbe.stream/manifest_w901625138.mpd (('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

error: Error when reading from stream: Read timeout, exiting
[cli][info] Stream ended
[cli][info] Closing currently open stream...

The other problem is that I made a systemd service:

[Unit]                                                                                                                 │  2  [|                                            0.7%]   Load average: 0.54 0.36 0.19
Description=Sarralbe's cygognes stream                                                                                 │  3  [|||||||||||||||||||||||||||||||||||||||     77.3%]   Uptime: 01:27:32
After=network.target                                                                                                   │  4  [                                             0.0%]
                                                                                                                       │  Mem[|||||||||||||                          139M/3.81G]
[Service]                                                                                                              │  Swp[                                        0K/100.0M]
ExecStart=/bin/bash stream.sh                                                                                          │
WorkingDirectory=/home/pi                                                                                              │  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
StandardOutput=inherit                                                                                                 │ 9053 pi         20   0 33492 24656  8752 S 77.1  0.6  0:01.16 /usr/bin/python3 /usr/bin/livestreamer https://sarralbe
StandardError=inherit                                                                                                  │ 2813 pi         20   0  8508  3304  2428 R  0.7  0.1  1:03.22 htop
Restart=always                                                                                                         │  321 messagebu  20   0  6560  2984  2708 S  0.7  0.1  0:00.69 /usr/bin/dbus-daemon --system --address=systemd: --nofo
User=pi                                                                                                                │  109 root       20   0 21236  8076  7220 S  0.0  0.2  0:01.53 /lib/systemd/systemd-journald
                                                                                                                       │    1 root       20   0 34756  8140  6432 S  0.0  0.2  0:05.28 /sbin/init
[Install]                                                                                                              │ 9035 root       20   0  8064  2888  2312 S  0.0  0.1  0:00.04 nano /etc/systemd/system/stream.service
WantedBy=multi-user.target

Here’s my stream.sh script:

#!/bin/bash

livestreamer https://sarralbe.hdr-tv.com/live/sarralbe/sarralbe.stream/manifest_w901625138.mpd best --player vlc --fifo

But now when I try to start my service (sudo systemctl start stream), it seems to start in a loop, nothing shows up on screen, there is high CPU usage and it’s creating a new process continuously. Here’s the output of sudo systemctl status stream (where often only “Started Sarralbe’s. cygognes stream.” shows up, because it seems to clear the log at each relaunch):

● stream.service - Sarralbe's cygognes stream
   Loaded: loaded (/etc/systemd/system/stream.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-03-18 02:18:04 CET; 3s ago
 Main PID: 10183 (bash)
    Tasks: 5 (limit: 4915)
   Memory: 21.6M
   CGroup: /system.slice/stream.service
           ├─10183 /bin/bash stream.sh
           └─10184 /usr/bin/python3 /usr/bin/livestreamer https://sarralbe.hdr-tv.com/live/sarralbe/sarralbe.stream/manifest_w901625138.mpd best --player vlc --fifo

Mar 18 02:18:04 raspberrypi systemd[1]: Started Sarralbe's cygognes stream.
Mar 18 02:18:05 raspberrypi bash[10183]: [cli][info] Found matching plugin dash for URL https://sarralbe.hdr-tv.com/live/sarralbe/sarralbe.stream/manifest_w901625138.mpd
Mar 18 02:18:07 raspberrypi bash[10183]: [cli][info] Available streams: 1100k (worst, best)
Mar 18 02:18:07 raspberrypi bash[10183]: [cli][info] Opening stream: 1100k (dash)
Mar 18 02:18:07 raspberrypi bash[10183]: [cli][info] Creating pipe streamlinkpipe-10184
Mar 18 02:18:07 raspberrypi bash[10183]: [cli][info] Starting player: vlc
Mar 18 02:18:08 raspberrypi bash[10183]: error: Failed to start player: vlc (Process exited prematurely)
Mar 18 02:18:08 raspberrypi bash[10183]: [cli][info] Closing currently open stream...

Any idea why this is happening? Thanks!

cdrage commented 4 years ago

Use https://github.com/streamlink/streamlink/

bachoo786 commented 2 years ago

@GilDev hey there did you manage to resolve this? I use streamlink and have similar issues as you.

GilDev commented 2 years ago

No, I think I used streamline in the end as suggested by @cdrage, which is in active development. Livestream is no longer maintained.