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

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

复制代码
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)
相关推荐
Tutankaaa1 分钟前
知识竞赛题库设计全攻略
人工智能·算法
TImCheng06099 分钟前
职场人AI学习周期评估:不同学习路径的时间成本
人工智能·学习
m0_4665252924 分钟前
酷特AGI:从“自家试验田”到“全球输出”
大数据·人工智能·agi
星爷AG I25 分钟前
20-1 记忆概览(AGI基础理论)
人工智能·agi
锕琅26 分钟前
OpenAI Codex使用教程-GPT功能配置
人工智能·gpt·codex
鹏子训29 分钟前
AI记忆新思路:用SQLite替代向量数据库,去EMBEDDINGS化,谷歌开源Google Always On Memory Agent
数据库·人工智能·sqlite·embedding
xyz59931 分钟前
ONNX Runtime(ORT) C++ Windows 深度学习模型部署简易教程
人工智能·深度学习
市象31 分钟前
AI带给TCL空调的头部假想
大数据·人工智能
武汉知识图谱科技41 分钟前
国家首次探索“词元交易”:大模型时代的知识产权困境与知识图谱的“价值锚定”机会
人工智能·知识图谱
实在智能RPA1 小时前
金融行业财务审核自动化工具推荐:2026企业级AI Agent与智能合规选型指南
人工智能·ai·金融·自动化