Python 官方文档:入门教程 => 点击学习
在平时的工作中,我们的目录有很多的视频文件,如果你没有一个好的视频分类习惯,在找视频素材的时候会很费时,通过对视频的分辨路进行分类可以在需要的时候快速找到你想要的视频分辨率。当然人工
在平时的工作中,我们的目录有很多的视频文件,如果你没有一个好的视频分类习惯,在找视频素材的时候会很费时,通过对视频的分辨路进行分类可以在需要的时候快速找到你想要的视频分辨率。当然人工去分类是一种比较费时费力的工作,通过软件也好,程序也罢都是为了可以提高我们的工作效率。
代码分享
import os
import subprocess
import JSON
import shutil
import datetime
def get_files(file_dir):
for root, dirs, files in os.walk(file_dir):
if len(files) > 0:
# 获取图片路径
for f in files:
if f.endswith(".mp4"):
p = os.path.join(root, f)
h, w, t = get_video_info(p)
new_dir = os.path.realpath(
"{}\{}x{}".fORMat(file_dir, h, w))
if not os.path.exists(new_dir):
os.makedirs(new_dir)
shutil.move(p, os.path.join(new_dir, "{}.mp4".format(t)))
def get_video_info(file_path):
cmd = "ffprobe -v quiet -print_format json -show_streams -i {}".format(
file_path)
with open('output.json', 'w') as f:
subprocess.call(cmd, stdout=f)
with open('output.json', 'r') as f:
streams = json.load(f)
for i in streams["streams"]:
if i['codec_type'] == "video":
print(file_path)
t2 = ""
try:
t1 = datetime.datetime.strptime(
i['tags']['creation_time'], "%Y-%m-%dT%H:%M:%S.%f%z")
t2 = datetime.datetime.strftime(t1, '%Y%m%d%H%M%S')
except KeyError:
t2 = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return i['height'], i['width'], t2
else:
continue
if __name__ == "__main__":
file_dir = input("dir:")
get_files(file_dir)
代码使用了ffprobe
获取视频信息
原文:Http://www.rencaixiu.cn/arcHives/811/
到此这篇关于使用python对视频文件分辨率进行分组的文章就介绍到这了,更多相关Python视频文件分辨率分组内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: 使用python对视频文件分辨率进行分组的实例代码
本文链接: https://www.lsjlt.com/news/154651.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0