Share

HEVC批量转成MP4

当前目录

import os
import subprocess

def convert_mov_to_mp4(source_directory, output_directory):
    # 确保输出目录存在
    if not os.path.exists(output_directory):
        os.makedirs(output_directory)
    
    # 遍历指定目录下的所有文件
    for filename in os.listdir(source_directory):
        if filename.endswith(".MOV"):
            # 构建完整的文件路径
            file_path = os.path.join(source_directory, filename)
            # 构建输出文件的路径
            output_path = os.path.join(output_directory, filename.replace(".MOV", ".mp4"))
            
            # 构建ffmpeg命令
            command = [
                'ffmpeg',
                '-i', file_path,  # 输入文件
                '-c:v', 'libx264',   # 复制视频流
                '-crf', '0',    # 使用AAC编码音频
                '-y',
                output_path       # 输出文件
            ]
            
            # 执行命令
            try:
                subprocess.run(command, check=True)
                print(f"Converted {file_path} to {output_path}")
            except subprocess.CalledProcessError as e:
                print(f"Failed to convert {file_path}: {e}")

# 指定要处理的源目录
source_directory = '.'
# 指定输出目录
output_directory = 'h264_videos'
convert_mov_to_mp4(source_directory, output_directory)
pip uninstalll numpy
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package numpy==1.23.0
import os
import subprocess

# 指定您的目录路径
directory = '.'

# 遍历目录下的所有文件
for filename in os.listdir(directory):
    if filename.endswith('.mp4'):
        file_path = os.path.join(directory, filename)
        # 应用Auto-Editor命令
        subprocess.run(['auto-editor', file_path, '--edit', 'motion', '--margin', '0.2s'])