1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# This program uses the media-info library to display information
# embedded in media files (tags in MP3/OGG files for instance).
require 'gst'
def print_hash(hash)
hash.each { |key, val| puts " #{key}: #{val}" }
end
def print_info(stream)
puts "- mime type: #{stream.mime}"
puts "- length: #{stream.length_time / Gst::SECOND} seconds"
puts "- bitrate: #{stream.bitrate / 1000.0} kbps"
puts "- number of tracks: #{stream.length_tracks}"
i = 0
stream.tracks.each do |x|
puts "- track #{i += 1}:"
puts " - metadata:"
if hash = x.metadata
print_hash(hash)
end
puts " - streaminfo:"
if hash = x.streaminfo
print_hash(hash)
end
puts " - format:"
if caps = x.format
caps.length.times { |i| print_hash(caps.get_structure(i)) }
end
end
end
Gst.init
if ARGV.empty?
$stderr.puts "Usage: #{__FILE__} files..."
exit 1
end
begin
info = Gst::MediaInfo.new
info.source = "filesrc"
ARGV.each do |x|
if stream = info.read(x)
print_info(stream)
else
$stderr.puts "No media info found for file #{x}."
end
end
rescue => e
$stderr.puts "Media error: #{e}."
exit 1
end
|