Class: StackEncode::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/stack-encode/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/stack-encode/cli.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#encode(*files) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/stack-encode/cli.rb', line 50

def encode(*files)
  FFMPEG.logger = Logger.new(options[:log_file])
  files.each do |source|
    unless File.file?(source)
      puts "#{source} is not a valid file"
      next
    end
    movie = FFMPEG::Movie.new(source)
    dest_format = movie.video_stream ? options[:video_format] : options[:audio_format]
    dest_dir = options[:destination] || File.dirname(source)
    filename = File.basename(source, File.extname(source)) + ".#{dest_format}"
    banner = "Encoding #{File.basename(source)} to #{dest_format.upcase} ==> #{filename}"
    puts banner unless options[:progress]
    transcoded_movie = movie.transcode(
      File.expand_path(
        "#{dest_dir}/" + filename
      ),
      options[:ffmpeg_options]
    ) do |progress|
      if options[:progress]
        print_progress(progress * 100, banner)
      end
    end
    puts if options[:progress]
    transcoded_movie
  end
end

#versionObject



23
24
25
# File 'lib/stack-encode/cli.rb', line 23

def version
  say "stack-encode v#{StackEncode::VERSION}"
end