Skip to content

Instantly share code, notes, and snippets.

@hannic
Last active December 7, 2019 18:30
Show Gist options
  • Save hannic/d7f5abd8afc1f3561295523b97094cab to your computer and use it in GitHub Desktop.
Save hannic/d7f5abd8afc1f3561295523b97094cab to your computer and use it in GitHub Desktop.
How to download sliced mpeg movie stream

how-to-download-movie-from-srf

Check Network Request

Analyze the request and response

  • seems as the movie stream is sliced up in many .ts files with just a few seconds

  • m3u file found: index_0_av.m3u

      #EXTM3U
      #EXT-X-TARGETDURATION:10
      #EXT-X-ALLOW-CACHE:YES
      #EXT-X-PLAYLIST-TYPE:VOD
      #EXT-X-VERSION:3
      #EXT-X-MEDIA-SEQUENCE:1
      #EXTINF:10.000,
      https://srfvodhd-vh.akamaihd.net/i/vod/dok/2019/04/dok_20190407_161903_14275265_v_webcast_h264_,q40,q10,q20,q30,q50,q60,.mp4.csmil/segment1_0_av.ts?start=0.0&end=2995.32
      #EXTINF:10.000,
      https://srfvodhd-vh.akamaihd.net/i/vod/dok/2019/04/dok_20190407_161903_14275265_v_webcast_h264_,q40,q10,q20,q30,q50,q60,.mp4.csmil/segment2_0_av.ts?start=0.0&end=2995.32
    

Strategy to get them

  • curl

  • BeautiflSoup

        $ curl -O index.m3u 
    
        import os
        for line in open("index_0_av.m3u"):
          os.system("curl -O %s" % line)
    

Merging to one file

Merge downloaded files into one

            segment1_4_av.ts?start=0.0
            segment2_4_av.ts?start=0.0
            segment3_4_av.ts?start=0.0


            from moviepy.editor import VideoFileClip, concatenate_videoclips
            clip1 = VideoFileClip("myvideo.mp4")
            clip2 = VideoFileClip("myvideo2.mp4").subclip(50,60)
            clip3 = VideoFileClip("myvideo3.mp4")
            final_clip = concatenate_videoclips([clip1,clip2,clip3])
            final_clip.write_videofile("my_concatenation.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment