首页
友链
壁纸
留言
今日热榜
更多
关于
时光
推荐
精品流量卡
Search
1
都二十多年了,你的梦为什么还没碎!
57,085 阅读
2
2022年5个好用的 BT/ 磁力链接下载工具推荐 |Windows 、安卓系统
37,336 阅读
3
nps内网穿透实现外网访问树莓派
32,420 阅读
4
实践利用宝塔建emlog个人博客-超详细【原创】
26,129 阅读
5
Typecho-Joe-Theme主题帮助文档
24,603 阅读
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
登录
Search
标签搜索
PHP
HTML
API
Javascript
源码
JS
Vue
Github
CloudFlare
接口
函数
SQL
ASP.NET
MVC
EF
T4模板
后台管理
CDN
微信小程序
MAC
韩小韩
累计撰写
261
篇文章
累计收到
1,303
条评论
首页
栏目
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
页面
友链
壁纸
留言
今日热榜
关于
时光
推荐
精品流量卡
搜索到
3
篇与
ffmpeg
的结果
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,082 阅读
8 评论
2 点赞
2021-09-09
树莓派延时摄影并把所有jpg图片转mp4视频成品
{callout color="#f0ad4e"}树莓派吃灰多年了,想着让他焕发下第二春。于是想想想想想搞了个延时摄影,搞完以后,发现图片合成视频成了一个问题,博主百度ANDgoogle了好多方法都太麻烦,然后博主整合了一下分享给大家。{/callout}延时摄影代码需要 python 环境新建 你喜欢的名字.py 文件填入以下代码import picamera import time def getCurrentTime(): (year, month, day, hour, minute, second, _, _, _) = time.localtime() ret = "%04d%02d%02d%02d%02d%02d" % (year, month, day, hour, minute, second) return ret camera = picamera.PiCamera() prefix = "yanshi" #保存的图片前缀 path = "./TimePhoto/" #图片保存的目录 while True: suffix = getCurrentTime() filename = path + prefix + "_" + suffix + ".jpg" #图片全名 camera.capture(filename) time.sleep(15) #延时15秒拍摄一张图片,根据自己喜好来(建议不低于5秒){callout color="#ef4d4d"}博主从上午9点多启动放在那里,因为没有夜视功能,所以到傍晚7点多天黑了就停止拍摄了,一共拍了2000多张(删除了部分天黑时的全黑图片){/callout}JPG图片转MP4视频代码需要安装 ffmpeg 自行安装ffmpeg -framerate 12 -pattern_type glob -i '*.jpg' -c:v libx264 -profile:v high -crf 12 -pix_fmt yuv420p 你喜欢的合成后视频的名字.mp4 {callout color="#ef4d4d"}由于博主拍了一整天,合成的视频太大了,就不放了!👋👋👋{/callout}
2021年09月09日
603 阅读
2 评论
0 点赞
2020-07-10
ffmpeg任意视频批量转码MP4-H264助手
{message type="info" content="简单的粗暴的小工具,利用windows命令行调用ffmpeg完成任意格式视频转换成H264编码的MP4视频,以确保视频可以在主流浏览器中直接播放,如:Chrome、Firefox等。只需要将包含视频的文件夹或单个视频文件拖放到【视频转码助手.bat】图标上即可。如果拖放的是文件夹,则会在该文件夹下生成一个名称为mp4的目录,用来存放转换完成的mp4视频,与原始视频文件同名,并且批量转换该文件夹下的所有视频。如果拖放的是单个视频文件,则会在该视频文件相同目录下生成一个名称为mp4的目录,用来存放转换完成的mp4视频,与原始视频文件同名。转换速度依据电脑配置高低而定。"/}使用说明拖放文件夹 拖放单个视频文件 正在处理 处理完成 {cloud title="任意视频批量转码MP4-H264助手" type="lz" url="https://vvhan.lanzoui.com/iaoX5ehas5e" password=""/}
2020年07月10日
1,546 阅读
2 评论
2 点赞