Skip to content

Instantly share code, notes, and snippets.

@egyjs
Last active February 21, 2021 00:40
Show Gist options
  • Save egyjs/d1688df9e7c42b52d7ccd2212d109919 to your computer and use it in GitHub Desktop.
Save egyjs/d1688df9e7c42b52d7ccd2212d109919 to your computer and use it in GitHub Desktop.
get ts, m3u8 files video and convert it to mp4

get ts, m3u8 files video and convert it to mp4

python3 get.py 
# you need to download all ts files,then:
sh marge.sh folderName
import os
folderName = 'folderName'
fileurl = "fileurl"
m3u8file = folderName+"/m3u8/480p.m3u8"
if not os.path.exists(folderName):
os.makedirs(folderName)
os.makedirs(folderName+/'marged')
os.makedirs(folderName+'/ts')
os.makedirs(folderName+'/m3u8')
os.system("wget "+fileurl+"/480p.m3u8 -O "+m3u8file)
# Parse playlist for filenames with ending .ts and put them into the list ts_filenames
with open(m3u8file, 'r') as playlist:
ts_filenames = [line.rstrip() for line in playlist
if line.rstrip().endswith('.ts')]
for x in (ts_filenames):
os.system("wget "+fileurl+'/'+ str(x) +" -bqc -O "+folderName+'/ts/'+str(x)+' -o log.txt')
#!/bin/bash
files=`ls -v $1/ts/*.ts`
for file in $files;
do
cat $file >> "$1/marged/newvideo.ts";
done;
ffmpeg -i "$1/marged/newvideo.ts" -c:v libx264 -c:a copy -bsf:a aac_adtstoasc "$1/$1.mp4";
rm "$1/marged/newvideo.ts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment