9e28782e6d5ac921d10b747f9b52a48ba557e641
[melted] / mlt++ / swig / ruby / thumbs.rb
1 #!/usr/bin/env ruby
2
3 # Required modules
4 require 'mltpp'
5
6 # Create the mlt system
7 Mltpp::Factory::init
8
9 # Get and check the argument
10 file = ARGV.shift
11 name = ARGV.shift
12 size = ARGV.shift
13 size = "192x144" if size.nil?
14 raise "Usage: thumbs.rb file name [ size ]" if file.nil? || name.nil?
15
16 # Create the producer
17 producer = Mltpp::Producer.new( file )
18 raise "Unable to load #{file}" if !producer.is_valid
19
20 # Construct the playlist
21 playlist = Mltpp::Playlist.new( )
22
23 # Get the out point
24 out = producer.get_int( "out" );
25
26 # Calculate position of frames
27 [ 0, 0.25, 0.5, 0.75, 1 ].each { |x| playlist.append( producer, x*out, x*out ) }
28
29 # Create the thumb nail generator
30 generator = Mltpp::Consumer.new( "avformat", "#{name}%d.jpg" )
31 generator.set( "real_time", "0" )
32 generator.set( "progressive", "1" )
33 generator.set( "size", size )
34
35 # Connect the consumer
36 generator.connect( playlist );
37 generator.run
38