這個比較好用。
copy /b d:\xxx\download_ts\* d:\xxx\download_ts\new.mp4
用python ffmpeg也可以,不過我合出來有卡頓或者掉聲問題,
參數估計調整不
#!/usr/bin/env/python #_*_coding:utf-8_*_ #Data:2017-10-02 #Auther:蘇莫 #Link:http://blog.csdn.net/lingluofengzang #PythonVersion:python2.7 #filename:convert_m3u8.py import os import sys reload(sys) sys.setdefaultencoding('utf-8') # 檢查文件路徑及文件是否正確 def check_path_file(_path, _file): # 判斷路徑是否存在 # os.path.isdir(path) 判斷路徑是否為目錄 # os.path.isabs(path) 判斷是否為絕對路徑 if os.path.isdir(_path) or os.path.isabs(_path): # 判斷文件是否存在 # os.path.join(path1[, path2[, ...]]) 把目錄和文件名合成一個路徑 # os.path.exists(path) 路徑存在則返回True,路徑損壞返回False if os.path.exists(os.path.join(_path, _file)): print u'>>>[-] 目標文件已經存在。' exit(0) return True else: print u'>>>[-] 路徑不存在。' exit(0) # 更改后綴名為[.ts] def change_file_name(_path): # 獲取路徑下的文件名 files = os.listdir(_path) for filename in files: # 文件名分割 文件名稱+后綴 portion = os.path.splitext(filename) if portion[1] != '.m3u8' or portion[1] == '': newname = portion[0]+".ts" # 切換到文件所在路徑 os.chdir(_path) # 更換文件后綴 os.rename(filename,newname) return True # 對[.ts]文件進行排序 def sort_file(_path, num = '1'): if num == '1': change_file_name(_path) file_lists = os.listdir(_path) file_list = [] for file in file_lists: portion = os.path.splitext(file) if portion[1] == '.ts': file_list.append(int(portion[0])) file_list.sort() return file_list # 合並文件 def convert_file(_path, files, filename): tmp = [] for file in files: tmp.append(str(file) + '.ts') # 合並ts文件 os.chdir(_path) shell_str = '+'.join(tmp) shell_str = 'copy /b '+ shell_str + ' ' + filename os.system(shell_str) # 刪除ts和m3u8文件 os.system('del /Q *.ts') os.system('del /Q *.m3u8') if __name__ == '__main__': print '-' * 60 + '\n' print u'將m3u8格式的視頻轉換成mp4格式'.center(60) + '\n' print '-' * 60 try: _path = raw_input(unicode('>>>[+] 請輸入m3u8視頻所在目錄\n>>>[+] ').encode('gbk')) _file = raw_input(unicode('>>>[+] 請輸入mp4的文件名\n>>>[+] ').encode('gbk'))+'.mp4' print u'>>>[+] 是否需要將m3u8視頻后綴名轉換為[.ts]' num = raw_input('>>>[+] Yes:1 No:2\n>>>[+] [1]') flag = check_path_file(_path, _file) if flag: if num == '2': files = sort_file(_path, num) else: files = sort_file(_path) print '-' * 60 convert_file(_path, files, _file) except Exception as e: print e