Created
April 27, 2019 20:47
-
-
Save rossant/52ba4371dca43e4bca0e5ce997ac0bf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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