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

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

复制代码
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)
相关推荐
DeepReinforce3 分钟前
四、AI量化投资:使用akshare获取A股主板20260430筛选后的涨停股票
人工智能
qcx236 分钟前
【AI Agent通识九课】02 · Agent 的“思考回路“长啥样?
人工智能·ai·llm·agent
翔云12345626 分钟前
端侧推理:全面解析与深度洞察
人工智能·ai·大模型
AI精钢27 分钟前
AI Agent 从上线到删库跑路始末
网络·人工智能·云原生·aigc
码农小旋风31 分钟前
2026 终端 AI 编程工具深度横评:Claude Code、Codex CLI、Gemini CLI、Aider 怎么选
人工智能·gpt·claude
Chef_Chen1 小时前
论文解读:多模态智能体长期记忆突破:M3-Agent让AI像人一样“看、听、记、想“
人工智能·机器学习·agent·memory
zhuiyisuifeng1 小时前
2026AI办公革命:Gemini3.1Pro重塑职场效率
人工智能
threelab1 小时前
Three.js UV 图像变换效果 | 三维可视化 / AI 提示词
javascript·人工智能·uv
海兰1 小时前
【第28篇】可观测性实战:LangFuse 方案详解
人工智能·spring boot·alibaba·spring ai
feng14561 小时前
OpenSREClaw - 故障复盘和变更评审双 Agent 案例
运维·人工智能