-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Checklist
- This is a bug report and not a different kind of issue
- I have read the contribution guidelines
- I have checked the list of open and recently closed bug reports
- I have checked the commit log of the master branch
Collaboration
Streamlink version
7.0.0+31.gfac5d8f7
Description
The Issue
Hi! Recently I'm testing MPEG-DASH with streamlink. After encountering a bunch of HTTP 404 errors when downloading segments, I've started to read the code, and then fortunately I think I've found the solution.
My command lines:
$ ffmpeg -i test.mkv -c copy -f dash test.mpd
$ ffprobe test.mkv
ffprobe version n6.1.1-7-ga267d4ad4c-20240222 Copyright (c) 2007-2023 the FFmpeg developers
built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21)
configuration: ...
...
Input #0, matroska,webm, from 'test.mkv':
Metadata:
COMPATIBLE_BRANDS: isomiso2avc1mp41
MAJOR_BRAND : isom
MINOR_VERSION : 512
ENCODER : Lavf60.16.100
Duration: 00:05:00.17, start: 0.000000, bitrate: 1620 kb/s
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, 30 fps, 30 tbr, 1k tbn (default)
Metadata:
HANDLER_NAME : VideoHandler
VENDOR_ID : [0][0][0][0]
DURATION : 00:05:00.166000000
Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp (default)
Metadata:
HANDLER_NAME : SoundHandler
VENDOR_ID : [0][0][0][0]
DURATION : 00:05:00.019000000The MPD file:
the content of "test.mpd"
<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:mpeg:dash:schema:mpd:2011"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
profiles="urn:mpeg:dash:profile:isoff-live:2011"
type="static"
mediaPresentationDuration="PT5M0.1S"
maxSegmentDuration="PT5.0S"
minBufferTime="PT12.0S">
<ProgramInformation>
</ProgramInformation>
<ServiceDescription id="0">
</ServiceDescription>
<Period id="0" start="PT0.0S">
<AdaptationSet id="0" contentType="video" startWithSAP="1" segmentAlignment="true" bitstreamSwitching="true" frameRate="30/1" maxWidth="1920" maxHeight="1080" par="16:9">
<Representation id="0" mimeType="video/mp4" codecs="avc1.4d4029" bandwidth="1428902" width="1920" height="1080" sar="1:1">
<SegmentTemplate timescale="10000000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="60000000" r="26" />
<S d="59990000" />
<S d="60000000" r="21" />
<S d="1670000" />
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="audio" startWithSAP="1" segmentAlignment="true" bitstreamSwitching="true">
<Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" bandwidth="194151" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2" />
<SegmentTemplate timescale="44100" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
<SegmentTimeline>
<S t="750" d="221174" />
<S d="221184" r="57" />
<S d="180224" />
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
</Period>
</MPD>
My Solution
streamlink/src/streamlink/stream/dash/dash.py
Lines 256 to 260 in fac5d8f
| urlp = list(urlparse(url)) | |
| urlp[2], _ = urlp[2].rsplit("/", 1) | |
| base_url: str = urlunparse(urlp) | |
| return manifest, dict(url=url, base_url=base_url) |
- urlp[2], _ = urlp[2].rsplit("/", 1)
+ urlp[2] = urlp[2].rsplit("/", 1)[0] + "/"And also add a correspoding test:
def test_baseurl_urljoin(self):
with xml("dash/test_baseurl_urljoin.mpd") as mpd_xml:
mpd = MPD(mpd_xml, base_url="https://foo/bar", url="https://foo/bar/manifest.mpd")
# ... ^
# No trailing slash |
assert segment_urls == [
[
("empty-baseurl", "absolute-segments", "https://foo/absolute/init_video_5000kbps.m4s"),
("empty-baseurl", "absolute-segments", "https://foo/absolute/media_video_5000kbps-1.m4s"),
],
[
("empty-baseurl", "relative-segments", "https://foo/relative/init_video_5000kbps.m4s"),
("empty-baseurl", "relative-segments", "https://foo/relative/media_video_5000kbps-1.m4s"),END.
Debug log
$ python -m streamlink --loglevel debug http://127.0.0.1:8080/mpeg-dash-test/vod/test.mpd best
[cli][debug] OS: Windows 10
[cli][debug] Python: 3.11.9
[cli][debug] OpenSSL: OpenSSL 3.0.13 30 Jan 2024
[cli][debug] Streamlink: 7.0.0+31.gfac5d8f7
[cli][debug] Dependencies:
[cli][debug] certifi: 2024.6.2
[cli][debug] isodate: 0.6.1
[cli][debug] lxml: 4.9.4
[cli][debug] pycountry: 24.6.1
[cli][debug] pycryptodome: 3.20.0
[cli][debug] PySocks: 1.7.1
[cli][debug] requests: 2.32.3
[cli][debug] trio: 0.25.1
[cli][debug] trio-websocket: 0.11.1
[cli][debug] typing-extensions: 4.12.2
[cli][debug] urllib3: 2.2.1
[cli][debug] websocket-client: 1.8.0
[cli][debug] Arguments:
[cli][debug] url=http://127.0.0.1:8080/mpeg-dash-test/vod/test.mpd
[cli][debug] stream=['best']
[cli][debug] --loglevel=debug
[cli][info] Found matching plugin dash for URL http://127.0.0.1:8080/mpeg-dash-test/vod/test.mpd
[plugins.dash][debug] URL=http://127.0.0.1:8080/mpeg-dash-test/vod/test.mpd; params={}
[utils.l10n][debug] Language code: en_US
[stream.dash][debug] Available languages for DASH audio streams: NONE (using: n/a)
[cli][info] Available streams: 1080p (worst, best)
[cli][info] Opening stream: 1080p (dash)
[cli][info] Starting player: C:\Program Files\VideoLAN\VLC\vlc.exe
[stream.dash][debug] Opening DASH reader for: ('0', '0', '0') - video/mp4
[stream.dash][debug] Opening DASH reader for: ('0', '1', '1') - audio/mp4
[stream.ffmpegmux][debug] ffmpeg version n6.1.1-7-ga267d4ad4c-20240222 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 13.2.0 (crosstool-NG 1.25.0.232_c175b21)
configuration: ...
...
[stream.dash.manifest][debug] Generating segment timeline for static playlist: ('0', '0', '0')
[stream.dash][debug] video/mp4 segment initialization: downloading (1970-01-01T00:00:00.000000Z / 2024-12-14T14:13:11.643145Z)
[utils.named_pipe][info] Creating pipe streamlinkpipe-247056-1-9449
[utils.named_pipe][info] Creating pipe streamlinkpipe-247056-2-3498
[stream.dash.manifest][debug] Generating segment timeline for static playlist: ('0', '1', '1')
[stream.ffmpegmux][debug] ffmpeg command: B:\dev\ffmpeg-n6.1.1-7-ga267d4ad4c-win64-gpl-6.1\bin\ffmpeg.EXE -y -nostats -loglevel info -i \\.\pipe\streamlinkpipe-247056-1-9449 -i \\.\pipe\streamlinkpipe-247056-2-3498 -c:v copy -c:a copy -copyts -f matroska pipe:1
[stream.dash][debug] audio/mp4 segment initialization: downloading (1970-01-01T00:00:00.000000Z / 2024-12-14T14:13:11.648832Z)
[stream.ffmpegmux][debug] Starting copy to pipe: \\.\pipe\streamlinkpipe-247056-1-9449
[stream.ffmpegmux][debug] Starting copy to pipe: \\.\pipe\streamlinkpipe-247056-2-3498
[cli][debug] Pre-buffering 8192 bytes
[stream.dash][error] video/mp4 segment initialization: failed (Unable to open URL: http://127.0.0.1:8080/mpeg-dash-test/init-stream0.m4s (404 Client Error: Not Found for url: http://127.0.0.1:8080/mpeg-dash-test/init-stream0.m4s))
[stream.dash][debug] video/mp4 segment 1: downloading (1970-01-01T00:00:00.000000Z / 2024-12-14T14:13:13.762230Z)
[stream.dash][error] audio/mp4 segment initialization: failed (Unable to open URL: http://127.0.0.1:8080/mpeg-dash-test/init-stream1.m4s (404 Client Error: Not Found for url: http://127.0.0.1:8080/mpeg-dash-test/init-stream1.m4s))
[stream.dash][debug] audio/mp4 segment 1: downloading (1970-01-01T00:00:00.000000Z / 2024-12-14T14:13:13.768768Z)
[stream.dash][error] video/mp4 segment 1: failed (Unable to open URL: http://127.0.0.1:8080/mpeg-dash-test/chunk-stream0-00001.m4s (404 Client Error: Not Found for url: http://127.0.0.1:8080/mpeg-dash-test/chunk-stream0-00001.m4s))
[stream.dash][debug] video/mp4 segment 2: downloading (1970-01-01T00:00:00.000000Z / 2024-12-14T14:13:15.883276Z)
[stream.dash][error] audio/mp4 segment 1: failed (Unable to open URL: http://127.0.0.1:8080/mpeg-dash-test/chunk-stream1-00001.m4s (404 Client Error: Not Found for url: http://127.0.0.1:8080/mpeg-dash-test/chunk-stream1-00001.m4s))
...