随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

代码

 

复制代码
import subprocess
import os
def get_all_mp4_files(directory):
    """获取指定文件夹下所有的MP4文件"""
    mp4_files = []
    # 遍历指定目录及其子目录中的文件
    for root, dirs, files in os.walk(directory):
        for file in files:
            # 检查文件扩展名是否为.mp4
            if file.lower().endswith('.mp4'):
                # 将文件的完整路径添加到列表中
                mp4_files.append(os.path.join(root, file))
    return mp4_files





def ffmpeg_crop(input_path, output_path, width, height, x, y):
    # 构建ffmpeg命令
    cmd = [
        'ffmpeg',
        '-i', input_path,
        '-filter:v', f'crop={width}:{height}:{x}:{y}',  # 注意这里的参数顺序
        '-c:a', 'copy',  # 确保-c:a后面紧跟的是copy,而不是output_path
        output_path
    ]

    # 执行ffmpeg命令
    subprocess.run(cmd, check=True)





# 要裁剪的视频文件路径
genmulu = r"F:\陈惟\blender\blender材质篇\yuan"
video_list = get_all_mp4_files(directory=genmulu)

for one in video_list:

    x1 = 240  # 裁剪区域左上角的x坐标
    y1 = 0  # 裁剪区域左上角的y坐标
    x2 = 1680  # 裁剪区域右下角的x坐标
    y2 = 1080  # 裁剪区域右下角的y坐标
    # 要裁剪的视频文件路径
    video_path = one
    # 裁剪后的视频文件路径
    output_path = r'%s.caiqiehou.mp4'% str(one)

    # 定义裁剪区域的宽度和高度
    crop_width = x2 - x1  # 裁剪区域的宽度
    crop_height = y2 - y1  # 裁剪区域的高度

    # 使用示例
    ffmpeg_crop(video_path, output_path, crop_width, crop_height, x1, y1)
复制代码

 

posted on   大话人生  阅读(126)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2023-04-21 chatgpt插件
2023-04-21 自媒体网址
2022-04-21 pytest之数据驱动-6
2020-04-21 centos设置笔记本盒盖依然正常
2020-04-21 u盘安装contos8
2020-04-21 pycharm git更新问题
点击右上角即可分享
微信分享提示