简体   繁体   中英

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. Also i have to add the i can see the stream if i open the url from vlc player.

I succeeded in playing the apple BipBop stream on my iPhone that is here but can't play my stream. I figured that my url shows not in the m3u8 file so i found this terminal command, and successfully used it.

/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

Now i have a playlist m3u8 file locally on my machine. 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. 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. 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.

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.

You can take a look at the code here: 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

Binaries can be found here: http://scribbeo.com/server

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM