惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
B
Blog
月光博客
月光博客
博客园 - 【当耐特】
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
博客园 - Franky
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
B
Blog RSS Feed
H
Help Net Security

韩小韩博客

你还在用真实邮箱注册网站?等等,你真的想清楚了吗? IPFS星际文件系统 最新二合一收款码 - 物理合并版 从Hexo到Astro博客1分钟迁移指南 Astro 添加 Waline 评论组件 腾讯云 EdgeOne Pages 实测对比:能否成为国内开发者的 Cloudflare Pages 最佳平替? Astro 中使用 Lenis 增加鼠标滚动阻尼感 一组手机和电脑动态壁纸分享【分享】 Astro 添加 Twikoo 评论组件 Astro主题-优雅的vhAstro-Theme【使用文档】 Fetch的GET、POST简单HTTP请求封装 一些实拍的手机壁纸 大理And威海【图】 很喜欢西湖的水【转自:狮子狮子鱼】 Tarot-塔罗牌占卜 Web Watermark 图片添加水印在线小助手 HanAnalytics访问分析Web统计托管于(Cloudflare Pages) 基于AI的微博动态心情分析 阿里云免费用9年ecs教程【适合轻量化服务如frp】 Cloudflare优选IP➕DnsPod的DDNS自动切换 混沌神器Clash全家桶 卷王都在用的变态休息法 NodeJs文本相似度去重脚本 骤雨重山无限存储图床托管于(Cloudflare Pages) 分享好看的天空和云(长期更新) Typecho转到Hexo(主题由Typecho-Joe-Theme转Butterfly主题) Typecho评论导出为Hexo的Valine、Twikoo等评论所支持的JSON文件 Safari浏览器内容被地址栏、菜单栏或工具栏遮挡导致的兼容问题 拼夕夕快速提现100元攻略 2024 平安喜乐
FFMPEG视频切片TS文件添加PNG文件头伪图片上传
.𝙃𝙖𝙣 · 2026-04-11 · via 韩小韩博客

893 4.5分钟

Code

在这个图床泛滥的时代,不能白白浪费那么那么那么多免费的图床!总想着做点什么,想来想去,只想把我好多好多无处可放的视频传上去,可是图床它并不能上传视频。 思来想去,图床只能上传图片嘛?为什么它知道我是图片?我想!并不是!看来看去,噢,原来只要把文件头改成图片 HEAD 头就 OK,我说它是图片它就是图片! 图片改头换面伪装大法现在开始~

前期准备

FFmpeg 并配置环境变量(不会的话百度一下 你知道~)

FFmpeg 官网下载

python 环境 (自行安装,不会的话,百度一下噢~)

Python 官网下载

FFMPEG视频切片TS文件添加PNG文件头伪图片上传

整体步奏

  1. 对 MP4 视频文件转换单 TS 文件
  2. 对单 TS 文件切割成多个 TS 切片文件并生成 M3U8 文件
  3. 对 TS 文件进行 “偷天换日 改头换面” 伪图片处理
  4. 上传任意图床取 “PNG” 文件地址

最后预览视频

国外图床 测试可正常播放 (视频质量过高,且国外 CDN,速度加载较慢,国内图床无敌!)

开始 Start

Python 脚本博主已经写好,一键处理,方便至简!!!!

FFMPEG视频切片TS文件添加PNG文件头伪图片上传

代码片段

标准 mp4 视频转 TS 文件

# 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 成功!')

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 成功!")

TS 切片 偷天换日 改头换面 添加 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("临时文件删除成功")

这里需要一个 PNG 文件头,可自己自定义,上传后伪图片文件可显示 博主提供一个做好的

FFMPEG视频切片TS文件添加PNG文件头伪图片上传

PNG 头部 HEAD 数据 16 进制

89504E470D0A1A0A0000000D494844520000007C0000007508060000008C118576000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000011049444154785EEDD10101000008C320FB97BE411815B8855238A6704CE198C23185630AC7148E29
PNG 头文件下载

代码整合脚本

# 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("临时文件删除成功")

我刚测试成功,立马发文,快去试试吧~

ffmpeg Python 切片 视频