Commit e1cf50e4 by xiaoqi

高度为8的倍数

parent bb769164
Showing with 38 additions and 7 deletions
......@@ -257,15 +257,22 @@ def webp2png(webp_file, dir_file, target_width=None):
if target_width < 8: # 确保宽度至少为 8
target_width = 8
# 对于高度,我们也应用同样的逻辑
target_height = (height // 8) * 8 # 向下取整到最近的 8 的倍数
if target_height < 8: # 确保高度至少为 8
target_height = 8
# 如果目标宽度大于原图宽度,添加透明背景居中
if target_width > width:
new_frame = Image.new("RGBA", (target_width, height), (0, 0, 0, 0))
offset = (target_width - width) // 2
new_frame.paste(frame, (offset, 0))
if target_width > width or target_height > height:
new_frame = Image.new("RGBA", (target_width, target_height), (0, 0, 0, 0))
offset_x = (target_width - width) // 2
offset_y = (target_height - height) // 2
new_frame.paste(frame, (offset_x, offset_y))
frame = new_frame
# 如果目标宽度小于原图宽度,裁剪图片
elif target_width < width:
frame = frame.crop(((width - target_width) // 2, 0, (width + target_width) // 2, height))
else:
# 调整宽度和高度
frame = frame.crop(((width - target_width) // 2, (height - target_height) // 2,
(width + target_width) // 2, (height + target_height) // 2))
# 构造保存路径
frame_path = os.path.join(dir_file, f"frame_{i:03d}.png")
......
import os
from moviepy import VideoFileClip
def check_mp4_height(directory):
# 遍历给定目录下的所有文件
for filename in os.listdir(directory):
if filename.endswith(".mp4"):
filepath = os.path.join(directory, filename)
try:
# 使用VideoFileClip读取视频文件
with VideoFileClip(filepath) as video:
# 获取视频的高度
height = video.size[1]
# 检查高度是否为偶数
if height % 2 != 0:
print(f"文件名: {filename}, 高度: {height} (不是偶数)")
except Exception as e:
print(f"无法处理文件 {filename}: {e}")
if __name__ == '__main__':
# 用户输入目录路径
mp4_directory = input("请输入MP4文件所在的目录:")
check_mp4_height(mp4_directory)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment