python ffmpeg合并ts文件

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家:点击跳转

当你从网站下载了一集动漫,然后发现是一堆ts文件,虽然可以打开,但是某个都是10秒左右,很不方便。

这时,可以用python合并ts文件。

(1)安装配置ffmpeg

官网下载ffmpeg-2023-08-07-git-d295b6b693-full_build

放到一个没有空格的路径中:

再把bin目录配置到环境变量。

官网下载ffmpeg

下载之后复制到site-packages中:

(2)python ffmpeg调用

代码:

python 复制代码
def merge_file(path, save_path):
    file_names = os.listdir(path)
    if 'file_list.txt' in file_names:
        os.remove(path+'file_list.txt')
    f = open(path+'file_list.txt', 'w+')
    for one in file_names:
        f.write("file '" + one + "'\n")
    f.close()
    ffmpeg_bin_dic = 'C:/ffmpeg-2023-08-07-git-d295b6b693-full_build/bin/'
    os.system(ffmpeg_bin_dic+'ffmpeg -f concat -safe 0 -i '+path+'file_list.txt'+' -c '+ ' copy ' +save_path)

注意,需要看一下file_list.txt中的各个ts顺序,和预期是否一致。

如果不一致,调整原有ts的命名,或者调整代码,直到file_list.txt中的各个ts顺序,和预期一致,才能得到正确的mp4文件。

相关推荐
金銀銅鐵2 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup116 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi008 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵10 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf11 小时前
Agent 流程编排
后端·python·agent
copyer_xyf11 小时前
Agent RAG
后端·python·agent
copyer_xyf11 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf12 小时前
Agent 记忆管理
后端·python·agent
星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程
python