- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python基于mediainfo批量重命名图片文件由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
大部分带彩色屏幕的终端设备,不管是手机,车机,电视等等,都需要涉及图片的显示.
作为一名专业的多媒体测试人员,我们需要一堆的规范化标准的图片测试文件, 但是现有的图片资源名字命名的很随意比如:img_20200325_161111.jpg, 以上命名不能看出图片文件的具体图片编码格式,分辨率等信息, 测试经理要求我进行批量重命名工作,模板如下, 图片编码格式_分辨率_位深度_容器.容器, 例如: jpeg_1920x1080_32bit_jpg.jpg 。
图片编码:将某各风景画面取景转成图片数据文件的过程,取景肯定涉及取景的范围, 图片解码:将图片数据文件显示到屏幕上的过程.
主要涉及以下技术参数
。
图片技术参数 | 参数释义 | 举例 |
---|---|---|
图片编码格式 (压缩技术) |
即像素点压缩的一类技术, 不同的编码格式, 其压缩率与压缩效果不一样。 |
jpeg, png, gif, bmp, webp, raw, heic |
图片分辨率 (单位:pixel) |
图片长像素点的数量*图片宽像素点的数量 | 4096×2160(4k), 1920x1080, 1280x720,720×480, 640x480, 320x480等 甚至10亿像素的图片都存在的。 |
位深度 (单位:bit) |
每个像素点所包含的数据量的大小 | 8bit, 16bit, 32bit |
图片容器 | 文件后缀,将图片像素点封装的一种文件格式 | .jpg; .png; .gif; .bmp; .heic; .webp等 |
。
我们碰到的任何图片文件,都是数据的集合, 一般数据越大,其图片越清晰.
1
2
3
4
5
6
7
8
9
10
|
+
-
-
-
input_image
#批量放入待命名的图片文件
|
1.jpg
|
2.png
|
+
-
-
-
output_image
#批量输出已命名的图片文件
| jpeg_1920x1080_32bit_jpg.jpg
| png_1280x720_32bit_png.png
|
\image_info.py
# 获取图片文件info信息的模块,
\rename_image.py
#调用image_info.py并实现重名,可双击运行
|
由于涉及较复杂的代码,建议直接用面向对象类的编程方式实现:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# coding=utf-8
import
os
import
re
import
subprocess
class
imageinfogetter():
'''获取图片文件的formate, 分辨率,位深度'''
def
__init__(
self
, image_file):
'''判断文件是否存在,如果存在获取其mediainfo信息'''
if
os.path.exists(image_file):
self
.image_file
=
image_file
p_obj
=
subprocess.popen(
'mediainfo "%s"'
%
self
.image_file, shell
=
true, stdout
=
subprocess.pipe,
stderr
=
subprocess.pipe)
self
.info
=
p_obj.stdout.read().decode(
"utf-8"
)
# 解决非英文字符的编码问题
else
:
raise
filenotfounderror(
"not this file!"
)
# 如果多媒体文件路径不存在,必须中断
def
get_image_format(
self
):
'''获取图片的格式,比如jpeg, png, bmp等'''
try
:
image_codec
=
re.findall(r
"format\s+:\s(.*)"
,
self
.info)[
-
1
]
# 取第最后一个format字段
image_codec
=
image_codec.strip()
# 去除前后的空格
if
image_codec
=
=
"rgb"
:
image_codec
=
"bmp"
except
:
image_codec
=
"undef"
# 防止程序因为异常而中断
return
image_codec
def
get_image_resolution(
self
):
'''获取图片的分辨率'''
try
:
image_widget
=
re.findall(r
'width\s+:\s(.*)pixels'
,
self
.info)[
-
1
]
image_widget
=
image_widget.replace(
" "
, "")
image_height
=
re.findall(r
'height\s+:\s(.*)pixels'
,
self
.info)[
-
1
]
image_height
=
image_height.replace(
" "
, "")
image_resolution
=
image_widget
+
"x"
+
image_height
except
:
image_resolution
=
"undef"
# 防止程序因为异常而中断
return
image_resolution
def
get_image_bit_depth(
self
):
'''获取图片的位深度'''
try
:
image_bit_depth
=
re.findall(r
"bit depth\s+:\s(.*bit)s"
,
self
.info)[
-
1
].strip()
image_bit_depth
=
image_bit_depth.replace(
" "
, "")
# 去空格
except
:
image_bit_depth
=
"undef"
# 防止程序因为异常而中断
return
image_bit_depth
def
get_image_container(
self
):
'''获取图片容器,即文件后缀名'''
_, image_container
=
os.path.splitext(
self
.image_file)
if
not
image_container:
raise
nameerror(
"this file no extension"
)
image_container
=
image_container.replace(
"."
, "")
image_container
=
image_container.lower()
# 全部转成小写
return
image_container
if
__name__
=
=
'__main__'
:
# 以下代码块,只是用来测试本模块的,一般不建议直接在这里大面积调用本模块'''
i_obj
=
imageinfogetter(
"c:\\img.jpg"
)
image_format
=
i_obj.get_image_format()
print
(image_format)
image_resolution
=
i_obj.get_image_resolution()
print
(image_resolution)
image_bit_depth
=
i_obj.get_image_bit_depth()
print
(image_bit_depth)
image_container
=
i_obj.get_image_container()
print
(image_container)
|
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
32
33
34
35
36
|
# coding=utf-8
import
os
import
image_info
from
shutil
import
copyfile
curdir
=
os.getcwd()
# 输入文件夹,放入待重命名的图片
input_image_path
=
os.path.join(curdir,
"input_image"
)
filelist
=
os.listdir(input_image_path)
# 获取文件列表
# 输出文件夹,已命名的图片存放在这里
output_image_path
=
os.path.join(curdir,
"output_image"
)
# 如果没有output_image这个文件夹,则创建这个文件夹
if
not
os.path.exists(output_image_path):
os.mkdir(output_image_path)
if
filelist:
# 如果文件列表不为空
for
i
in
filelist:
# 遍历文件列表
# 以下代码块,只是用来测试本模块的,一般不建议直接在这里大面积调用本模块'''
image_file
=
os.path.join(input_image_path, i)
i_obj
=
image_info.imageinfogetter(image_file)
image_format
=
i_obj.get_image_format()
image_resolution
=
i_obj.get_image_resolution()
image_bit_depth
=
i_obj.get_image_bit_depth()
image_container
=
i_obj.get_image_container()
new_image_name
=
image_format
+
"_"
+
image_resolution
+
"_"
+
image_bit_depth
+
"_"
\
+
image_container
+
"."
+
image_container
print
(new_image_name)
new_image_file
=
os.path.join(output_image_path, new_image_name)
copyfile(image_file, new_image_file)
# 复制文件
else
:
print
(
"it's a empty folder, please input the image files which need to be renamed firstly!!!"
)
os.system(
"pause"
)
|
包含:mediainfo.exe(更建议丢到某个环境变量里去), 各种编码格式的图片文件,image_info.py模块,rename_image.py批处理脚本 运行效果如下:
以上可以看出,输入输出文件架构的好处, 我只需要将不同名字不同字符的, 待重命名的图片丢到input_image文件夹下,运行程序脚本后查看output_image输出文件, 就可以测试脚本的运行是否正常,健壮性(容错)是否符合要求,从而对这个程序脚本实现了“灰盒测试”.
比如android手机,google推出了cdd(compatibiltiy definition document兼容性定义文档), 。
其第5部分,涉及了很多图片编解码格式的规定:
这就是android最主要的图片多媒体编解码测试需求.
以上就是python基于mediainfo批量重命名图片文件的详细内容,更多关于python 批量重命名文件的资料请关注我其它相关文章! 。
原文链接:https://www.zipython.com/#/detail?id=83bc5c1566104f5da17baa22f25390b6 。
最后此篇关于Python基于mediainfo批量重命名图片文件的文章就讲到这里了,如果你想了解更多关于Python基于mediainfo批量重命名图片文件的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
今天我在一个 Java 应用程序中看到了几种不同的加载文件的方法。 文件:/ 文件:// 文件:/// 这三个 URL 开头有什么区别?使用它们的首选方式是什么? 非常感谢 斯特凡 最佳答案 file
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 javascript 文件,并且在该方法中有一个“测试”方法,我喜欢调用 C# 函数。 c# 函数与 javascript 文件不在同一文件中。 它位于 .cs 文件中。那么我该如何管理 j
需要检查我使用的文件/目录的权限 //filePath = path of file/directory access denied by user ( in windows ) File fil
我在一个目录中有很多 java 文件,我想在我的 Intellij 项目中使用它。但是我不想每次开始一个新项目时都将 java 文件复制到我的项目中。 我知道我可以在 Visual Studio 和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有 3 个组件的 Twig 文件: 文件 1: {# content-here #} 文件 2: {{ title-here }} {# content-here #}
我得到了 mod_ldap.c 和 mod_authnz_ldap.c 文件。我需要使用 Linux 命令的 mod_ldap.so 和 mod_authnz_ldap.so 文件。 最佳答案 从 c
我想使用PIE在我的项目中使用 IE7。 但是我不明白的是,我只能在网络服务器上使用 .htc 文件吗? 我可以在没有网络服务器的情况下通过浏览器加载的本地页面中使用它吗? 我在 PIE 的文档中看到
我在 CI 管道中考虑这一点,我应该首先构建和测试我的应用程序,结果应该是一个 docker 镜像。 我想知道使用构建环境在构建服务器上构建然后运行测试是否更常见。也许为此使用构建脚本。最后只需将 j
using namespace std; struct WebSites { string siteName; int rank; string getSiteName() {
我是 Linux 新手,目前正在尝试使用 ginkgo USB-CAN 接口(interface) 的 API 编程功能。为了使用 C++ 对 API 进行编程,他们提供了库文件,其中包含三个带有 .
我刚学C语言,在实现一个程序时遇到了问题将 test.txt 文件作为程序的输入。 test.txt 文件的内容是: 1 30 30 40 50 60 2 40 30 50 60 60 3 30 20
如何连接两个tcpdump文件,使一个流量在文件中出现一个接一个?具体来说,我想“乘以”一个 tcpdump 文件,这样所有的 session 将一个接一个地按顺序重复几次。 最佳答案 mergeca
我有一个名为 input.MP4 的文件,它已损坏。它来自闭路电视摄像机。我什么都试过了,ffmpeg , VLC 转换,没有运气。但是,我使用了 mediainfo和 exiftool并提取以下信息
我想做什么? 我想提取 ISO 文件并编辑其中的文件,然后将其重新打包回 ISO 文件。 (正如你已经读过的) 我为什么要这样做? 我想开始修改 PSP ISO,为此我必须使用游戏资源、 Assets
给定一个 gzip 文件 Z,如果我将其解压缩为 Z',有什么办法可以重新压缩它以恢复完全相同的 gzip 文件 Z?在粗略阅读了 DEFLATE 格式后,我猜不会,因为任何给定的文件都可能在 DEF
我必须从数据库向我的邮件 ID 发送一封带有附件的邮件。 EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Adventure Works Admin
我有一个大的 M4B 文件和一个 CUE 文件。我想将其拆分为多个 M4B 文件,或将其拆分为多个 MP3 文件(以前首选)。 我想在命令行中执行此操作(OS X,但如果需要可以使用 Linux),而
快速提问。我有一个没有实现文件的类的项目。 然后在 AppDelegate 我有: #import "AppDelegate.h" #import "SomeClass.h" @interface A
我是一名优秀的程序员,十分优秀!