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

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

复制代码
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)
相关推荐
数智工坊4 分钟前
RealNet:用于异常检测的特征选择网络,具备真实的合成异常样本
人工智能·深度学习
阳明山水14 分钟前
TimesFM与Moirai MoE零样本预测解析
人工智能·深度学习·算法·机器学习·架构
在世修行15 分钟前
第24篇:PyInstaller打包实战 — 从Python脚本到Windows EXE
人工智能·python·pyinstaller
一次旅行20 分钟前
AI 前沿日报 | 2026年07月14日
人工智能
智慧物业老杨23 分钟前
物业单盘精细化预算数智化方案:IoT采集+AI建模全链路自动化落地体系
人工智能·物联网·自动化
xn713338 分钟前
别再把 MCP Roots 当安全沙箱:一个符号链接就能逃逸目录
人工智能·后端·mcp
Nturmoils42 分钟前
不自己造轮子:在小艺开放平台搭一个真实的健康小助手
人工智能
statistican_ABin44 分钟前
中国城市 PM2.5较高浓度风险识别
人工智能
茶马古道的搬运工1 小时前
AI 深度技能之-解读Multica(一)- 让Agent 变成真·队友
人工智能
YOLO数据集集合1 小时前
自动驾驶道路视觉开源数据集TT100K工程化使用文档|道路标识目标检测资源|开源数据集分享
人工智能·目标检测·自动驾驶