RnP: Improve error handling in video_info, audio_info functions
This commit is contained in:
parent
5600ddfba4
commit
ef607f0e44
@ -172,15 +172,22 @@ module BigBlueButton
|
||||
|
||||
def self.audio_info(filename)
|
||||
IO.popen([*FFPROBE, filename]) do |probe|
|
||||
info = nil
|
||||
begin
|
||||
info = JSON.parse(probe.read, :symbolize_names => true)
|
||||
if !info[:streams]
|
||||
return {}
|
||||
rescue StandardError => e
|
||||
BigBlueButton.logger.warn("Couldn't parse audio info: #{e}")
|
||||
end
|
||||
info[:audio] = info[:streams].find { |stream| stream[:codec_type] == 'audio' }
|
||||
return {} if !info
|
||||
return {} if !info[:streams]
|
||||
return {} if !info[:format]
|
||||
|
||||
if info[:audio]
|
||||
info[:sample_rate] = info[:audio][:sample_rate].to_i
|
||||
info[:audio] = info[:streams].find do |stream|
|
||||
stream[:codec_type] == 'audio'
|
||||
end
|
||||
return {} if !info[:audio]
|
||||
|
||||
info[:sample_rate] = info[:audio][:sample_rate].to_i
|
||||
|
||||
if info[:format][:format_name] == 'wav'
|
||||
# wav files generated by freeswitch can have incorrect length
|
||||
|
@ -269,33 +269,35 @@ module BigBlueButton
|
||||
|
||||
def self.video_info(filename)
|
||||
IO.popen([*FFPROBE, filename]) do |probe|
|
||||
info = nil
|
||||
begin
|
||||
info = JSON.parse(probe.read, :symbolize_names => true)
|
||||
rescue StandardError => e
|
||||
BigBlueButton.logger.warn("Couldn't parse video info: #{e}")
|
||||
end
|
||||
return {} if !info
|
||||
return {} if !info[:streams]
|
||||
return {} if !info[:format]
|
||||
|
||||
if info[:streams]
|
||||
info[:video] = info[:streams].find { |stream| stream[:codec_type] == 'video' }
|
||||
info[:audio] = info[:streams].find { |stream| stream[:codec_type] == 'audio' }
|
||||
info[:video] = info[:streams].find do |stream|
|
||||
stream[:codec_type] == 'audio'
|
||||
end
|
||||
|
||||
if info[:video]
|
||||
return {} if !info[:video]
|
||||
|
||||
info[:width] = info[:video][:width].to_i
|
||||
info[:height] = info[:video][:height].to_i
|
||||
|
||||
return {} if info[:width] == 0 or info[:height] == 0
|
||||
return {} if info[:video][:display_aspect_ratio] == '0:0'
|
||||
|
||||
info[:aspect_ratio] = info[:video][:display_aspect_ratio].to_r
|
||||
info[:aspect_ratio] = Rational(*(info[:video][:display_aspect_ratio].split(':')))
|
||||
if info[:aspect_ratio] == 0
|
||||
info[:aspect_ratio] = Rational(info[:width], info[:height])
|
||||
end
|
||||
end
|
||||
|
||||
# Convert the duration to milliseconds
|
||||
if info[:format]
|
||||
info[:duration] = (info[:format][:duration].to_r * 1000).to_i
|
||||
else
|
||||
info[:duration] = 0
|
||||
end
|
||||
|
||||
return info
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user