Class: FfmpegProgress::Ffmpeg
- Inherits:
-
Object
- Object
- FfmpegProgress::Ffmpeg
- Defined in:
- lib/ffmpeg_progress.rb
Overview
The class that does the actual work.
Constant Summary collapse
- LOG_FILE =
The log file for ffmpeg. Progress data will be read from here.
'ffmpeg.log'- DEFAULT_EXT =
The extension for the default output file.
'mp4'- DEFAULT_DIR =
The directory for the default output file.
'converted/'- DEFAULT_THEME =
The default theme, change this with #theme=. FfmpegProgress expects a 256-color capable terminal.
{ bars: 63, head: '[', full: '=', empty: '-', tail: ']', end_fg: 202, full_fg: 214, empty_fg: 202, time_fg: 214, block_fg: 214, finish_fg: 40, cancel_fg: 1 }
Constants included from Presets
Presets::BURN_800, Presets::BURN_MKV_SUBS, Presets::DEFAULT_OPTS
Instance Attribute Summary collapse
-
#duration ⇒ Integer
readonly
Returns the duration (in seconds) of the input file.
-
#duration_ff ⇒ Integer
readonly
Returns the duration of the input file as a
ffmpegformat string (HH:MM:SS.ms). -
#input ⇒ String
The input file.
-
#options ⇒ String
The options to pass to
ffmpeg. -
#output ⇒ String
The output file.
-
#pid ⇒ Integer
readonly
The PID of the last spawned
ffmpegprocess, ornilif none spawned yet. -
#theme ⇒ Hash
The theme for the progress bar.
Instance Method Summary collapse
-
#command ⇒ String
Returns the current
ffmpegcommand that will be executed by #run. -
#initialize(input_file = nil, ffmpeg_options = DEFAULT_OPTS) ⇒ Ffmpeg
constructor
Creates a new Ffmpeg instance.
-
#run(&block) ⇒ 0
Run
ffmpegwhile printing a progress bar to the terminal.
Methods included from Utils
Constructor Details
#initialize(input_file = nil, ffmpeg_options = DEFAULT_OPTS) ⇒ Ffmpeg
Creates a new FfmpegProgress::Ffmpeg instance.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ffmpeg_progress.rb', line 117 def initialize(input_file = nil, = DEFAULT_OPTS) self.input = input_file = @output ||= nil @duration_ff ||= nil @duration ||= nil @block = nil @pid = nil @theme = DEFAULT_THEME = nil end |
Instance Attribute Details
#duration ⇒ Integer (readonly)
Returns the duration (in seconds) of the input file.
89 90 91 |
# File 'lib/ffmpeg_progress.rb', line 89 def duration @duration end |
#duration_ff ⇒ Integer (readonly)
Returns the duration of the input file as a ffmpeg format string (HH:MM:SS.ms).
95 96 97 |
# File 'lib/ffmpeg_progress.rb', line 95 def duration_ff @duration_ff end |
#input ⇒ String
The input file.
81 82 83 |
# File 'lib/ffmpeg_progress.rb', line 81 def input @input end |
#options ⇒ String
The options to pass to ffmpeg. Any occurrences of the string INPUT will be converted to the value of the #input attribute.
100 101 102 |
# File 'lib/ffmpeg_progress.rb', line 100 def end |
#output ⇒ String
The output file. Directories will be auto-created on execution.
85 86 87 |
# File 'lib/ffmpeg_progress.rb', line 85 def output @output end |
#pid ⇒ Integer (readonly)
The PID of the last spawned ffmpeg process, or nil if none spawned yet.
109 110 111 |
# File 'lib/ffmpeg_progress.rb', line 109 def pid @pid end |
#theme ⇒ Hash
The theme for the progress bar. See DEFAULT_THEME for details.
104 105 106 |
# File 'lib/ffmpeg_progress.rb', line 104 def theme @theme end |
Instance Method Details
#command ⇒ String
Returns the current ffmpeg command that will be executed by #run.
153 154 155 156 |
# File 'lib/ffmpeg_progress.rb', line 153 def command "ffmpeg -i \'#{@input}\' #{@options} \'#{@output}\' &> #{LOG_FILE}" .gsub('_INPUT_', "'#{@input}'") end |
#run(&block) ⇒ 0
Run ffmpeg while printing a progress bar to the terminal. If a block is passed, its return value will be attached to the progress bar. The current FfmpegProgress::Ffmpeg instance will be passed to the block.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ffmpeg_progress.rb', line 164 def run(&block) File.delete(LOG_FILE) if File.exist?(LOG_FILE) FileUtils.mkpath(@output.rpartition('/').first) if output.include?('/') @pid = spawn command @block = block sleep 1 until current_time monitor_progress cleanup 0 end |