Register now and start sharing your code snippets.
How to extract video metadata with mplayer and Ruby
Ruby posted 6 months ago by christian
You can easily extract video metadata into a hash with mplayer and Ruby:
1 class Metadata 2 3 def self.get(file) 4 command = "mplayer -vo null -ao null -frames 0 -identify #{file}" 5 metadata = nil 6 7 Open3.popen3(command) do |input, output, error| 8 metadata = output.readlines.grep(/ID_.*/).collect {|name| name[3..name.length].split('=')} 9 metadata = metadata.inject({}) {|hash, (key, value)| hash[key.to_sym] = value.chomp; hash} 10 end 11 12 return metadata 13 end 14 15 end
Then in an RSpec test do:
1 it "should parse 3gp" do 2 metadata = Metadata.get("videos/sony_ericsson_k850i.3gp") 3 4 metadata[:DEMUXER].should == 'mov' 5 metadata[:VIDEO_FORMAT].should == 's263' 6 metadata[:VIDEO_WIDTH].should == '176' 7 metadata[:VIDEO_HEIGHT].should == '144' 8 end
How to extract a thumbnail from a video file with mplayer
Ruby posted 6 months ago by christian
1 mplayer 123.avi -ss 1 -nosound -vo jpeg:outdir=. -frames 2
We use the -ss switch to jump to the first second of the video; specify the time in either seconds or hh:mm:ss. We tell mplayer that we want two frames with the -frames switch.
Make sure jpeg is in the list of supported video output formats:
1 mplayer -vo help