Fix division by zero in video in bitrate computation code (#27129)
This commit is contained in:
parent
12bbccbe82
commit
916b5bd4ad
1 changed files with 2 additions and 1 deletions
|
@ -43,7 +43,8 @@ module Paperclip
|
||||||
unless eligible_to_passthrough?(metadata)
|
unless eligible_to_passthrough?(metadata)
|
||||||
size_limit_in_bits = MediaAttachment::VIDEO_LIMIT * 8
|
size_limit_in_bits = MediaAttachment::VIDEO_LIMIT * 8
|
||||||
desired_bitrate = (metadata.width * metadata.height * 30 * BITS_PER_PIXEL).floor
|
desired_bitrate = (metadata.width * metadata.height * 30 * BITS_PER_PIXEL).floor
|
||||||
maximum_bitrate = (size_limit_in_bits / metadata.duration).floor - 192_000 # Leave some space for the audio stream
|
duration = [metadata.duration, 1].max
|
||||||
|
maximum_bitrate = (size_limit_in_bits / duration).floor - 192_000 # Leave some space for the audio stream
|
||||||
bitrate = [desired_bitrate, maximum_bitrate].min
|
bitrate = [desired_bitrate, maximum_bitrate].min
|
||||||
|
|
||||||
@output_options['b:v'] = bitrate
|
@output_options['b:v'] = bitrate
|
||||||
|
|
Loading…
Reference in a new issue