Skip to content

Instantly share code, notes, and snippets.

@ranlix
Last active July 15, 2018 09:45
Show Gist options
  • Save ranlix/8332191 to your computer and use it in GitHub Desktop.
Save ranlix/8332191 to your computer and use it in GitHub Desktop.
将同一目录下所有.ts文件合并到一个新的.ts文件(PS: .ts文件是可以直接合并的视频文件,因此可以这样合并)
# -*-coding: utf-8 -*-
import sys
import os
num = sys.argv[1] # num is the amount of *.ts files
def add(x):
"""'x' is the amount of *.ts
This function should add all other .ts combined into '1.ts'
"""
os.popen("touch all.ts")
x = int(x)
i = 1
while i <= x:
command = "cat " + str(i) + ".ts " + ">> all.ts"
try:
os.popen(command)
except: # 如果没有当前.ts, 打印出错误并跳过
print "There is no " + i + ".ts"
i += 1
return True
if __name__ == '__main__':
add(num)
@pingod
Copy link

pingod commented Jul 15, 2018

直接cat可能有时候文件顺序不对

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment