mplayer snippets

How to extract a thumbnail from a video file with mplayer

Tagged mplayer, thumbnail, video, jpeg  Languages ruby
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:

mplayer -vo help

How to extract video metadata with mplayer and Ruby

Tagged mplayer, ruby, metadata, flv, movie, video  Languages ruby

You can easily extract video metadata into a hash with mplayer and Ruby:

class Metadata
  
  def self.get(file)
    command  = "mplayer -vo null -ao null -frames 0 -identify #{file}"
    metadata = nil
    
    Open3.popen3(command) do |input, output, error|
      metadata = output.readlines.grep(/ID_.*/).collect {|name| name[3..name.length].split('=')}
      metadata = metadata.inject({}) {|hash, (key, value)| hash[key.to_sym] = value.chomp; hash}
    end
    
    return metadata
  end
  
end

Then in an RSpec test do:

it "should support 3gp" do
    metadata = Metadata.get("videos/sony_ericsson_k850i.3gp")
    
    metadata[:DEMUXER].should == 'mov'
    metadata[:VIDEO_FORMAT].should == 's263'
    metadata[:VIDEO_WIDTH].should == '176'
    metadata[:VIDEO_HEIGHT].should == '144'
  end

Note to self: metadata.demuxer would perhaps be a slightly better syntax.