Skip to content

Instantly share code, notes, and snippets.

@rossant
Created April 27, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossant/52ba4371dca43e4bca0e5ce997ac0bf0 to your computer and use it in GitHub Desktop.
Save rossant/52ba4371dca43e4bca0e5ce997ac0bf0 to your computer and use it in GitHub Desktop.
import os
import requests
import shutil
def _dl(url, path):
print("download", url, "to", path)
response = requests.get(url, stream=True)
if response.status_code != 200:
return
with open(path, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
urltmp = '...mp4.csmil/segment%d_4_av.ts?null=0'
def download(i):
url = urltmp % i
path = 'video%d.ts' % i
if not os.path.exists(path):
return
try:
#if not _dl(url, path):
# return
return path
except Exception as e:
print("error", e)
return
i = 1
files = []
while True:
f = download(i)
if f is None:
break
files.append(f)
i += 1
cmd = 'cat %s > out.ts' % ' '.join(files)
os.system(cmd)
os.system('ffmpeg -i out.ts -acodec copy -vcodec copy out.mp4')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment