diff --git a/lib/ffmpeg/transcoder.rb b/lib/ffmpeg/transcoder.rb index c9dfe83d..ee29b417 100644 --- a/lib/ffmpeg/transcoder.rb +++ b/lib/ffmpeg/transcoder.rb @@ -33,10 +33,11 @@ def initialize(movie, output_file, options = EncodingOptions.new, transcoder_opt # This is because ffmpeg can't reliably handle inputs that contain frames with differing resolutions particularly for trimming with `filter_complex` @movie.check_frame_resolutions if @transcoder_options[:permit_dynamic_resolution_pre_encode] + temp_dir = ENV.fetch('TMPDIR', '/tmp') if requires_pre_encode @movie.paths.each do |path| # Make the interim path folder if it doesn't exist - dirname = "/tmp/interim" + dirname = "#{temp_dir}/interim" unless File.directory?(dirname) FileUtils.mkdir_p(dirname) end @@ -172,7 +173,8 @@ def transcode_movie pre_encode_if_necessary # change output file to /tmp/interim/output.mp4 needs to be unique to every run # get file extension from original file - dont overwrite original file - temp_output_file = "/tmp/interim/#{File.basename(@output_file, File.extname(@output_file))}_#{SecureRandom.urlsafe_base64}#{File.extname(@output_file)}" + temp_dir = ENV.fetch('TMPDIR', '/tmp') + temp_output_file = "#{temp_dir}/interim/#{File.basename(@output_file, File.extname(@output_file))}_#{SecureRandom.urlsafe_base64}#{File.extname(@output_file)}" @command = "#{@movie.ffmpeg_command} -y #{@raw_options} #{Shellwords.escape(temp_output_file)}" FFMPEG.logger.info("Running transcoding...\n#{@command}\n")