movie snippets

Create an flv movie

Tagged flv, movie, audio, ffmpeg, flash  Languages bash

Create an flv movie that is 320 wide by 240 high. For audio functionality ffmpeg needs to be compiled with the following parameters:


The snippet itself:

ffmpeg -i mymovie.avi -s 320x240 -ar 44100 -r 12 mymovie.flv

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

Create a thumbnail of a movie.

Tagged thumbnail, movie, ffmpeg, jpg  Languages bash

Create a thumbnail that is 320 wide by 240 high and five seconds into the movie.

ffmpeg -i mymovie.avi -f mjpeg -t 0.001 -ss 5 -s "320x240" mymovie.jpg

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.