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

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

复制代码
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)
相关推荐
MartinYeung54 分钟前
[论文分析]使大型语言模型智能体与理性和道德偏好对齐:一种监督微调方法
人工智能·机器学习·语言模型
AI服务老曹5 分钟前
车牌识别算法接入AI视频分析平台的流程和误报优化
人工智能·算法·音视频
GrowthRadar7 分钟前
CNC柔性自动化工程验收标准:专业协作机器人集成商的四大核心技术能力
人工智能·机器人·自动化
a1117769 分钟前
MuJoCo 机械臂仿真快速入门指南+文档
人工智能·开源
微三云生态系统架构师-彭丹18 分钟前
排队免单风控系统设计:四层防套利机制与异常交易检测
人工智能
似水流年QC18 分钟前
什么是 Skill?深入理解 AI Agent Skill 的工作原理与应用实践
人工智能·agent·skill
Zguigo21 分钟前
【DL】LSTM|Cell State|三个门
人工智能·rnn·lstm
LadiesAndGentlemen28 分钟前
GeoX 论文解读:不用人工标注,如何训练会空间推理的遥感大模型
人工智能·深度学习·机器学习
水管在开花.29 分钟前
Agent范式与LangGraph④-零基础保姆级教程
人工智能·agent·rag