本文最后更新于 450 天前,其中的信息可能已经有所发展或是发生改变。
教程网站买了会员还不让下载,索性自己爬了。
关于 MPD 这个流媒体传输格式的具体信息可以看这篇文章:自适应流媒体传输(四)——深入理解 MPD,本章只讲视频的爬取如何实现。
参考的 GitHub 项目:ugeshgupta000/downloadMpdStream
1、解析并下载所有视频片段
.mpd
格式的流媒体传输有个规律,即:第一个文件为 .mpd
格式,用来记录视频的信息,而之后视频的片段均为 .m4s
格式。
于是我们首先需要做的就是下载 .mpd
文件和解析它,下载不用多说了,直接在浏览器控制台搜索并下载即可:

打开之后是这样的:
<?xml version="1.0" ?>
<MPD mediaPresentationDuration="PT4H4M25.000S" minBufferTime="PT2.00S" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" xmlns="urn:mpeg:dash:schema:mpd:2011">
<!-- Created with Bento4 mp4-dash.py, VERSION=1.6.0-598 -->
<Period>
<!-- Audio -->
<AdaptationSet lang="en" mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1">
<SegmentTemplate initialization="$RepresentationID$/init.mp4" media="$RepresentationID$/seg-$Number$.m4f" startNumber="1" timescale="44100">
<SegmentTimeline>
<S d="88064" r="3"/>
<S d="80896"/>
<S d="88064" r="2"/>
...
...
<S d="89088"/>
<S d="88064" r="5"/>
</SegmentTimeline>
</SegmentTemplate>
<Representation audioSamplingRate="44100" bandwidth="130183" codecs="mp4a.40.2" id="audio/en">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
</Representation>
</AdaptationSet>
<!-- Video -->
<AdaptationSet mimeType="video/mp4" segmentAlignment="true" startWithSAP="1">
<SegmentTemplate initialization="$RepresentationID$/init.mp4" media="$RepresentationID$/seg-$Number$.m4f" startNumber="1" timescale="15360">
<SegmentTimeline>
<S d="88064" r="3"/>
<S d="80896"/>
<S d="88064" r="2"/>
...
...
<S d="89088"/>
<S d="88064" r="5"/>
</SegmentTimeline>
</SegmentTemplate>
<Representation bandwidth="1008805" codecs="avc1.64001F" frameRate="30" height="720" id="video/1" scanType="progressive" width="1280"/>
<Representation bandwidth="512402" codecs="avc1.64001F" frameRate="30" height="720" id="video/2" scanType="progressive" width="1280"/>
</AdaptationSet>
</Period>
</MPD>