From eea47c4a85717e373e18023c86c16341277fe336 Mon Sep 17 00:00:00 2001 From: march3 Date: Sun, 23 Mar 2025 10:28:06 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mkv_2_mp4.py | 34 +++++++++++++++++++++++++++++ simulators/mpl_2d_simulator.py | 39 +++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 mkv_2_mp4.py diff --git a/mkv_2_mp4.py b/mkv_2_mp4.py new file mode 100644 index 0000000..73cc0a4 --- /dev/null +++ b/mkv_2_mp4.py @@ -0,0 +1,34 @@ +import os +import subprocess + + +def get_exists_files(output_dir): + return [i[:-2] + "kv" for i in os.listdir(output_dir)] + + +def convert_mkv_to_mp4(input_dir, output_dir): + # 确保输出目录存在 + os.makedirs(output_dir, exist_ok=True) + + exists_files = get_exists_files(output_dir) + + # 遍历输入目录中的所有文件 + for filename in os.listdir(input_dir): + if filename in exists_files: + continue + + if filename.endswith('.mkv'): + input_file = os.path.join(input_dir, filename) + output_file = os.path.join(output_dir, filename[:-4] + '.mp4') + + # 使用 ffmpeg 进行转换 + command = ['ffmpeg', '-i', input_file, output_file] + subprocess.run(command) + + print(f'Converted: {input_file} to {output_file}') + + +# 使用示例 +input_directory = r'E:\琅琊榜mkv' # 替换为你的输入目录 +output_directory = r'D:\琅琊榜' # 替换为你的输出目录 +convert_mkv_to_mp4(input_directory, output_directory) diff --git a/simulators/mpl_2d_simulator.py b/simulators/mpl_2d_simulator.py index 084e545..f5b2958 100644 --- a/simulators/mpl_2d_simulator.py +++ b/simulators/mpl_2d_simulator.py @@ -73,17 +73,36 @@ class 星球: self.轨迹.pop(0) -# 创建星球列表 -星球列表 = [ - 星球(质量=1e12, 位置=[0, 0], 速度=[0, 1], 颜色='red', 名称="太阳", 名称偏移=[2, 0]), - 星球(质量=1e9, 位置=[10, 0], 速度=[0, 2], 颜色='blue', 名称="蓝星"), - 星球(质量=1e9, 位置=[-10, 0], 速度=[0, -2], 颜色='green', 名称="绿星") -] - # 初始化图形 图形, 坐标轴 = plt.subplots() -坐标轴.set_xlim(-50, 50) -坐标轴.set_ylim(-20, 80) +星球列表 = [] + + +def 场景1(): + global 星球列表 + # 创建星球列表 + 星球列表 = [ + 星球(质量=1e12, 位置=[0, 0], 速度=[0, 1], 颜色='red', 名称="太阳", 名称偏移=[2, 0]), + 星球(质量=1e9, 位置=[10, 0], 速度=[0, 2], 颜色='blue', 名称="蓝星"), + 星球(质量=1e9, 位置=[-10, 0], 速度=[0, -2], 颜色='green', 名称="绿星") + ] + 坐标轴.set_xlim(-50, 50) + 坐标轴.set_ylim(-20, 80) + + +def 场景2(): + global 星球列表 + 星球列表 = [ + 星球(质量=1e12, 位置=[10, 0], 速度=[0, 1], 颜色='blue', 名称="蓝星", 名称偏移=[2, 0]), + 星球(质量=1e12, 位置=[-10, 0], 速度=[0, -1], 颜色='green', 名称="绿星", 名称偏移=[2, 0]) + ] + 坐标轴.set_xlim(-50, 50) + 坐标轴.set_ylim(-50, 50) + + +# 场景1() +场景2() + # 调整边距 plt.subplots_adjust(left=0.05, bottom=0.04, right=0.97, top=0.97, wspace=0.4, hspace=0.4) 点列表 = [坐标轴.plot([], [], 'o', color=星球.颜色, markersize=星球.大小)[0] for 星球 in 星球列表] @@ -129,4 +148,4 @@ def 更新(帧): 动画 = FuncAnimation(图形, 更新, frames=range(1000), init_func=初始化, blit=True, interval=2) # 显示动画 -plt.show() \ No newline at end of file +plt.show() -- GitLab