Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
xiaoqi
/
mp4giftconvert
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e1cf50e4
authored
2 weeks ago
by
xiaoqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
高度为8的倍数
parent
bb769164
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
7 deletions
convert_webp_2_mp4.py
mp4_height_wrong.py
convert_webp_2_mp4.py
View file @
e1cf50e4
...
@@ -257,15 +257,22 @@ def webp2png(webp_file, dir_file, target_width=None):
...
@@ -257,15 +257,22 @@ def webp2png(webp_file, dir_file, target_width=None):
if
target_width
<
8
:
# 确保宽度至少为 8
if
target_width
<
8
:
# 确保宽度至少为 8
target_width
=
8
target_width
=
8
# 对于高度,我们也应用同样的逻辑
target_height
=
(
height
//
8
)
*
8
# 向下取整到最近的 8 的倍数
if
target_height
<
8
:
# 确保高度至少为 8
target_height
=
8
# 如果目标宽度大于原图宽度,添加透明背景居中
# 如果目标宽度大于原图宽度,添加透明背景居中
if
target_width
>
width
:
if
target_width
>
width
or
target_height
>
height
:
new_frame
=
Image
.
new
(
"RGBA"
,
(
target_width
,
height
),
(
0
,
0
,
0
,
0
))
new_frame
=
Image
.
new
(
"RGBA"
,
(
target_width
,
target_height
),
(
0
,
0
,
0
,
0
))
offset
=
(
target_width
-
width
)
//
2
offset_x
=
(
target_width
-
width
)
//
2
new_frame
.
paste
(
frame
,
(
offset
,
0
))
offset_y
=
(
target_height
-
height
)
//
2
new_frame
.
paste
(
frame
,
(
offset_x
,
offset_y
))
frame
=
new_frame
frame
=
new_frame
# 如果目标宽度小于原图宽度,裁剪图片
else
:
elif
target_width
<
width
:
# 调整宽度和高度
frame
=
frame
.
crop
(((
width
-
target_width
)
//
2
,
0
,
(
width
+
target_width
)
//
2
,
height
))
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"
)
frame_path
=
os
.
path
.
join
(
dir_file
,
f
"frame_{i:03d}.png"
)
...
...
This diff is collapsed.
Click to expand it.
mp4_height_wrong.py
0 → 100644
View file @
e1cf50e4
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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment