首页
友链
壁纸
留言
今日热榜
更多
关于
时光
推荐
精品流量卡
Search
1
都二十多年了,你的梦为什么还没碎!
57,051 阅读
2
2022年5个好用的 BT/ 磁力链接下载工具推荐 |Windows 、安卓系统
37,158 阅读
3
nps内网穿透实现外网访问树莓派
32,370 阅读
4
实践利用宝塔建emlog个人博客-超详细【原创】
26,116 阅读
5
Typecho-Joe-Theme主题帮助文档
24,518 阅读
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
登录
Search
标签搜索
PHP
HTML
API
Javascript
源码
JS
Vue
Github
CloudFlare
接口
函数
SQL
ASP.NET
MVC
EF
T4模板
后台管理
CDN
微信小程序
MAC
韩小韩
累计撰写
261
篇文章
累计收到
1,296
条评论
首页
栏目
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
页面
友链
壁纸
留言
今日热榜
关于
时光
推荐
精品流量卡
搜索到
2
篇与
Python
的结果
2022-08-24
FFMPEG视频切片TS文件添加PNG文件头伪图片上传
{message type="info" content="在这个图床泛滥的时代,不能白白浪费那么那么那么多免费的图床!总想着做点什么,想来想去,只想把我好多好多无处可放的视频传上去,可是图床它并不能上传视频。思来想去,图床只能上传图片嘛?为什么它知道我是图片?我想!并不是!看来看去,噢,原来只要把文件头改成图片HEAD头就OK,我说它是图片它就是图片!图片改头换面伪装大法现在开始~"/}前期准备{callout color="#f0ad4e"}FFmpeg 并配置环境变量(不会的话百度一下 你知道~){/callout}{cloud title="FFmpeg 官网下载" type="default" url="https://www.gyan.dev/ffmpeg/builds/" password=""/}{callout color="#f0ad4e"}python 环境 (自行安装,不会的话,百度一下噢~){/callout}{cloud title="Python 官网下载" type="default" url="https://www.python.org/downloads/" password=""/}整体步奏对MP4视频文件转换单TS文件对单TS文件切割成多个TS切片文件并生成M3U8文件对TS文件进行 "偷天换日 改头换面" 伪图片处理上传任意图床取 "PNG" 文件地址最后预览视频{callout color="#f0ad4e"}国外图床 测试可正常播放(视频质量过高,且国外CDN,速度加载较慢,国内图床无敌!){/callout}{dplayer src="https://jsd.onmicrosoft.cn/gh/uxiaohan/GitImgTypecho@master/usr/uploads/2022/08/index.m3u8"/}开始 Start{callout color="#f0ad4e"}Python 脚本博主已经写好,一键处理,方便至简!!!!{/callout}代码片段{callout color="#f0ad4e"}标准mp4视频转TS文件{/callout}# Mp4 文件名字 不需要加 .mp4 后缀 vName = 'SaiBoPengKe' cmd_str = f'ffmpeg -y -i {vName}.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb {vName}.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'标准 Mp4 转换到 TS 成功!'){callout color="#f0ad4e"}TS单文件切片{/callout}filePath = f'./{vName}' if os.path.exists(filePath) == False: os.makedirs(filePath) cmd_str = f'ffmpeg -i {vName}.ts -c copy -map 0 -f segment -segment_list ./{vName}/index.m3u8 -segment_time 2 ./{vName}/output%03d.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'TS 切片 成功!'){callout color="#f0ad4e"}TS切片文件批量重命名为PNG{/callout}file_list = os.listdir(filePath) for i in file_list: if i.endswith(".ts"): new_name = i.replace(".ts", ".png") os.rename(f'{filePath}/' + i, f'{filePath}/' + new_name) print("TS重命名为PNG 成功!"){callout color="#f0ad4e"}TS切片 偷天换日 改头换面 添加PNG文件头{/callout}file_list = os.listdir(filePath) rewritePath = f'{filePath}Png/' if os.path.exists(rewritePath) == False: os.makedirs(rewritePath) for i in file_list: if i.endswith(".png"): copyfile("PNG", f'{rewritePath}/' + i) else: copyfile(f'{filePath}/' + i, f'{rewritePath}/' + i) file_list = os.listdir(rewritePath) for i in file_list: if i.endswith(".png"): bin_file = open(f'{filePath}/' + i, 'rb') # 打开二进制文件 # 合并文件 with open(f'{rewritePath}/' + i, 'ab') as f: f.write(bin_file.read()) bin_file.close() print("PNG元数据转PNG-TS 成功!") os.remove(f'{vName}.ts') shutil.rmtree(filePath) print("临时文件删除成功"){callout color="#f0ad4e"}这里需要一个 PNG 文件头,可自己自定义,上传后伪图片文件可显示博主提供一个做好的{/callout}{callout color="#f0ad4e"}PNG头部HEAD数据16进制{/callout}89504E470D0A1A0A0000000D494844520000007C0000007508060000008C118576000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000011049444154785EEDD10101000008C320FB97BE411815B8855238A6704CE198C23185630AC7148E29{cloud title="PNG头文件下载" type="lz" url="https://ohan.lanzouv.com/i4PL80a5vgoh" password=""/}代码整合脚本# utf-8 import subprocess import os import shutil from shutil import copyfile # Mp4 文件名字 vName = 'sbpk' # 标准mp4转TS格式------------------------------------------------------------------------------ cmd_str = f'ffmpeg -y -i {vName}.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb {vName}.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'标准 Mp4 转换到 TS 成功!') # TS切片------------------------------------------------------------------------------ filePath = f'./{vName}' if os.path.exists(filePath) == False: os.makedirs(filePath) cmd_str = f'ffmpeg -i {vName}.ts -c copy -map 0 -f segment -segment_list ./{vName}/index.m3u8 -segment_time 2 ./{vName}/output%03d.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'TS 切片 成功!') # TS重命名为PNG------------------------------------------------------------------------------ file_list = os.listdir(filePath) for i in file_list: if i.endswith(".ts"): new_name = i.replace(".ts", ".png") os.rename(f'{filePath}/' + i, f'{filePath}/' + new_name) print("TS重命名为PNG 成功!") # PNG文件添加PNG文件头------------------------------------------------------------------------------ file_list = os.listdir(filePath) rewritePath = f'{filePath}Png/' if os.path.exists(rewritePath) == False: os.makedirs(rewritePath) for i in file_list: if i.endswith(".png"): copyfile("PNG", f'{rewritePath}/' + i) else: copyfile(f'{filePath}/' + i, f'{rewritePath}/' + i) file_list = os.listdir(rewritePath) for i in file_list: if i.endswith(".png"): bin_file = open(f'{filePath}/' + i, 'rb') # 打开二进制文件 # 合并文件 with open(f'{rewritePath}/' + i, 'ab') as f: f.write(bin_file.read()) bin_file.close() print("PNG元数据转PNG-TS 成功!") os.remove(f'{vName}.ts') shutil.rmtree(filePath) print("临时文件删除成功"){message type="info" content="我刚测试成功,立马发文,快去试试吧~"/}
2022年08月24日
2,047 阅读
8 评论
2 点赞
2020-11-24
Python操作selenium
logging用法logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) logger.info("test")pyautogui坐标点击识别图片coords = pyautogui.locateOnScreen('1.png')获取坐标x, y = pyautogui.center(coords)点击坐标pyautogui.leftClick(x, y)
2020年11月24日
1,167 阅读
0 评论
0 点赞