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

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

复制代码
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)
相关推荐
Ralph_Salar4 分钟前
从0到1搭建AI智能支付风控助手Stage4-Agent编排 — 让AI自己思考、决策、行动
人工智能
smallyoung5 分钟前
Spring AI 2.0 VectorStore实战:从原理到RAG落地
人工智能·后端
火山引擎开发者社区1 小时前
被 Vibe Coding 用户频点名的火山 Supabase 到底是个啥?一图来看懂
人工智能
火山引擎开发者社区1 小时前
动手做 AI 实验赢好礼!产品 + 大模型免费额度限时供应!
人工智能
字节跳动视频云技术团队1 小时前
从 VCloud 到 Agentic VCloud:Agent 时代的范式重构
人工智能·音视频开发
AKAMAI2 小时前
每百万 Token 成本砍六成,出海 AI 团队开始重算推理这笔账
人工智能·云计算
RTC实战笔记2 小时前
实时互动数字人怎么做,才不是一个只会说话的视频?
音视频·数字人·rtc·数字人接入
用户938515635073 小时前
从 Prompt 到 Harness:AI 工程化的三年跃迁与实战解码
javascript·人工智能
甲维斯3 小时前
Agnes免费生图批图API+一键生图软件!
人工智能
April6664 小时前
Prompt-only 已死,Harness 才是 2026 的分水岭
人工智能