Skip to content

Commit

Permalink
Fixed crash when supplying FFMPEG_BINARY environment variable (#30022)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyjrogers authored and ClearlyClaire committed May 10, 2024
1 parent c7cced6 commit 1c13e0b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/lib/video_metadata_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def valid?
private

def ffmpeg_command_output
command = Terrapin::CommandLine.new('ffprobe', '-i :path -print_format :format -show_format -show_streams -show_error -loglevel :loglevel')
command = Terrapin::CommandLine.new(Rails.configuration.x.ffprobe_binary, '-i :path -print_format :format -show_format -show_streams -show_error -loglevel :loglevel')
command.run(path: @path, format: 'json', loglevel: 'fatal')
end

Expand Down
7 changes: 5 additions & 2 deletions config/initializers/ffmpeg.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if ENV['FFMPEG_BINARY'].present?
FFMPEG.ffmpeg_binary = ENV['FFMPEG_BINARY']
# frozen_string_literal: true

Rails.application.configure do
config.x.ffmpeg_binary = ENV['FFMPEG_BINARY'] || 'ffmpeg'
config.x.ffprobe_binary = ENV['FFPROBE_BINARY'] || 'ffprobe'
end
2 changes: 1 addition & 1 deletion lib/paperclip/image_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def extract_image_from_file!
dst.binmode

begin
command = Terrapin::CommandLine.new('ffmpeg', '-i :source -loglevel :loglevel -y :destination', logger: Paperclip.logger)
command = Terrapin::CommandLine.new(Rails.configuration.x.ffmpeg_binary, '-i :source -loglevel :loglevel -y :destination', logger: Paperclip.logger)
command.run(source: @file.path, destination: dst.path, loglevel: 'fatal')
rescue Terrapin::ExitStatusError
dst.close(true)
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def make
command_arguments, interpolations = prepare_command(destination)

begin
command = Terrapin::CommandLine.new('ffmpeg', command_arguments.join(' '), logger: Paperclip.logger)
command = Terrapin::CommandLine.new(Rails.configuration.x.ffmpeg_binary, command_arguments.join(' '), logger: Paperclip.logger)
command.run(interpolations)
rescue Terrapin::ExitStatusError => e
raise Paperclip::Error, "Error while transcoding #{@basename}: #{e}"
Expand Down

0 comments on commit 1c13e0b

Please sign in to comment.