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

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

复制代码
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)
相关推荐
用户960984579224021 分钟前
本机 AGY 环境备份、跨平台改造与新机一键初始化实战
人工智能
前进的李工23 分钟前
Agent 学习笔记 29:多 Agent 协作的六种失败模式
人工智能·乐观锁·ai agent·harness·理解债与认知缺陷·拜占庭故障·循环失控
用户960984579224025 分钟前
多会话并行控 Chrome 不打架:标签归属隔离、桌面输入互斥与第六色状态灯实战
人工智能
用户960984579224034 分钟前
项目级 .agent/ 隔离、双协议 Hooks 与只读 DB/Redis 插件实战
人工智能
用户960984579224034 分钟前
MCP 懒加载代理与 Chrome 会话标签组:按需拉起浏览器、容器与标签归组实战
人工智能
云票36 分钟前
湖南废止施工组织设计智能评审:2分规则取消
大数据·人工智能
王亚博_Abel42 分钟前
127 加 1 为什么是 -128?手拆补码四个实验实测
人工智能
Techblog of HaoWANG1 小时前
具身智能机器人专题(7)大模型 / 语音 / RAG 的容器化架构与系统开发
人工智能·算法·大模型·边缘计算·具身智能
RPA机器人就用八爪鱼1 小时前
电商重复流程自动化:用 AI 搭建和维护,用 RPA 按规则执行
人工智能·自动化·rpa
ii_best2 小时前
按键精灵找图脚本怎么写?iOS 找图找色实现与参数要点
人工智能·计算机视觉·ios·自动化·按键精灵