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

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

复制代码
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)
相关推荐
NeoGressAI外贸数字化31 分钟前
IOR新规9月18日生效:Form 5106六项资料自查清单
人工智能
根目录下的猫1 小时前
RK3588适配的轻量级AI模型推荐
人工智能·后端·python·目标检测
weixin_6681 小时前
Cursor 插件使用说明:Linear 与 Figma
人工智能·cursor
wshzd2 小时前
LLM之Agent(六十八)|PI(七)构建测试与开发流程
人工智能
H0311169852 小时前
App竞品数据平台功能梳理:月狐数据、七麦数据、点点数据
人工智能
YOLO数据集集合2 小时前
高铁轨道紧固件损坏检测数据集 | 高铁巡检 紧固件缺陷 轨道安全9093期
人工智能·目标检测·计算机视觉·目标跟踪·轨道·铁轨紧固件·铁轨
冬奇Lab2 小时前
一天一个开源项目(第223篇):TeamAI-CLI —— 腾讯开源的团队级 AI Agent 中间层,让每个人的 AI 能力变成团队共享能力
人工智能·开源·资讯
ShineWinsu2 小时前
对于Coze—AI:SDK的解析
人工智能·python·ai·sdk·项目·coze·字节跳动
代码方舟2 小时前
零信任架构实战:基于天远名下企业A构建自动化B2B供应链准入网关
人工智能·ai·工具分享
IvorySQL2 小时前
IvorySQL 5.6 发布:PG 18.6 内核升级,沙盒即开即用
数据库·人工智能·postgresql