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

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

复制代码
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)
相关推荐
imythu1 分钟前
让 Claude Code 在家跑,我在外面用手机盯着:做一个开源工具踩过的几个坑
人工智能·github
躺柒12 分钟前
读数据安全架构设计与实践20安全政策文件体系(上)
大数据·人工智能·安全·数据安全·安全架构·安全体系
用户3025147280621 分钟前
从对话到行动:用 AIUI 构建「意图驱动」的隐形界面——「言值」AI 表达教练开发实录
人工智能
武子康26 分钟前
工作流 JSON 没变,为什么 ComfyUI 更新后仍可能跑出不同结果?
人工智能·agent
海螺_AIHCC38 分钟前
Agent 能自己调工具之后,安全就不该写在提示词里:一个 200 行拦截器的工程实践
人工智能
加宝的起点雷达1 小时前
三个定时任务被删那天,系统一声不吭
人工智能·后端
用户321757668341 小时前
ComfyUI AI 漫剧本地量产流水线搭建教程|8G 显存本地部署、分镜生成、角色一致性、视频生成
人工智能
荆棘宠物1 小时前
大模型 API 流式输出的工程细节:SSE 分帧、中断与重试边界
人工智能
神鹰手哥_起飞版1 小时前
别让大模型写 HTML:一个省 token 的分工实验
人工智能
AI日报派送佬1 小时前
高效目标检测利器:X-AnyLabeling 加载自定义 YOLO 模型自动标注实操指南
人工智能·yolo·目标检测