[英]Http live streaming to iphone
I'm trying to play an http live stream to iphone , it looks like i have looked every example, mistakes and everything that i could found on the internet and apple docs about http live stream, and i think i'm in a dead end now.. I'm using MPMoviePlayer
as in most of examples. 我正在尝试向iphone播放http live流 ,看起来我看过每个示例,错误以及我在互联网和Apple文档中可以找到的有关http live流的所有内容,但我认为我已经死了现在..在大多数示例中,我正在使用MPMoviePlayer
。 Also i have to add the i can see the stream if i open the url from vlc player. 另外,如果我从vlc播放器打开url,我必须添加我可以看到的流。
I succeeded in playing the apple BipBop stream on my iPhone that is here but can't play my stream. 我成功在这里的 iPhone上播放了苹果BipBop流 ,但无法播放我的流。 I figured that my url shows not in the m3u8 file so i found this terminal command, and successfully used it. 我发现我的网址未显示在m3u8文件中,因此我找到了此终端命令,并成功使用了它。
/Applications/VLC.app/Contents/MacOS/VLC --intf=rc rtp://@239.35.86.11:10000 '--sout=#transcode{fps=25,vcodec=h264,venc=x264{aud,profile=baseline,level=30, keyint=30,bframes=0,ref=1,nocabac},acodec=mp3,ab=56,audio-sync,deinterlace}:standard{mux=ts,dst=-,access=file}' | /Applications/VLC.app/Contents/MacOS/VLC --intf = rc rtp://@239.35.86.11:10000'--sout =#transcode {fps = 25,vcodec = h264,venc = x264 {aud,profile = baseline,level = 30,keyint = 30,bframes = 0,ref = 1,nocabac},acodec = mp3,ab = 56,audio-sync,deinterlace}:standard {mux = ts,dst =-,access = file }'| mediastreamsegmenter -b http://192.168.1.16/~Jonas/streaming/ -f /users/jonas/sites/streaming/ -D mediastreamsegmenter -b http://192.168.1.16/~Jonas/streaming/ -f / users / jonas / sites / streaming / -D
Now i have a playlist m3u8 file locally on my machine. 现在,我的机器上本地有一个播放列表m3u8文件。 As i understand with the command i download stream divide it into smaller ts files and generate m3u8 file that is like a reference to those ts files. 据我了解的命令,我下载流将其分为较小的ts文件,并生成m3u8文件,就像对这些ts文件的引用一样。 So i've tried to load this, but still no luck. 因此,我尝试加载此文件,但仍然没有运气。 For some reasons i can't even open the m3u8 file in vlc or itunes, it throws me errors. 由于某些原因,我什至无法在vlc或iTunes中打开m3u8文件,这引发了我错误。 So i guess it is something wrong with the playlist file? 所以我想播放列表文件有问题吗?
Maybe some of you can see what am i doing wrong here or have some suggestions how to find my problem? 也许有些人可以在这里看到我做错了什么,或者对如何找到问题有一些建议? I would really appreciate it. 我真的很感激。
It looks like your iOS code is just fine and that it is your server-side code that is causing issues, primarily with regards to generating the m3u8 playlist and possibly with how you're hosting the ts files that it references. 看起来您的iOS代码很好,并且是服务器端代码引起了问题,主要是与生成m3u8播放列表有关,还可能与托管它引用的ts文件有关。
Unfortunately my example code is a bit noisy as I wrote it a year ago (it is in python) and it does a bit more than you're asking for (it live-transcodes a video into the correct m3u8/ts stuff) but it is tested and functional. 不幸的是,我的示例代码有些杂乱,就像我一年前写的那样(使用python),它的功能比您要求的要多(它将视频实时转码为正确的m3u8 / ts内容),但是经过测试和功能。
You can take a look at the code here: https://github.com/DFTi/ScribbeoServer/blob/python/transcode.py 您可以在这里查看代码: https : //github.com/DFTi/ScribbeoServer/blob/python/transcode.py
I will paste some of the relevant methods here for your convenience; 为了方便起见,我将在此处粘贴一些相关方法。 I hope it helps you: 我希望它可以帮助您:
def start_transcoding(self, videoPath):
if DISABLE_LIVE_TRANSCODE:
print "Live transcoding is currently disabled! There is a problem with your configuration."
return
print "Initiating transcode for asset at path: "+videoPath
videoPath = unquote(videoPath)
video_md5 = md5.new(videoPath).hexdigest()
if self.sessions.has_key(video_md5): # Session already exists?
return self.m3u8_bitrates_for(video_md5)
transcodingSession = TranscodeSession(self, videoPath)
if transcodingSession.can_be_decoded():
self.sessions[transcodingSession.md5] = transcodingSession
return self.m3u8_bitrates_for(transcodingSession.md5)
else:
return "Cannot decode this file."
def m3u8_segments_for(self, md5_hash, video_bitrate):
segment = string.Template("#EXTINF:$length,\n$md5hash-$bitrate-$segment.ts\n")
partCount = math.floor(self.sessions[md5_hash].duration / 10)
m3u8_segment_file = "#EXTM3U\n#EXT-X-TARGETDURATION:10\n"
for i in range(0, int(partCount)):
m3u8_segment_file += segment.substitute(length=10, md5hash=md5_hash, bitrate=video_bitrate, segment=i)
last_segment_length = math.ceil((self.sessions[md5_hash].duration - (partCount * 10)))
m3u8_segment_file += segment.substitute(length=last_segment_length, md5hash=md5_hash, bitrate=video_bitrate, segment=i)
m3u8_segment_file += "#EXT-X-ENDLIST"
return m3u8_segment_file
def m3u8_bitrates_for(self, md5_hash):
m3u8_fudge = string.Template(
"#EXTM3U\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=384000\n"
# "$hash-384-segments.m3u8\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=512000\n"
# "$hash-512-segments.m3u8\n"
"#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=768000\n"
"$hash-768-segments.m3u8\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1024000\n"
# "$hash-1024-segments.m3u8\n"
)
return m3u8_fudge.substitute(hash=md5_hash)
def segment_path(self, md5_hash, the_bitrate, segment_number):
# A segment was requested.
path = self.sessions[md5_hash].transcode(segment_number, the_bitrate)
if path:
return path
else:
raise "Segment path not found"
That project is all open source now and can be found here: https://github.com/DFTi/ScribbeoServer/tree/python 该项目现在都是开源的,可以在这里找到: https : //github.com/DFTi/ScribbeoServer/tree/python
Binaries can be found here: http://scribbeo.com/server 二进制文件可以在这里找到: http : //scribbeo.com/server
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.