删除视频最后几帧 剪切视频

删除视频最后几帧 剪切视频

复制代码
remove_last.py
python 复制代码
import subprocess
def remove_last_frame(input_file, output_file, frame_rate):
    command_duration = [
        'ffprobe',
        '-v', 'error',
        '-show_entries', 'format=duration',
        '-of', 'default=noprint_wrappers=1:nokey=1',
        input_file
    ]
    try:
        total_duration = float(subprocess.check_output(command_duration).strip())
        # 减去最后一帧的时长
        new_duration = total_duration - (5 / frame_rate)
        # 调用 ffmpeg 剪切视频
        command_ffmpeg = [
            'ffmpeg',
            '-i', input_file,
            '-t', str(new_duration),
            '-c', 'copy',  # 不重新编码
            '-y',  # 强制覆盖输出文件
            output_file
        ]

        subprocess.run(command_ffmpeg, check=True)
        print(f"Successfully removed the last frame from {input_file} and saved as {output_file}")

    except subprocess.CalledProcessError as e:
        print(f"Error occurred: {e}")

# 示例使用
input_file = r"E:\project\depth\buquan2\JpS7kM8\seg\mp4_all\blur\20201229_100633_861519_0_107_25.mp4"
output_file = input_file[:-4]+"_new.mp4"
frame_rate = 25

remove_last_frame(input_file, output_file, frame_rate)
相关推荐
AIHR数智引擎32 分钟前
拆掉“关键人依赖”:黄仁勋复职全员会上的四道组织切口
人工智能·经验分享·职场和发展·ai-native·英伟达·aihr
Flynn Liang32 分钟前
全栈实战:从零搭建一套可落地的生产级 AI 智能体系统(Redis 版)
人工智能·redis·ai agent
小九九的爸爸33 分钟前
为了收第一笔钱,我终于打通OPC支付链路
人工智能·程序员·全栈
kyriewen44 分钟前
我写的 12 个 AI Skill,三个月后 8 个在吃空饷
javascript·人工智能·程序员
陆枫Larry1 小时前
MCP 实践(二):让自己开发的 MCP Server 调用真实 HTTP 接口
人工智能
阿里云大数据AI技术1 小时前
从空间圈选到区域决策:EMR Serverless StarRocks(Stella)的 GIS 架构与空间索引实践
人工智能
掘金酱2 小时前
X-Lab 年度大会线上同步活动 | 带上你的 AI 作品,来 X-Lab 年度大会聊聊 AI 新生意!
人工智能
阿里云大数据AI技术2 小时前
Hologres 长记忆服务发布知识库:好记性,也要懂业务
人工智能
AllData公司负责人2 小时前
实战二:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 Http 接口同步至 Doris,API 业务数据自动拉取入数仓
大数据·数据库·数据仓库·人工智能·算法·http·doris
掘金安东尼2 小时前
Cloudflare 推出 Search for Agents:一键给网站加上面向智能体的搜索接口(全文转译 + 评论)
人工智能·agent·ai编程