Skip to content

Commit

Permalink
fix: switch popen to use an array invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
swarley committed Mar 8, 2023
1 parent 413cd09 commit 91e1304
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/discordrb/voice/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 91e1304

Please # to comment.