對於大型音視頻而言,完整下載後再播放會致使延時很大。針對這種應用場景,七牛雲還提供對音視頻進行切片存儲的功能,目前已支持HLS(HTTP Live Streaming,Apple提出的基於HTTP的流媒體傳輸協議)。html
本篇將解釋如何使用音視頻切片功能與如何保護切片內容。segmentfault
七牛雲經過在avthumb接口中提供m3u8指令實現HLS切片存儲功能。api
注意:avthumb接口是同步接口,如原資源過大將致使訪問端超時返回。如下示例僅做爲用法演示,強烈建議正式生產環境中使用預轉持久化處理接口或觸發持久化處理接口進行預處理,加快訪問速度。瀏覽器
仍以美劇《黑名單》第1季第12集的預告片(flv資源)爲例,在瀏覽器中打開以下URL:七牛雲存儲
http://developer.qiniu.com/samples/黑名單-S01E12.flv?avthumb/m3u8/segtime/10/preset/video_240k
則七牛雲將對指定資源進行切片並返回相應的m3u8列表文件:ide
#EXTM3U #EXT-X-VERSION:3 #EXT-X-TARGETDURATION:10 #EXTINF:11.000, http://developer.qiniu.com/samples/%E9%BB%91%E5%90%8D%E5%8D%95-S01E12.flv?avthumb/m3u8/segtime/10/preset/video_240k@seg1 #EXTINF:10.000, http://developer.qiniu.com/samples/%E9%BB%91%E5%90%8D%E5%8D%95-S01E12.flv?avthumb/m3u8/segtime/10/preset/video_240k@seg2 #EXTINF:8.267, http://developer.qiniu.com/samples/%E9%BB%91%E5%90%8D%E5%8D%95-S01E12.flv?avthumb/m3u8/segtime/10/preset/video_240k@seg3 #EXT-X-ENDLIST
切片存儲生成的各個片斷資源將存儲在與原資源相同的存儲空間裏。對於私有空間中的片斷資源,必須進行下載受權方可訪問,這就要求對m3u8文件裏的每個URL進行受權。七牛雲提供pm3u8接口來實現這一功能。code
假設已有以下m3u8文件(保存在私有空間中):視頻
http://developer.qiniu.com/samples/live_net.m3u8 #EXTM3U #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOW-CACHE:YES #EXT-X-TARGETDURATION:31 #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00000_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00001_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00002_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00003_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00004_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00005_.ts #EXTINF:30.827000, http://developer.qiniu.com/samples/fop/av/live_00006_.ts #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00007_.ts #EXTINF:30.827000, http://developer.qiniu.com/samples/fop/av/live_00008_.ts #EXTINF:25.149000, http://developer.qiniu.com/samples/fop/av/live_00009_.ts #EXT-X-ENDLIST
那麼在瀏覽器中鍵入以下URL便可獲得相應的受權m3u8文件:htm
http://developer.qiniu.com/samples/live_net.m3u8?pm3u8/0&e=1388734117&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:sKjXkO59AxPtdaO2cEtWtiHmzdo= #EXTM3U #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOW-CACHE:YES #EXT-X-TARGETDURATION:31 #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00000_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:qhXZvVauNafcUMoBeo4SkRWaWiw #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00001_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:h1Oy8oW7oAIOGWZP8QNVAPI82Vw #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00002_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:OQ6GMLEjFRnCAne9K9YU8-tXeIg #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00003_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:XWdLiYgUxNZbqikNLQ3joG3Mvhk #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00004_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:3EKOMwcqSUWsdap3SaY4l3RoaCg #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00005_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:j4uORlTKDBHk4Xwkv90eCM3I87U #EXTINF:30.827000, http://developer.qiniu.com/samples/fop/av/live_00006_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:tp7CjnEBGxGHkDbRqd8OehlGSno #EXTINF:30.826000, http://developer.qiniu.com/samples/fop/av/live_00007_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:QxYkdqWEAYj90kgX5jUPedFxXVo #EXTINF:30.827000, http://developer.qiniu.com/samples/fop/av/live_00008_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:MQ7EDzKP2f_EtpXq-maGr88mazA #EXTINF:25.149000, http://developer.qiniu.com/samples/fop/av/live_00009_.ts?e=1388773727&token=u8WqmQu1jH21kxpIQmo2LqntzugM1VoHE9_pozCU:jmx4dIZndnrNFqzLg72YZM-qtmY #EXT-X-ENDLIST
注意:blog
通過三篇文章以後,讀者應該瞭解並能獨立使用七牛雲的音視頻處理功能,本指南將告一段落。
隨着處理功能的增多,本指南還可能會追加相應內容,敬請期待!
七牛雲存儲 © 2014 署名-非商業性使用-禁止演繹
容許自由轉載,請註明做者及出處。