Last active
December 16, 2015 18:09
-
-
Save hiccupzhu/5476100 to your computer and use it in GitHub Desktop.
简单的m3u8切片程序,python实现
This file contains 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
input_name = "jiangsugaoqing"; | |
m3u8str = '''#EXTM3U | |
#EXT-X-VERSION:3 | |
#EXT-X-TARGETDURATION:128 | |
#EXT-X-MEDIA-SEQUENCE:10000 | |
'''; | |
if __name__ == "__main__": | |
if(len(sys.argv) == 1): | |
print "Usage:%s filename" %(sys.argv[0]); | |
exit(0); | |
input_name = sys.argv[1]; | |
filesize = os.path.getsize(input_name + ".ts"); | |
os.system("rm -f *.m3u8.ts"); | |
count = 0; | |
slice_size = 188 * 25000; | |
fin = open(input_name + ".ts", 'rb'); | |
fm3u8 = open(input_name + ".m3u8", "w"); | |
fm3u8.write(m3u8str); | |
block = fin.read(slice_size); | |
while block: | |
out_name = input_name + str(count) + ".m3u8.ts"; | |
print "create:" + out_name; | |
line = "#EXTINF:%.3f,\n" %(128.0 / filesize * slice_size) | |
## fm3u8.write("#EXTINF:15.000,\n"); | |
fm3u8.write(line); | |
fm3u8.write("http://192.168.2.8:8080/" + out_name + "\n"); | |
fm3u8.flush(); | |
fout = open(out_name, "wb"); | |
fout.write(block); | |
fout.close(); | |
count += 1; | |
block = fin.read(slice_size); | |
fin.close(); | |
fm3u8.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment