Skip to content

Commit bddbc22

Browse files
author
peiss
committed
'xx'
1 parent 453dae9 commit bddbc22

3 files changed

Lines changed: 298 additions & 0 deletions

File tree

2020-08-12 Python自动整理文件夹/mytest.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## 怎样批量统计视频的总时长\n",
8+
"\n",
9+
"环境依赖\n",
10+
"\n",
11+
"#### 1、安装python包\n",
12+
"\n",
13+
"pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ffmpeg-python\n",
14+
"\n",
15+
"#### 2、下载windows的exe可执行文件\n",
16+
"\n",
17+
"https://web.archive.org/web/20200918193047/https://ffmpeg.zeranoe.com/builds/\n",
18+
"\n",
19+
"下载后解压,记住解压路径"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 47,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"import os\n",
29+
"import ffmpeg"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 48,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"dir_path = \"G:/2020-11-16 高顿教育/01. 零基础入门学Python\"\n",
39+
"ffprobe_exe_path = \"D:/software/ffmpeg-20200831-4a11a6f-win64-static/bin/ffprobe.exe\""
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 50,
45+
"metadata": {
46+
"scrolled": false
47+
},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
"01.为什么选择学习python.mp4\n",
54+
"02.Python的学习大纲.mp4\n",
55+
"03.Python简介和版本选择.mp4\n",
56+
"04.Python在各个系统的安装.mp4\n",
57+
"05.命令行下执行Python代码.mp4\n",
58+
"06.命令行下执行Python文件.mp4\n",
59+
"07.Python最好用的编辑器Pycharm.mp4\n",
60+
"08.Python的打印和缩进和注释.mp4\n",
61+
"09.Python基本数据类型和变量.mp4\n",
62+
"10.Python的算数和逻辑运算符.mp4\n",
63+
"11.Python的if语句.mp4\n",
64+
"12.Python的for循环.mp4\n",
65+
"13.Python的while循环.mp4\n",
66+
"14.Python的break和continue关键字.mp4\n",
67+
"15.Python读写文件的方法.mp4\n",
68+
"16.Python的字符串知识点讲解.mp4\n",
69+
"17.Python的列表的索引和切片操作.mp4\n",
70+
"18.Python的列表支持的函数.mp4\n",
71+
"19.Python的列表推导式.mp4\n",
72+
"20.Python的元组Tuple.mp4\n",
73+
"21.Python的元组和列表的区别.mp4\n",
74+
"22.Python的字典dict的基础知识.mp4\n",
75+
"23.Python的字典的常用方法.mp4\n",
76+
"24.Python的字典的数据统计案例.mp4\n",
77+
"25.Python的集合set.mp4\n",
78+
"26.Python的集合set的实际案例.mp4\n",
79+
"27.Python高级数据结构的总结对比.mp4\n",
80+
"28.Python实战计算PV和UV第1部分.mp4\n",
81+
"29.Python实战计算PV和UV第2部分.mp4\n",
82+
"30.Python代码的组织结构.mp4\n",
83+
"31.Python的函数的基础知识.mp4\n",
84+
"32.Python的函数的代码演示.mp4\n",
85+
"33.Python使用函数重构PVUV实例代码.mp4\n",
86+
"34.Python的lambda函数和列表的排序.mp4\n",
87+
"35.Python的类的知识和演示.mp4\n",
88+
"36.Python的类知识的实际案例.mp4\n",
89+
"37.Python的异常的基本知识.mp4\n",
90+
"38.Python模拟处理爬虫的异常.mp4\n",
91+
"39.Python的包和模块的基础知识.mp4\n",
92+
"40.Python的常见模块介绍.mp4\n",
93+
"41.Python的开源模块的安装方法.mp4\n",
94+
"42.Python的sys和os模块.mp4\n",
95+
"43.Python的sys和os模块整理文件夹.mp4\n",
96+
"44.Python的json模块.mp4\n",
97+
"45.Python使用flask开发web应用程序.mp4\n",
98+
"46.Python的http爬虫库requests.mp4\n",
99+
"47.Python使用PyMySQL模块操作MySQL.mp4\n",
100+
"48.Python使用xlwt模块生成excel.mp4\n",
101+
"49.Python使用multiprocessing模块开发多进程程序.mp4\n",
102+
"50.Python课程最后的总结.mp4\n",
103+
"308.3598722166666\n"
104+
]
105+
}
106+
],
107+
"source": [
108+
"total_duration = 0.0\n",
109+
"for fname in os.listdir(dir_path):\n",
110+
" if not fname.endswith(\".mp4\"):\n",
111+
" continue\n",
112+
" fpath = f\"{dir_path}/{fname}\"\n",
113+
" print(fname)\n",
114+
" info = ffmpeg.probe(fpath, cmd=ffprobe_exe_path)\n",
115+
" total_duration += float(info['format']['duration'])\n",
116+
"\n",
117+
"print(total_duration/60)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": []
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "Python 3",
131+
"language": "python",
132+
"name": "python3"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.8.3"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 4
149+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## 怎样批量统计视频的总时长\n",
8+
"\n",
9+
"环境依赖\n",
10+
"\n",
11+
"#### 1、安装python包\n",
12+
"\n",
13+
"pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ffmpeg-python\n",
14+
"\n",
15+
"#### 2、下载windows的exe可执行文件\n",
16+
"\n",
17+
"https://web.archive.org/web/20200918193047/https://ffmpeg.zeranoe.com/builds/\n",
18+
"\n",
19+
"下载后解压,记住解压路径"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 47,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"import os\n",
29+
"import ffmpeg"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": 48,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"dir_path = \"G:/2020-11-16 高顿教育/01. 零基础入门学Python\"\n",
39+
"ffprobe_exe_path = \"D:/software/ffmpeg-20200831-4a11a6f-win64-static/bin/ffprobe.exe\""
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 50,
45+
"metadata": {
46+
"scrolled": false
47+
},
48+
"outputs": [
49+
{
50+
"name": "stdout",
51+
"output_type": "stream",
52+
"text": [
53+
"01.为什么选择学习python.mp4\n",
54+
"02.Python的学习大纲.mp4\n",
55+
"03.Python简介和版本选择.mp4\n",
56+
"04.Python在各个系统的安装.mp4\n",
57+
"05.命令行下执行Python代码.mp4\n",
58+
"06.命令行下执行Python文件.mp4\n",
59+
"07.Python最好用的编辑器Pycharm.mp4\n",
60+
"08.Python的打印和缩进和注释.mp4\n",
61+
"09.Python基本数据类型和变量.mp4\n",
62+
"10.Python的算数和逻辑运算符.mp4\n",
63+
"11.Python的if语句.mp4\n",
64+
"12.Python的for循环.mp4\n",
65+
"13.Python的while循环.mp4\n",
66+
"14.Python的break和continue关键字.mp4\n",
67+
"15.Python读写文件的方法.mp4\n",
68+
"16.Python的字符串知识点讲解.mp4\n",
69+
"17.Python的列表的索引和切片操作.mp4\n",
70+
"18.Python的列表支持的函数.mp4\n",
71+
"19.Python的列表推导式.mp4\n",
72+
"20.Python的元组Tuple.mp4\n",
73+
"21.Python的元组和列表的区别.mp4\n",
74+
"22.Python的字典dict的基础知识.mp4\n",
75+
"23.Python的字典的常用方法.mp4\n",
76+
"24.Python的字典的数据统计案例.mp4\n",
77+
"25.Python的集合set.mp4\n",
78+
"26.Python的集合set的实际案例.mp4\n",
79+
"27.Python高级数据结构的总结对比.mp4\n",
80+
"28.Python实战计算PV和UV第1部分.mp4\n",
81+
"29.Python实战计算PV和UV第2部分.mp4\n",
82+
"30.Python代码的组织结构.mp4\n",
83+
"31.Python的函数的基础知识.mp4\n",
84+
"32.Python的函数的代码演示.mp4\n",
85+
"33.Python使用函数重构PVUV实例代码.mp4\n",
86+
"34.Python的lambda函数和列表的排序.mp4\n",
87+
"35.Python的类的知识和演示.mp4\n",
88+
"36.Python的类知识的实际案例.mp4\n",
89+
"37.Python的异常的基本知识.mp4\n",
90+
"38.Python模拟处理爬虫的异常.mp4\n",
91+
"39.Python的包和模块的基础知识.mp4\n",
92+
"40.Python的常见模块介绍.mp4\n",
93+
"41.Python的开源模块的安装方法.mp4\n",
94+
"42.Python的sys和os模块.mp4\n",
95+
"43.Python的sys和os模块整理文件夹.mp4\n",
96+
"44.Python的json模块.mp4\n",
97+
"45.Python使用flask开发web应用程序.mp4\n",
98+
"46.Python的http爬虫库requests.mp4\n",
99+
"47.Python使用PyMySQL模块操作MySQL.mp4\n",
100+
"48.Python使用xlwt模块生成excel.mp4\n",
101+
"49.Python使用multiprocessing模块开发多进程程序.mp4\n",
102+
"50.Python课程最后的总结.mp4\n",
103+
"308.3598722166666\n"
104+
]
105+
}
106+
],
107+
"source": [
108+
"total_duration = 0.0\n",
109+
"for fname in os.listdir(dir_path):\n",
110+
" if not fname.endswith(\".mp4\"):\n",
111+
" continue\n",
112+
" fpath = f\"{dir_path}/{fname}\"\n",
113+
" print(fname)\n",
114+
" info = ffmpeg.probe(fpath, cmd=ffprobe_exe_path)\n",
115+
" total_duration += float(info['format']['duration'])\n",
116+
"\n",
117+
"print(total_duration/60)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": []
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "Python 3",
131+
"language": "python",
132+
"name": "python3"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.8.3"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 4
149+
}

0 commit comments

Comments
 (0)