0
0
Fork 0

Fix MP4 (H264 + AAC) video files being needlessly re-encoded (#13239)

This commit is contained in:
ThibG 2020-03-09 23:15:59 +01:00 committed by GitHub
parent 57d98b20f2
commit abd8394880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View file

@ -5,12 +5,20 @@ module Paperclip
# to check when uploaded videos are actually gifv's
class VideoTranscoder < Paperclip::Processor
def make
meta = ::Av.cli.identify(@file.path)
movie = FFMPEG::Movie.new(@file.path)
actual_options = options
passthrough_options = actual_options[:passthrough_options]
actual_options = passthrough_options[:options] if passthrough?(movie, passthrough_options)
attachment.instance.type = MediaAttachment.types[:gifv] unless meta[:audio_encode]
options[:format] = File.extname(attachment.instance.file_file_name)[1..-1] if options[:keep_same_format]
attachment.instance.type = MediaAttachment.types[:gifv] unless movie.audio_codec
Paperclip::Transcoder.make(file, options, attachment)
Paperclip::Transcoder.make(file, actual_options, attachment)
end
private
def passthrough?(movie, options)
options && options[:video_codec_whitelist].include?(movie.video_codec) && options[:audio_codec_whitelist].include?(movie.audio_codec)
end
end
end