Skip to content

Commit

Permalink
Fixed bitrate and for recent ffmpeg versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien committed Nov 26, 2010
1 parent e0ecc81 commit 7598c5c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
21 changes: 13 additions & 8 deletions lib/rvideo/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,12 @@ def audio_channels_string

def audio_channels
return nil unless audio?

case audio_match[5]
when "mono" then 1
when "stereo" then 2
when /(\d+) channels/ then $1.to_i
when /^(\d.\d)$/ then $1.to_i+$2.to_i
else
raise RuntimeError, "Unknown number of channels"
end
Expand Down Expand Up @@ -439,18 +441,18 @@ def video_bit_rate_units
#
def fps
return nil unless video?
video_match[2] or video_match[11]
video_match[2] || video_match[13] || video_match[14]
end
alias_method :framerate, :fps

def time_base
return nil unless video?
video_match[12]
video_match[14]
end

def codec_time_base
return nil unless video?
video_match[13]
video_match[15]
end

private
Expand All @@ -467,13 +469,14 @@ def bitrate_match
VAL = '([^,]+)'

RATE = '([\d.]+k?)'
PAR_DAR = '(?:\s*\[?(?:PAR\s*(\d+:\d+))?\s*(?:DAR\s*(\d+:\d+))?\]?)?'

AUDIO_MATCH_PATTERN = /
Stream\s+(.*?)[,:\(\[].*?\s*
Audio:\s+
#{VAL}#{SEP} # codec
#{RATE}\s+(\w*)#{SEP}? # sample rate
([a-zA-Z:]*)#{SEP}? # channels
#{VAL}#{SEP}? # channels
(?:s(\d+)#{SEP}?)? # audio sample bit depth
(?:(\d+)\s+(\S+))? # audio bit rate
/x
Expand All @@ -493,10 +496,12 @@ def audio_match
#{VAL}#{SEP} # codec
(?:#{VAL}#{SEP})? # color space
(\d+)x(\d+) # resolution
(?:\s*\[?(?:PAR\s*(\d+:\d+))?\s*(?:DAR\s*(\d+:\d+))?\]?)? # pixel and display aspect ratios
#{SEP}?
#{PAR_DAR} # pixel and display aspect ratios
#{SEP}?
(?:#{RATE}\s*(kb\/s)#{SEP}?)? # video bit rate
(?:#{RATE}\s*(?:tb\(?r\)?|#{FPS})#{SEP}?)? # frame rate
#{PAR_DAR}#{SEP}? # pixel and display aspect ratios
(?:#{RATE}\s*#{FPS}#{SEP}?)? # frame rate
(?:#{RATE}\s*tbr#{SEP}?)? # time base
(?:#{RATE}\s*tbn#{SEP}?)? # time base
(?:#{RATE}\s*tbc#{SEP}?)? # codec time base
/x
Expand Down
17 changes: 15 additions & 2 deletions spec/integrations/inspection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require File.dirname(__FILE__) + "/../spec_helper"

module RVideo

describe Inspector, "with boat.avi" do

before(:each) do
@i = Inspector.new :file => spec_file("boat.avi")
end
Expand Down Expand Up @@ -71,7 +72,7 @@ module RVideo
end

it "gives the audio channels as a string" do
assert_equal "mono", @i.audio_channels_string
assert_equal "1 channels", @i.audio_channels_string
end

it "knows the audio bit rate" do
Expand Down Expand Up @@ -109,4 +110,16 @@ module RVideo
assert_equal "11:9", @i.display_aspect_ratio
end
end

describe Inspector, "with kites.mp4" do
before(:each) do
@i = Inspector.new :file => '/Users/vivien/Downloads/995b7684b98fac47b7b9affd5578c15a.avi'
end

it "knows the pixel aspect ratio" do
assert_equal "384 kb/s", @i.audio_bit_rate_with_units
end

end

end

0 comments on commit 7598c5c

Please sign in to comment.