修改
我的问题现在已经解决了(见下文),每个人都可以使用这个脚本下载m3u8流,如Apple的bipbop
ORIG问题
我创建了这个很好的脚本来下载Apple的BipBop示例HLS流。但是我没能玩它。如果您帮我解决了这个问题,我们都可以享受这个脚本:
#!/bin/bash
unset PROMPT_COMMAND
set -x
URL=https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8
MANIFESTNAME=$(basename $URL)
LOCAL_MANIFEST=$MANIFESTNAME
URLPREF=$(dirname $URL)
wget $URL -O $LOCAL_MANIFEST
cat $LOCAL_MANIFEST | grep "#EXT-X-STREAM-INF:" -A1 | grep m3u8 > all_playlists.txt
cat $LOCAL_MANIFEST | grep "#EXT-X-MEDIA.*URI" | sed -e 's_.*URI=\"\(.*\)\".*_\1_' >> all_playlists.txt
#this will yield files which we already downloaded, but we want the index file itself
cat $LOCAL_MANIFEST | grep "#EXT-X-I-FRAME-STREAM-INF.*URI" | sed -e 's_.*URI=\"\(.*\)\".*_\1_' >> all_playlists.txt
while read playList; do
FOLDER=$(dirname $playList)
PL_NAME=$(basename $playList)
LOCAL_PL=$FOLDER/$PL_NAME
mkdir -p $FOLDER 2> /dev/null
PL_URL=$URLPREF/$playList
echo "PL_URL=$PL_URL"
TSL=${FOLDER}_TSList.txt
wget $PL_URL -O $LOCAL_PL
echo "LOCAL_PL=$LOCAL_PL"
cat $LOCAL_PL | grep -v "^#" | uniq > $TSL
echo "====== media list ======="
cat $TSL
echo "========================="
#TS is actually any media file
while read ts; do
TS_NAME=$URLPREF/$FOLDER/$ts
LOCAL_TS=$FOLDER/$ts
echo $TS_NAME
if [ -s $LOCAL_TS ]; then
echo "Already exists. skiping."
else
wget $TS_NAME -O $LOCAL_TS
fi
done < $TSL
rm $TSL
done < all_playlists.txt
rm all_playlists.txt
find . -name Thumbs.db -exec rm {} \;
当流准备就绪时,我使用Python的http服务器运行http服务器:
http-server -p 8090
然后尝试使用此命令播放:
open http://localhost:8090/bipbop_16x9_variant.m3u8 -a Safari
http服务器显示正常请求:
[12:24:51] "GET /bipbop_16x9_variant.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:51] "GET /gear1/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear1/main.ts" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/fileSequence0.webvtt" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear0/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear0/main.aac" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/fileSequence1.webvtt" "Mozilla/5.0 (Macintosh..."
但Safari未能播放该流,显示&#34; 缺少插件&#34;消息...
任何想法请???我们需要这个流来进行iOS开发......
答案 0 :(得分:0)
感谢@ libertyernie的评论,这个问题现在已经解决了。我自己实际上怀疑这个问题:Python的http服务器模块不是服务m3u8流的正确工具,因为它无法配置正确的内容类型。
更好的工具是Lighttpd。
<强>安装强>:
brew install lighttpd
现在创建一个配置文件 lighttpd.conf :
server.document-root = "<full-path-no-~>/bipbop"
server.port = 8090
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png",
".m3u8" => "application/vnd.apple.mpegurl",
".ts" => "video/MP2T"
)
最后两行对我们的成功至关重要。现在我们可以运行我们的流服务器:
lighttpd -D -f lighttpd.conf
现在我们可以打开http://localhost:8090/bipbop_16x9_variant.m3u8并观看视频流。