20230720在ubuntu22.04系统下载+解密+合并ts切片的步骤
2023/7/20 23:06
1、视频源头,打开时效肯定有时间限制的!
【并且不同时间打开,下载链接/参数会有区别的!以前的链接就会失效/出错了!】
https://app1ce7glfm1187.h5.xiaoeknow.com/v2/course/alive/l_64af6130e4b03e4b54da1681?type=2&app_id=app1cE7gLFM1187&pro_id=term_645c69388953e_Nhew9A&available=true&share_user_id=u_5e59118832c25_IrOax1kylJ&share_type=5&scene=%E5%88%86%E4%BA%AB&share_scene=1&entry=2&entry_type=2002
2023-07-15 1530逆势增长:新一代企业经营者的能力构建-高手知路.ts
2、使用python脚本将下载的ts切片顺序命名,方便将来的/下一步合并:
(暂时最高支持6000个ts切片,如果有需要/更多可以更改循坏的终点值)
001.ts-999.ts
1000.ts-6000.ts
D:\ZIP\20230715\delete-jin6.py
#with open("5060_XhZCF6k4srMrcrGX_24481610.m3u8") as f:
#with open("5060_tZ8MCtBms2EFQi76_85905257.m3u8") as f:
#with open("5060_BHDBEMAMThXAMkzC_83736491.m3u8") as f:
#with open("5060_6f4aaa46b800eb11g_65368069.m3u8") as f:
#with open("playlist_eof.m3u8") as f:
#with open("playlist.f3.m3u8") as f:
with open("v.f146750.m3u8") as f:
#with open("v.f421220.m3u8") as f:
#with open("v.f146750.m3u8") as f:
lines = f.readlines()
for line in lines:
#if line[0] == 'h':
#if line[0] == 'p':
if line[0] == 'v':
#if line[0] == '1':
#if line[0] == '2':
#if line[0] == '3':
#if line[0] == '4':
#if line[0] == '5':
#if line[0] == '6':
#if line[0] == '7':
#if line[0] == '8':
#if line[0] == '9':
#print(line.rstrip())
print("https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/"+line.rstrip())
#print(line.rstrip())
Microsoft Windows [版本 10.0.19045.2311]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd D:\ZIP\20230715
C:\Users\Administrator>d:
D:\ZIP\20230715>dir
驱动器 D 中的卷是 SOFT
卷的序列号是 0ACA-475A
D:\ZIP\20230715 的目录
2023/07/22 23:02 <DIR> .
2023/07/22 23:02 <DIR> ..
2023/07/22 23:02 950,966 1574.txt
2023/07/20 23:12 946,492 1574旧的.txt
2023/07/22 23:01 950 delete-jin6.py
2023/07/22 23:01 615,787 v.f146750.m3u8
2023/07/20 22:54 615,787 v.f146750旧的.m3u8
2023/07/18 23:42 3,333 新建文本文档-旧的.txt
2023/07/22 23:01 4,169 新建文本文档.txt
7 个文件 3,137,484 字节
2 个目录 24,042,561,536 可用字节
D:\ZIP\20230715>python delete-jin6.py
原理:
(一)将原始的m3u8处理为真实的下载链接:【】
原始:m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="https://app.xiaoe-tech.com/get_video_key.php?edk=CiC4VtGs01Wqn9bzplV30xTHXBpeJ584cjeCi2paoN1uuxCO08TAChiaoOvUBCokYjRhNjFiNTgtMmVhNy00OWYxLTgwZGMtZTE0NTIyODc5YWIy&fileId=3270835010715022023&keySource=VodBuildInKMS",IV=0x00000000000000000000000000000000
#EXTINF:2.000000,
v.f146750_0.ts?start=0&end=108479&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
#EXTINF:2.000000,
v.f146750_0.ts?start=108480&end=216399&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
#EXTINF:2.000000,
(二)从猫抓中拷贝的部分真实路径:
https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/v.f146750.m3u8?sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh&time=1689864706616&uuid=u_6165733764809_rUxpVMZk1O
https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/v.f146750_0.ts?start=0&end=108479&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/v.f146750_0.ts?start=108480&end=216399&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
(三)将m3u8中以v开头的行真实链接和从猫抓中拷贝的部分真实路径【头】合并!:1574.txt
将字符串合并得到:最终的真实的下载链接:
https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/v.f146750_0.ts?start=0&end=108479&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
https://btt-vod.xiaoeknow.com/9764a7a5vodtransgzp1252524126/d362ace83270835010715022023/drm/v.f146750_0.ts?start=108480&end=216399&type=mpegts&sign=5766b75a00b62cece0007a8dcf49d6cd&t=64b9f2c3&us=ZviMNiFKSh
3、下载加密的ts视频切片:
D:\ZIP\ts1574.py
import requests
from multiprocessing import Pool
def mission(url,n):
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"}
print('*****')
response=requests.get(url,headers=headers)
print('-----')
#f=open("./1/%03d.ts"%n,"wb")
f=open("./1574/%03d.ts"%n,"wb")
f.write(response.content)
f.close()
print("%03d.ts OK..."%n)
if __name__ == "__main__":
#f = open("f:\\p1\\1574.txt")
#f = open("g:\\1575\\1574.txt")
#f = open("1574.txt")
f = open("d:\\ZIP\\1574.txt")
pool=Pool(20)
#for n in range(1,1574):
#for n in range(1,2000):
#for n in range(1,4000):
for n in range(1,6000):
line = f.readline()
#pool.apply_async(mission,(line,n))
pool.apply_async(mission,(line.rstrip(),n))
pool.close()
pool.join()
print('\n 2022/9/13 23:01-finish')
print(n)
Microsoft Windows [版本 10.0.19045.2311]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd d:\ZIP\
C:\Users\Administrator>
C:\Users\Administrator>d:
d:\ZIP>
d:\ZIP>python ts1574.py
4、生成通过openssl以AES-128加密模式解密ts切片的脚本并解密ts切片:
write.py
# openssl aes-128-cbc -d -in 001.ts -out 001xx.ts -nosalt -iv 00000000000000000000000000000000 -K 34961199b37742b8b9174b6102af4a9c
for n in range(1,6000):
#print("https://btt-vod.xiaoeknow.com/522ff1e0vodcq1252524126/da99c7ef3270835010800009264/"+line.rstrip())
#print("openssl aes-128-cbc -d -in 000.ts -out 000xx.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e"+line.rstrip())
#print("openssl aes-128-cbc -d -in 000.ts -out 000xx.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e")
#f=open("./1574/%03d.ts"%n,"wb")
#print("openssl aes-128-cbc -d -in %03d.ts -out 000xx.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e"%n)
#print("openssl aes-128-cbc -d -in %03d.ts -out xx/%03d.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e"%n, %n)
#print("openssl aes-128-cbc -d -in %03d.ts -out xx/%03d.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e"%n%n)
#print("openssl aes-128-cbc -d -in %03d.ts -out xx/%03d.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e"%n%n)
#print("{} + {} = {}".format(1,2,3))
#print("openssl aes-128-cbc -d -in {%03d}.ts -out xx/{%03d}.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e".format(n, n))
#print("openssl aes-128-cbc -d -in {}.ts -out xx/{}.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e".format(n, n))
#'{value:0>6d}'.format(value=6666)
print("openssl aes-128-cbc -d -in {:0>3d}.ts -out xx/{:0>3d}.ts -nosalt -iv 00000000000000000000000000000000 -K 0b53fbec72cb3a6d4d9c8efbc23a025e".format(n, n))
Microsoft Windows [版本 10.0.19045.2311]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Administrator>cd D:\ZIP
C:\Users\Administrator>d:
D:\ZIP>dir
驱动器 D 中的卷是 SOFT
卷的序列号是 0ACA-475A
D:\ZIP 的目录
2023/07/22 23:43 <DIR> .
2023/07/22 23:43 <DIR> ..
2023/07/22 23:39 4,368 12jia.py
2023/07/22 23:28 <DIR> 1574
2023/07/22 23:02 950,966 1574.txt
2023/07/22 23:10 495,640,050 1574a只有加密的.zip
2023/07/22 23:38 994,470,172 1574b加密+解密.zip
2023/07/22 23:02 <DIR> 20230715
2023/07/20 22:58 1,189 get_video_key.mhtml
2023/07/20 23:00 16 get_video_key.php
2023/07/22 23:41 500,611,288 output.ts
2023/07/22 12:31 994 ts1574.py
2023/07/19 20:34 1,750 write.py
2023/03/18 19:04 4,992 !!!!20160908如何将多段ts文件合并成一个ts文件.txt
10 个文件 1,991,685,785 字节
4 个目录 24,044,519,424 可用字节
D:\ZIP>
D:\ZIP>python write.py > 1574\decrypt.bat
D:\ZIP\1574>decrypt.bat
5、合并切片:
Z:\zip\12jia.py
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(1,999):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%03d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output1.ts"
url = url + temp
f=open("./1574/xx/1.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(1000,2000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output2.ts"
url = url + temp
f=open("./1574/xx/2.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(2001,3000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output3.ts"
url = url + temp
f=open("./1574/xx/3.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
#for n in range(3001,3389):
for n in range(3001,4000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output4.ts"
url = url + temp
f=open("./1574/xx/4.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(4001,5000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output5.ts"
url = url + temp
f=open("./1574/xx/5.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(5001,6000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output6.ts"
url = url + temp
f=open("./1574/xx/6.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(6001,7000):
#temp = "./1574/xx/%04d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output7.ts"
url = url + temp
f=open("./1574/xx/7.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(7001,8000):
#temp = "./1574/xx/%04d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output8.ts"
url = url + temp
f=open("./1574/xx/8.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(8001,9000):
#temp = "./1574/xx/%04d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output9.ts"
url = url + temp
f=open("./1574/xx/9.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(9001,10000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%04d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output10.ts"
url = url + temp
f=open("./1574/xx/10.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(10001,11000):
#temp = "./1574/xx/%03d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%04d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output11.ts"
url = url + temp
f=open("./1574/xx/11.bat","w")
f.write(url)
f.close()
temp = ""
url = "ffmpeg -i \"concat:"
#for n in range(1,10):
for n in range(11001,12000):
#temp = "./1574/xx/%05d.ts"%n
temp = "%03d.ts|"%n
url = url + temp
#print(temp)
#print(url)
temp = "%05d.ts"%(n+1)
url = url + temp
temp = "\" -c copy output12.ts"
url = url + temp
f=open("./1574/xx/12.bat","w")
f.write(url)
f.close()
D:\ZIP\1574\xx>
D:\ZIP\1574\xx>1.bat
D:\ZIP\1574\xx>2.bat
D:\ZIP\1574\xx>3.bat
D:\ZIP\1574\xx>4.bat
D:\ZIP\1574\xx>5.bat
D:\ZIP\1574\xx>ffmpeg -i "concat:output1.ts|output2.ts|output3.ts|output4.ts|output5.ts" -c copy output.ts
D:\ZIP\1574\xx>
【5.bat需要拿掉后面没有的文件/ts切片!】
参考资料:
https://www.cnblogs.com/faberbeta/p/ffmpeg001.html
Linux 下使用 ffmpeg 大批量合并 ts 文件, mp4切割文件为m3u8
https://blog.csdn.net/oncealong/article/details/82785642
hls视频的加解密示例
https://blog.csdn.net/nizhengjia888/article/details/78041945
解密HLS中的AES加密
https://blog.csdn.net/oncealong/article/details/82785447
使用openssl命令加解密 aes-128-cbc的简单示例
https://blog.csdn.net/ddddfang/article/details/92838200
xxd命令
https://blog.csdn.net/y534560449/article/details/116531326
!!!!使用 FFmpeg 生成 ts 切片并使用 AES-128 加密
https://blog.csdn.net/beyond706/article/details/111772810
!!!!使用openssl m3u8解密 EXT-X-KEY:METHOD=AES-128,URI=xxx
https://blog.csdn.net/u014470361/article/details/90705336
ubuntu16.04安装ffmpeg最新版
https://blog.csdn.net/huangjingshui/article/details/75003771
如何查看openssl版本号
openssl version
openssl version -a