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

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

复制代码
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)
相关推荐
oak隔壁找我8 分钟前
一款运行在 DSH(DeepSeek Harness)中的 Redis 管理插件
人工智能
孟健21 分钟前
一个人做的免费AI工具,月访问千万的选品与技术拆解
人工智能·aigc
乌鲁木齐德润恒圣信息科技有限公司2 小时前
GEO生成式引擎优化:技术原理与43引擎自动测试系统
大数据·前端·人工智能
SelectDB3 小时前
SelectDB 和阿里云 SelectDB 有什么区别?公司关系、产品版本与部署方式详解
人工智能
SelectDB3 小时前
什么是 AI Agent 数据库?SelectDB 如何构建 Agent Native 实时分析基座
人工智能
严肃小白兔3 小时前
第 14/24 期:正则化方法及其对神经网络的影响
人工智能·神经网络·机器学习
江润舟3 小时前
万物|炼器:从零手搓工业级旋转目标检测网络·卷7 —— OBB检测头与DFL解码(三)
人工智能·python·深度学习
峯5804 小时前
清华博士90分钟AI与神经网络-内容梳理
人工智能
AI创界者4 小时前
Python 进阶实战(五十六):KV Cache 驱逐闭环反馈与 Prefill / Decode 分离协同调度
人工智能·python·aigc
乌鲁木齐德润恒圣信息科技有限公司4 小时前
43引擎自动测试系统:GEO工程化怎么按月迭代
人工智能