8000 Update split_silence · jch-wang/ffmpeg-python@496f670 · GitHub
[go: up one dir, main page]

Skip to content

Commit 496f670

Browse files
committed
Update split_silence
1 parent c72c86e commit 496f670

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

examples/split_silence.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time
4848
if end_time is not None:
4949
input_kwargs['t'] = end_time - start_time
5050

51-
p = _logged_popen(
51+
child = _logged_popen(
5252
(ffmpeg
5353
.input(in_filename, **input_kwargs)
5454
.filter_('silencedetect', n='{}dB'.format(silence_threshold), d=silence_duration)
@@ -57,8 +57,8 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time
5757
) + ['-nostats'], # FIXME: use .nostats() once it's implemented in ffmpeg-python.
5858
stderr=subprocess.PIPE
5959
)
60-
output = p.communicate()[1].decode('utf-8')
61-
if p.returncode != 0:
60+
output = child.communicate()[1].decode('utf-8')
61+
if child.returncode != 0:
6262
sys.stderr.write(output)
6363
sys.exit(1)
6464
logger.debug(output)
@@ -127,25 +127,24 @@ def split_audio(
127127
input = ffmpeg.input(in_filename, ss=start_time, t=time)
128128

129129
if padding > 0.:
130-
silence = ffmpeg.input('aevalsrc=0:0::duration={}'.format(padding), format='lavfi')
131-
input = ffmpeg.concat(silence, input, v=0, a=1)
130+
silence = ffmpeg.input('anullsrc', format='lavfi', t=padding)
131+
input = ffmpeg.concat(silence, input, silence, v=0, a=1)
132132

133133
ffmpeg_cmd = (input
134134
.output(out_filename)
135135
.overwrite_output()
136136
.compile()
137137
)
138-
print ffmpeg_cmd
139138

140-
p = _logged_popen(
139+
child = _logged_popen(
141140
ffmpeg_cmd,
142141
stdout=subprocess.PIPE if not verbose else None,
143142
stderr=subprocess.PIPE if not verbose else None,
144143
)
145-
out = p.communicate()
146-
if p.returncode != 0:
144+
out = child.communicate()
145+
if child.returncode != 0:
147146
if not verbose:
148-
sys.stderr.write(out[1])
147+
sys.stderr.write(out[1].decode('utf-8'))
149148
sys.exit(1)
150149

151150

0 commit comments

Comments
 (0)
0