From 5bb827022949921ccc28ae1bd1d200d67eb642ee Mon Sep 17 00:00:00 2001 From: Julien 'Lta' BALLET Date: Sun, 28 Sep 2025 17:55:56 +0200 Subject: [PATCH] fix: handle missing bitrate in some muxers fixup --- lib/ffmpeg/command_args.rb | 6 ++++-- lib/ffmpeg/media.rb | 4 ++-- spec/ffmpeg/command_args_spec.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ffmpeg/command_args.rb b/lib/ffmpeg/command_args.rb index 1704444..cf6dce5 100644 --- a/lib/ffmpeg/command_args.rb +++ b/lib/ffmpeg/command_args.rb @@ -130,8 +130,10 @@ def adjusted_audio_bit_rate(target_value) def min_bit_rate(*values) bit_rate = - values.compact.map do |value| - next value if value.is_a?(Integer) + values.filter_map do |value| + # Some muxers (webm) might not expose birate under certain conditions + next false if value.nil? + next (value.positive? ? value : false) if value.is_a?(Integer) unless value.is_a?(String) raise ArgumentError, diff --git a/lib/ffmpeg/media.rb b/lib/ffmpeg/media.rb index 56b6d54..05eba18 100644 --- a/lib/ffmpeg/media.rb +++ b/lib/ffmpeg/media.rb @@ -195,8 +195,8 @@ def local? # @return [Boolean] autoload def hdr? default_video_stream&.color_primaries == 'bt2020' && - default_video_stream&.color_space == 'bt2020nc' && - %w[smpte2084 arib-std-b67].include?(default_video_stream&.color_transfer) + default_video_stream&.color_space == 'bt2020nc' && + %w[smpte2084 arib-std-b67].include?(default_video_stream&.color_transfer) end # Whether the media is rotated (based on the default video stream). diff --git a/spec/ffmpeg/command_args_spec.rb b/spec/ffmpeg/command_args_spec.rb index 9922d79..2eac701 100644 --- a/spec/ffmpeg/command_args_spec.rb +++ b/spec/ffmpeg/command_args_spec.rb @@ -96,6 +96,14 @@ module FFMPEG expect(args.to_a).to eq(%w[]) end end + + context 'when the reported media bitrate is 0' do + it 'returns the requested bitrate' do + media = instance_double(Media, video_bit_rate: 0) + args = CommandArgs.compose(media) { min_video_bit_rate '2M' } + expect(args.to_a).to eq(%w[-minrate 2000k]) + end + end end describe '#max_video_bit_rate' do