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

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

复制代码
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 分钟前
视频增强技术解析
人工智能·目标检测·机器学习·计算机视觉·超分辨率重建
魔乐社区17 分钟前
GLM-5上线魔乐社区,基于昇腾的模型推理+训练部署教程请查收!
人工智能·开源·大模型
geneculture43 分钟前
化繁为简且以简驭繁:唯文论英汉对照哲学术语49个主义/论
人工智能·融智学的重要应用·哲学与科学统一性·信息融智学·融智时代(杂志)
睡醒了叭1 小时前
coze-工作流-http请求
人工智能·aigc
twilight_4692 小时前
机器学习与模式识别——机器学习中的搜索算法
人工智能·python·机器学习
冰西瓜6002 小时前
深度学习的数学原理(十)—— 权重如何自发分工
人工智能·深度学习·计算机视觉
niuniudengdeng2 小时前
基于时序上下文编码的端到端无文本依赖语音分词模型
人工智能·数学·算法·概率论
Soonyang Zhang3 小时前
flashinfer attention kernel分析
人工智能·算子·推理框架
林籁泉韵73 小时前
2026年GEO服务商推荐:覆盖多场景适配,助力企业AI时代增长
人工智能
Sinosecu-OCR3 小时前
释放数字化力量:智能OCR识别如何重塑现代办公效率
大数据·人工智能