From 1c9b726f4022306517572de3726a8de7e93d7aca Mon Sep 17 00:00:00 2001 From: Matthew Carey Date: Wed, 8 Mar 2023 15:33:54 -0500 Subject: [PATCH] fix: switch popen to use an array invocation --- lib/discordrb/voice/encoder.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/discordrb/voice/encoder.rb b/lib/discordrb/voice/encoder.rb index 807f1588d..f288732ab 100644 --- a/lib/discordrb/voice/encoder.rb +++ b/lib/discordrb/voice/encoder.rb @@ -77,7 +77,7 @@ def adjust_volume(buf, mult) # @param options [String] ffmpeg options to pass after the -i flag # @return [IO] the audio, encoded as s16le PCM def encode_file(file, options = '') - command = "#{ffmpeg_command} -loglevel 0 -i \"#{file}\" #{options} -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1" + command = ffmpeg_command(input: file, options: options) IO.popen(command) end @@ -87,14 +87,23 @@ def encode_file(file, options = '') # @param options [String] ffmpeg options to pass after the -i flag # @return [IO] the audio, encoded as s16le PCM def encode_io(io, options = '') - command = "#{ffmpeg_command} -loglevel 0 -i - #{options} -f s16le -ar 48000 -ac 2 #{filter_volume_argument} pipe:1" + command = ffmpeg_command(options: options) IO.popen(command, in: io) end private - def ffmpeg_command - @use_avconv ? 'avconv' : 'ffmpeg' + def ffmpeg_command(input: '-', options: null) + [ + @use_avconv ? 'avconv' : 'ffmpeg', + '-loglevel', '0', + '-i', input, + '-f', 's16le', + '-ar', '48000', + '-ac', '2', + 'pipe:1', + filter_volume_argument, + ].concat(options.split).reject {|segment| segment.nil? || segment == '' } end def filter_volume_argument