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

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

复制代码
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)
相关推荐
链上日记3 分钟前
AgentWin:AI Agent驱动的Web4智能金融新纪元
人工智能·金融
程序员飞哥8 分钟前
重构 AI 思维(一):Prompt Engineering,如何下达不可违抗的指令?
人工智能·后端
冬奇Lab1 小时前
一天一个开源项目(第94篇):Agent Skills - 为 AI 代码助手注入工程师级纪律
人工智能·开源·资讯
冬奇Lab1 小时前
RAG 系列(九):效果不好怎么定位——用 RAGAS 做根因诊断
人工智能·llm·源码
火山引擎开发者社区1 小时前
ArkClaw 的技能是不是越多越好?很多人一开始就想错了
人工智能
火山引擎开发者社区1 小时前
星穹方舟基于火山引擎 ArkClaw 推出全场景龙虾硬件
人工智能
甲维斯1 小时前
JCode支持Claude和第三方模型tokens统计!
人工智能·ai编程
小短腿的代码世界2 小时前
QtAV音视频播放实战深度解析:从零构建高性能跨平台播放器
qt·音视频
拓朗工控2 小时前
深度学习工控机部署实战:从硬件选型到稳定运行的避坑指南
人工智能·深度学习·智能电视·工控机
iDao技术魔方2 小时前
DeepSeek TUI:原生 Rust 打造的终端 AI 编码 Agent
开发语言·人工智能·rust