Module: SplitVideo

Defined in:
lib/split_video.rb,
lib/split_video/version.rb

Constant Summary collapse

USAGE =
%{
  Usage: #{$0} [options] filename

  Options include:

    -s, --slices   : Number of pieces to slice the video into
    -d, --duration : Duration of each slice

  Important: only specify ONE of those!
}
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.split_a_video(filename, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/split_video.rb', line 16

def self.split_a_video(filename, options)
  unless (!! options['slices']) ^ (!! options['duration'])
    puts USAGE
    exit
  end

  if options['slices']
    SplitVideo.split_by_slices(filename, options['slices'].to_i, options)
  elsif options['duration']
    SplitVideo.split_by_duration(filename, options['duration'].to_i, options)
  end
end

.split_by_duration(filename, duration, options = {}) ⇒ Object



48
49
50
51
# File 'lib/split_video.rb', line 48

def self.split_by_duration(filename, duration, options = {})
  puts "Sorry I haven't implemented this yet."
  exit
end

.split_by_slices(filename, num_slices, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/split_video.rb', line 29

def self.split_by_slices(filename, num_slices, options = {})
  seconds_per_slice = duration_in_seconds(filename) / num_slices

  offset = 0.0
  (0..(num_slices - 1)).each do |slice|
    print "Cutting slice #{slice}"
    %x{
      ffmpeg -i      "#{filename}"            \
             -vcodec copy                     \
             -acodec copy                     \
             -ss     "#{offset}"              \
             -t      "#{seconds_per_slice}"   \
             #{output_filename_for(filename) % slice}
    }
    puts "...done!"
    offset += seconds_per_slice
  end
end