Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix division by zero in video in bitrate computation code #27129

Merged
merged 1 commit into from Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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