Created
June 20, 2018 18:32
-
-
Save chexov/11240ae16fff0393e42e09185658b220 to your computer and use it in GitHub Desktop.
concat list input for ffmpeg from dash m4s chunks
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
#!/usr/bin/env python | |
import sys | |
import os | |
def ffmpegconcatlist(ts_list, isPlain): | |
tslist = [] | |
for f in ts_list: | |
f = f.strip() | |
if not f or not os.stat(f).st_size: | |
continue | |
ts = os.path.basename(f) | |
seq = int(ts.replace(".m4s", "").replace("./","")) | |
tslist.append((seq,f)) | |
tslist = sorted(tslist, key=lambda o: o[0]) | |
result = [] | |
for o,f in tslist: | |
if (isPlain): | |
result.append(("{0}".format(f)) ) | |
else: | |
result.append(("file '{0}'".format(f)) ) | |
return result | |
def test(): | |
data = """ | |
/a/b/c/d/9.ts | |
aa/a/a/a/5.ts | |
a/a/a/a/a/a/1.ts | |
a/a/a/a/a/a/a/2.ts | |
""" | |
print("\n".join(ffmpegconcatlist(data.splitlines())), False) | |
data = """ | |
9.ts | |
5.ts | |
1.ts | |
2.ts | |
10.ts | |
1000.ts | |
1010.ts | |
2010.ts | |
3010.ts | |
3013.ts | |
""" | |
print("\n".join(ffmpegconcatlist(data.splitlines())), True) | |
if __name__ == "__main__": | |
#test() | |
result = [] | |
if len(sys.argv) > 1: | |
if (sys.argv[1] == "-plain"): | |
result = ffmpegconcatlist(sys.stdin.readlines(), True) | |
else: | |
print "error. incorrect params" | |
sys.exit(1) | |
else: | |
result = ffmpegconcatlist(sys.stdin.readlines(), False) | |
if (len(result) > 0): | |
print("\n".join(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment