mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-08-10 21:20:08 +08:00
Update split_silence
This commit is contained in:
parent
c72c86e82f
commit
496f670b04
@ -48,7 +48,7 @@ def get_chunk_times(in_filename, silence_threshold, silence_duration, start_time
|
|||||||
if end_time is not None:
|
if end_time is not None:
|
||||||
input_kwargs['t'] = end_time - start_time
|
input_kwargs['t'] = end_time - start_time
|
||||||
|
|
||||||
p = _logged_popen(
|
child = _logged_popen(
|
||||||
(ffmpeg
|
(ffmpeg
|
||||||
.input(in_filename, **input_kwargs)
|
.input(in_filename, **input_kwargs)
|
||||||
.filter_('silencedetect', n='{}dB'.format(silence_threshold), d=silence_duration)
|
.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
|
|||||||
) + ['-nostats'], # FIXME: use .nostats() once it's implemented in ffmpeg-python.
|
) + ['-nostats'], # FIXME: use .nostats() once it's implemented in ffmpeg-python.
|
||||||
stderr=subprocess.PIPE
|
stderr=subprocess.PIPE
|
||||||
)
|
)
|
||||||
output = p.communicate()[1].decode('utf-8')
|
output = child.communicate()[1].decode('utf-8')
|
||||||
if p.returncode != 0:
|
if child.returncode != 0:
|
||||||
sys.stderr.write(output)
|
sys.stderr.write(output)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
logger.debug(output)
|
logger.debug(output)
|
||||||
@ -127,25 +127,24 @@ def split_audio(
|
|||||||
input = ffmpeg.input(in_filename, ss=start_time, t=time)
|
input = ffmpeg.input(in_filename, ss=start_time, t=time)
|
||||||
|
|
||||||
if padding > 0.:
|
if padding > 0.:
|
||||||
silence = ffmpeg.input('aevalsrc=0:0::duration={}'.format(padding), format='lavfi')
|
silence = ffmpeg.input('anullsrc', format='lavfi', t=padding)
|
||||||
input = ffmpeg.concat(silence, input, v=0, a=1)
|
input = ffmpeg.concat(silence, input, silence, v=0, a=1)
|
||||||
|
|
||||||
ffmpeg_cmd = (input
|
ffmpeg_cmd = (input
|
||||||
.output(out_filename)
|
.output(out_filename)
|
||||||
.overwrite_output()
|
.overwrite_output()
|
||||||
.compile()
|
.compile()
|
||||||
)
|
)
|
||||||
print ffmpeg_cmd
|
|
||||||
|
|
||||||
p = _logged_popen(
|
child = _logged_popen(
|
||||||
ffmpeg_cmd,
|
ffmpeg_cmd,
|
||||||
stdout=subprocess.PIPE if not verbose else None,
|
stdout=subprocess.PIPE if not verbose else None,
|
||||||
stderr=subprocess.PIPE if not verbose else None,
|
stderr=subprocess.PIPE if not verbose else None,
|
||||||
)
|
)
|
||||||
out = p.communicate()
|
out = child.communicate()
|
||||||
if p.returncode != 0:
|
if child.returncode != 0:
|
||||||
if not verbose:
|
if not verbose:
|
||||||
sys.stderr.write(out[1])
|
sys.stderr.write(out[1].decode('utf-8'))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user