-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathffmpeg_af.py
More file actions
126 lines (113 loc) · 5.5 KB
/
Copy pathffmpeg_af.py
File metadata and controls
126 lines (113 loc) · 5.5 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#/**************************************************************************
#* ffmpeg_af.py: audio filter cases on windows: python 3.x, ffmpeg-4.3.1
#***************************************************************************
#* Copyright (c) 2020-2020 Hybase@qq.com
#*
#* This program is free software: you can redistribute it and/or modify
#* it under the terms of the GNU General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or
#* (at your option) any later version.
#*
#* This program is distributed in the hope that it will be useful,
#* but WITHOUT ANY WARRANTY; without even the implied warranty of
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#* GNU General Public License for more details.
#*
#****************************************************************************/
import os
import re
import sys
import hysmm_def
import ffmpeg_run
################################################################################
# 通用参数字符串
dst_dir = hysmm_def.dst_dir
log_param = hysmm_def.log_param
tt_src_dir = 'e:/material/ffmpeg_hys_python'
input_mp4_file = ' -i ' + tt_src_dir + '/tt.mp4 '
input_mp3_file = ' -i ' + tt_src_dir + '/es_mp3.mp3 '
af_out = dst_dir + '/af_effect'
################################################################################
# case flags: (default: the first be set, please set others by yourself)
play_flag = False # true - ffplay, false - ffmpeg
sfx = '.ts'
start_num = 1
end_num = 15
class af_case_c:
def __init__(self):
# aformat 转换格式
self.case001 = [af_out + '/d001_aformat' + sfx, " aformat=f=s16:r=48000:cl=stereo "]
# volume 调整音量
self.case002 = [af_out + '/d002_volume' + sfx, " volume=0.25 "]
# amix 混音 (需要两路以上输入): 不支持 ffplay
self.case003 = [af_out + '/d003_amix' + sfx, " amix=inputs=2:duration=first:dropout_transition=3 "]
# adelay 延迟
self.case004 = [af_out + '/d004_adelay' + sfx, " adelay=delays=1500:all=1 "]
# aecho 回声
self.case005 = [af_out + '/d005_aecho' + sfx, " aecho=0.8:0.88:60:0.4 "]
# afade 淡入淡出
self.case006 = [af_out + '/d006_afadein' + sfx, " afade=t=in:ss=0:d=5 "]
# aloop 循环
self.case007 = [af_out + '/d007_aloop' + sfx, " aloop=loop=-1 "]
# asubboost 低音炮效果
self.case008 = [af_out + '/d008_asubboost' + sfx, " asubboost=dry=0.5:wet=0.8:decay=0.7:feedback=0.5:cutoff=100:slope=0.5:delay=20"]
# atempo 节拍速度
self.case009 = [af_out + '/d009_atempo' + sfx, " atempo=0.5"]
# chorus 和声
# | ^ " &等字符是特殊字符。
# windows cmd.exe特殊字符需转义。
# 转义时,^^代表^,^|代表|,^"代表"等等
#af_str = ''' chorus=0.7:0.9:55:0.4:0.25:2'''
#af_str = ''' chorus='0.6:0.9:50^|60:0.4^|0.32:0.25^|0.4:2^|1.3' '''
self.case010 = [af_out + '/d010_chorus' + sfx, " chorus='0.7:0.9:55:0.4:0.25:2' "]
self.case011 = [af_out + '/d011_chorus' + sfx, " chorus='0.6:0.9:50^|60:0.4^|0.32:0.25^|0.4:2^|1.3' "]
self.case012 = [af_out + '/d012_chorus' + sfx, " chorus='0.5:0.9:50^|60^|40:0.4^|0.32^|0.3:0.25^|0.4^|0.3:2^|2.3^|1.3' "]
# aresample 重采样
self.case013 = [af_out + '/d013_aresample' + sfx, " aresample=44100 "]
# tremolo 颤音
self.case014 = [af_out + '/d014_tremolo' + sfx, " tremolo "]
#################################################################################
# main process
if __name__ == "__main__":
# init logger
log = hysmm_def.Logger('sys_all.log',level='debug')
hysmm_def.Logger('sys_err.log', level='error')
log.logger.info("========= program start ============")
# check source and output dir, create output dir if necessary
hysmm_def.checkDir(log, tt_src_dir)
hysmm_def.createDirIfNotFound(log, dst_dir)
hysmm_def.createDirIfNotFound(log, af_out)
# init af case
af_case = af_case_c()
af_case_dict = af_case.__dict__
# ***********************************
# transcode parameters
trc_str = ' -vcodec copy -acodec aac -ab 128k ' + hysmm_def.tsmux_vbr_str
log.logger.info(trc_str)
for i in range(start_num, end_num):
idx = '%03d' %i
key = "case" + idx
if (i == 3): # only for amix
input_file = input_mp4_file + input_mp3_file
else:
input_file = input_mp4_file
output_file = af_case_dict[key][0]
if (play_flag):
af_str = ' -af ' + af_case_dict[key][1]
log.logger.info("key:%s, af: %s, dst: %s", key, af_str, output_file)
cmd = 'ffplay ' + log_param + input_file + af_str
ffmpeg_run.ffplay_run(key, True, log, cmd)
else:
af_str = ' -filter_complex ' + af_case_dict[key][1]
log.logger.info("key:%s, af: %s, dst: %s", key, af_str, output_file)
cmd = 'ffmpeg -y ' + log_param + input_file + af_str + trc_str + output_file
ffmpeg_run.ffmpeg_run(key, True, log, cmd)
## end of all cases
log.logger.info("=== all cases run ===")
log.logger.info("============ program exit ============")
sys.exit(0)
################################################################################
# end
#