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

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

复制代码
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)
相关推荐
招财小梗7 分钟前
AI矩阵获客,品牌连锁落地有啥方案?
大数据·人工智能·矩阵
jianwuhuang829 分钟前
告别手拷数据:怎么把平板电脑上Perplexity的表格导出来?详解“AI导出鸭”平板版底层逻辑
人工智能·电脑·ai导出鸭
Wang's Blog12 分钟前
AI Agent白手起家57: 上下文记忆系统——基于 Redis 的长短期记忆实现
人工智能
Leo.yuan22 分钟前
给数据团队的AI智能体选型参考:2026年8款AI数据分析产品深度测评
人工智能
寥落半伤感27 分钟前
codex接入deepseek+VLM视觉语言模型教程
人工智能·语言模型·自然语言处理·codex·deepseek
FlyWIHTSKY28 分钟前
idea中集成claude功能
java·ide·人工智能·intellij-idea·cloudera
IT_陈寒31 分钟前
SpringBoot自动配置坑了我三天,原来漏了这个注解
前端·人工智能·后端
zandy101132 分钟前
主流 AI Agent搜索Skill推荐及高阶选型指南
大数据·人工智能
Greg_Zhong34 分钟前
微信小程序 + 腾讯云人体分析:从 0 到 1 实现 AI 抠图打卡合照(细节待更新~)
人工智能·微信小程序·腾讯云·ai抠图-ai打卡拍照