|
|
@ -4,6 +4,9 @@ module Paperclip
|
|
|
|
# This transcoder is only to be used for the MediaAttachment model
|
|
|
|
# This transcoder is only to be used for the MediaAttachment model
|
|
|
|
# to check when uploaded videos are actually gifv's
|
|
|
|
# to check when uploaded videos are actually gifv's
|
|
|
|
class Transcoder < Paperclip::Processor
|
|
|
|
class Transcoder < Paperclip::Processor
|
|
|
|
|
|
|
|
# This is the H.264 "High" value taken from https://www.dr-lex.be/info-stuff/videocalc.html
|
|
|
|
|
|
|
|
BITS_PER_PIXEL = 0.11
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(file, options = {}, attachment = nil)
|
|
|
|
def initialize(file, options = {}, attachment = nil)
|
|
|
|
super
|
|
|
|
super
|
|
|
|
|
|
|
|
|
|
|
@ -38,8 +41,11 @@ module Paperclip
|
|
|
|
@output_options['vframes'] = 1
|
|
|
|
@output_options['vframes'] = 1
|
|
|
|
when 'mp4'
|
|
|
|
when 'mp4'
|
|
|
|
unless eligible_to_passthrough?(metadata)
|
|
|
|
unless eligible_to_passthrough?(metadata)
|
|
|
|
@output_options['acodec'] = 'aac'
|
|
|
|
bitrate = (metadata.width * metadata.height * 30 * BITS_PER_PIXEL) / 1_000
|
|
|
|
@output_options['strict'] = 'experimental'
|
|
|
|
|
|
|
|
|
|
|
|
@output_options['b:v'] = "#{bitrate}k"
|
|
|
|
|
|
|
|
@output_options['maxrate'] = "#{bitrate + 192}k"
|
|
|
|
|
|
|
|
@output_options['bufsize'] = "#{bitrate * 5}k"
|
|
|
|
|
|
|
|
|
|
|
|
if high_vfr?(metadata)
|
|
|
|
if high_vfr?(metadata)
|
|
|
|
@output_options['vsync'] = 'vfr'
|
|
|
|
@output_options['vsync'] = 'vfr'
|
|
|
|