metadata snippets

Add duration metadata into flv movie

Tagged flv, movie, flash, duration, metadata, flvtool2  Languages bash

By default an flv movie doesn't contain the duration metadata. Using the flvtool2 program it is injected like this into the movie file.

cat mymovie.flv | flvtool2 -U stdin mymovie.flv

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[].split('=')}
      metadata = metadata.inject({}) {|hash, (key, value)| hash[key.to_sym] = value.chomp; hash}
    return metadata

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'

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