Class: FFmpegProgress::FFmpeg
- Inherits:
-
Object
- Object
- FFmpegProgress::FFmpeg
- Defined in:
- lib/ffmpeg_progress/ffmpeg.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/'
Constants included from Utils
Constants included from Presets
Presets::BURN_800, Presets::BURN_MKV_SUBS, Presets::DEFAULT_OPTIONS, Presets::WIDTH_800
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, option_hash = {}) ⇒ 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, option_hash = {}) ⇒ FFmpeg
Creates a new FFmpegProgress::FFmpeg instance.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 60 def initialize(input_file, option_hash = {}) self.input = input_file @options = option_hash.fetch :options, DEFAULT_OPTIONS @theme = Theme.from(option_hash.fetch :theme, Theme.new) @bell = option_hash.fetch :bell, false @output = option_hash.fetch :output, @output @duration_ff ||= nil @duration ||= nil @block = nil @pid = nil @last_bar = nil end |
Instance Attribute Details
#duration ⇒ Integer (readonly)
Returns the duration (in seconds) of the input file.
26 27 28 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 26 def duration @duration end |
#duration_ff ⇒ Integer (readonly)
Returns the duration of the input file as a ffmpeg format string (HH:MM:SS.ms).
32 33 34 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 32 def duration_ff @duration_ff end |
#input ⇒ String
The input file.
18 19 20 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 18 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.
37 38 39 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 37 def @options end |
#output ⇒ String
The output file. Directories will be auto-created on execution.
22 23 24 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 22 def output @output end |
#pid ⇒ Integer (readonly)
The PID of the last spawned ffmpeg process, or nil if none spawned yet.
46 47 48 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 46 def pid @pid end |
#theme ⇒ Hash
The theme for the progress bar. See Theme::DEFAULT_THEME for details.
41 42 43 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 41 def theme @theme end |
Instance Method Details
#command ⇒ String
Returns the current ffmpeg command that will be executed by #run.
98 99 100 101 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 98 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.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ffmpeg_progress/ffmpeg.rb', line 109 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 |