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

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

复制代码
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)
相关推荐
沐泽百川13 分钟前
AI 应用上线后怎么排查问题?日志与可观测性应该这样设计
人工智能
在世修行16 分钟前
第17篇:晶粒尺寸统计算法 — 从像素到微米的转换
人工智能·计算机视觉·像素转换
万点科技码农22 分钟前
2025年7月11日行业热点解读:定制软件开发与AI工作流重构一体化趋势
大数据·人工智能·重构
JL1531 分钟前
Agent工程-为什么Agent必须有观测和Tracing
服务器·网络·人工智能·安全
用户69549770994941 分钟前
第 8 章 vLLM/LMDeploy/Triton 适配 DeepSeek 源码改造
人工智能
波动几何44 分钟前
角色生成器character-builder
人工智能
dayuOK630744 分钟前
AI Agent市场爆发:从“试一试”到“离不开”,只用了不到一年
大数据·人工智能·ai作画·新媒体运营·aigc·ai写作
茶马古道的搬运工1 小时前
AI 深度技能之-解读Hermes Agent(四)- Hermes Kanban 多 Agent 流水线
人工智能
海外数字观察家1 小时前
马来西亚商贸数字化落地指南:跨境批发、连锁零售首选ERP方案(品未云)
大数据·人工智能·马来西亚进销存系统·马来西亚收银系统·马来西亚erp系统·马来西亚仓库管理系统
珠海西格电力1 小时前
数据采集与治理:零碳园区管理系统的 “生命线”
大数据·人工智能·算法·架构·能源