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

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

复制代码
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)
相关推荐
13线2 小时前
为什么要合并飞书和豆包
人工智能·飞书·火山引擎·豆包
wangqiaowq2 小时前
AI智能体学习
人工智能
科创致远2 小时前
科创致远 eSOP 电子作业指导书系统落地应用指南
大数据·人工智能·汽车·制造·精益工程
宅小年2 小时前
让 AI 用上你的资料,RAG 是怎么做到的?
人工智能
宅小年2 小时前
为什么你的 AI 越聊越“笨”,还越来越慢?
人工智能
宅小年2 小时前
AI 技能地图
人工智能
宅小年3 小时前
DeepSeek Harness 的插件,到底该怎么用?
人工智能
仙魁XAN3 小时前
【WorkBuddy · 三件套:技能/专家/技能】第 17 章 · 配置 MCP 服务器
人工智能·workbuddy·workbuddy三件套·mcp 配置与使用
无忧.芙桃3 小时前
AI 生产力工具实践(四):豆包如何成为日常学习与写作助手
人工智能
IT_陈寒3 小时前
Python的GIL把我坑惨了,多线程跑得比单线程还慢
前端·人工智能·后端