Skip to content

Commit

Permalink
Fix division by zero in video in bitrate computation code (mastodon#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and audiodude committed Oct 23, 2023
1 parent dffb270 commit 6bc0610
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/paperclip/transcoder.rb
Expand Up @@ -43,7 +43,8 @@ def make
unless eligible_to_passthrough?(metadata)
size_limit_in_bits = MediaAttachment::VIDEO_LIMIT * 8
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

@output_options['b:v'] = bitrate
Expand Down

0 comments on commit 6bc0610

Please sign in to comment.