Class: CutCut::Media
Overview
Media
Instance Attribute Summary collapse
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
Attributes inherited from Base
Instance Method Summary collapse
- #convert(options = {}) ⇒ Object
- #copy_metadata_to_screenshots(basename, fps) ⇒ Object
- #cut(options = {}) ⇒ Object
- #extract_output_raw_options(options = {}) ⇒ Object
- #extract_screenshots(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Media
constructor
A new instance of Media.
- #screenshot_basename_time(basename, file, fps) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Media
6 7 8 9 10 |
# File 'lib/cutcut/media.rb', line 6 def initialize( = {}) @input = .delete(:input) @output = .delete(:output) @output_path = .delete(:output_path) || File.dirname(@input) end |
Instance Attribute Details
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
4 5 6 |
# File 'lib/cutcut/media.rb', line 4 def output_path @output_path end |
Instance Method Details
#convert(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/cutcut/media.rb', line 12 def convert( = {}) = [:copy_metadata] || false output = [:output] || @output || File.join(@output_path, '__' + File.basename(@input)) execute_ffmpeg_command(input: @input, output: output, raw_options: { output: () }) Helpers.(@input, output) if output end |
#copy_metadata_to_screenshots(basename, fps) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/cutcut/media.rb', line 55 def (basename, fps) Dir.glob("#{output_path}/#{basename}*.jpg").sort.each do |file| seconds = screenshot_basename_time(basename, file, fps) exif = MiniExiftool.new(file) exif.create_date = original_date_time + seconds.seconds exif.save end end |
#cut(options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cutcut/media.rb', line 43 def cut( = {}) starts_at = [:start] || '00:00' time = [:time] || 1 output = [:output] || "#{File.basename(@input, '.MP4')}_#{starts_at}.mp4" execute_ffmpeg_command( input: @input, output: "#{output_path}/#{output}", raw_options: { output: "-ss #{starts_at} -t #{time}" } ) end |
#extract_output_raw_options(options = {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/cutcut/media.rb', line 22 def ( = {}) scale = [:scale] speed = "-filter:v \"setpts=#{options[:speed]}*PTS\"" if [:speed] remove_audio = [:remove_audio] == true ? '-an' : nil "-movflags +faststart -vf scale=#{scale} -c:v libx264 -crf 20 -preset ultrafast #{speed} #{remove_audio}" end |
#extract_screenshots(options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cutcut/media.rb', line 29 def extract_screenshots( = {}) fps = [:fps] || 1 basename = [:basename] || File.basename(@input, '.MP4') + '_screenshot' = [:copy_metadata] execute_ffmpeg_command( input: @input, output: "#{output_path}/#{basename}%d.jpg", raw_options: { output: "-vf fps=#{fps}" } ) (basename, fps) if end |
#screenshot_basename_time(basename, file, fps) ⇒ Object
64 65 66 |
# File 'lib/cutcut/media.rb', line 64 def screenshot_basename_time(basename, file, fps) (1.0 / fps.to_f) * File.basename(file, '.jpg').gsub(basename, '').to_i - (1.0 / fps.to_f) end |