Skip to content

Commit

Permalink
Try Tmp Dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrluckechuck committed Oct 21, 2024
1 parent 8a836b2 commit efa2e32
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/ffmpeg/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit efa2e32

Please sign in to comment.