Class: MmTool::MmMovie
- Inherits:
-
Object
- Object
- MmTool::MmMovie
- Defined in:
- lib/mm_tool/mm_movie.rb
Overview
A movie as a self contained class. Instances of this class consist of one or more MmMovieStream instances, and contains intelligence about itself so that it can provide commands to ffmpeg and/or mkvpropedit as required. Upon creation it must be provided with a filename.
Class Method Summary collapse
-
.dispositions ⇒ Object
———————————————————— This class method returns the known dispositions supported by ffmpeg.
Instance Method Summary collapse
-
#command_rename ⇒ Object
———————————————————— The complete command to rename the main input file to include a tag indicating that it’s the original.
-
#command_review_post ⇒ Object
———————————————————— The complete command to view the output file after running the transcode command ————————————————————.
-
#command_transcode ⇒ Object
———————————————————— The complete, proposed ffmpeg command to transcode the input file to an output file.
-
#format_duration ⇒ Object
———————————————————— Get the file-level ‘duration’ metadata.
-
#format_size ⇒ Object
———————————————————— Get the file-level ‘size’ metadata.
-
#format_table ⇒ Object
———————————————————— Get the rendered text of the format_table.
-
#format_title ⇒ Object
———————————————————— Get the file-level ‘title’ metadata.
-
#has_low_quality_streams? ⇒ Boolean
———————————————————— Indicates whether any of the streams are of a lower quality than desired by the user.
-
#initialize(with_file:) ⇒ MmMovie
constructor
———————————————————— Initialize ————————————————————.
-
#interesting? ⇒ Boolean
———————————————————— Indicates whether any of the streams are interesting.
-
#meets_minimum_quality? ⇒ Boolean
———————————————————— Indicates whether or not a file has at least one high- quality video stream and high-quality audio stream.
-
#stream_table ⇒ Object
———————————————————— For the given table, get the rendered text of the table for output.
Constructor Details
#initialize(with_file:) ⇒ MmMovie
Initialize
28 29 30 31 32 |
# File 'lib/mm_tool/mm_movie.rb', line 28 def initialize(with_file:) @defaults = MmUserDefaults.shared_user_defaults @streams = MmMovieStream::streams(with_files: all_paths(with_file: with_file)) @format_metadata = FFMPEG::Movie.new(with_file).[:format] end |
Class Method Details
.dispositions ⇒ Object
This class method returns the known dispositions supported by ffmpeg. This array also reflects the output orders in the dispositions table field. Not combining them would result in a too-long table row.
21 22 23 |
# File 'lib/mm_tool/mm_movie.rb', line 21 def self.dispositions %i(default dub original comment lyrics karaoke forced hearing_impaired visual_impaired clean_effects attached_pic timed_thumbnails) end |
Instance Method Details
#command_rename ⇒ Object
The complete command to rename the main input file to include a tag indicating that it’s the original.
117 118 119 120 121 |
# File 'lib/mm_tool/mm_movie.rb', line 117 def command_rename src = @streams[0].source_file dst = File.join(File.dirname(src), File.basename(src, '.*') + @defaults[:suffix] + File.extname(src)) "mv \"#{src}\" \"#{dst}\"" end |
#command_review_post ⇒ Object
The complete command to view the output file after running the transcode command
147 148 149 |
# File 'lib/mm_tool/mm_movie.rb', line 147 def command_review_post "\"#{$0}\" --no-use-external-subs \"#{output_path}\"" end |
#command_transcode ⇒ Object
The complete, proposed ffmpeg command to transcode the input file to an output file. It uses the ‘new_input_path’ as the input file.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/mm_tool/mm_movie.rb', line 128 def command_transcode command = ["ffmpeg \\"] @streams.each {|stream| command |= [" #{stream.instruction_input}"] if stream.instruction_input } @streams.each {|stream| command << " #{stream.instruction_map}" if stream.instruction_map } @streams.each {|stream| command << " #{stream.instruction_action}" if stream.instruction_action } @streams.each {|stream| command << " #{stream.instruction_disposition}" if stream.instruction_disposition } @streams.each do |stream| stream..each { |instruction| command << " #{instruction}" } end command << " -metadata title=\"#{format_title}\" \\" if format_title command << " \"#{output_path}\"" command.join("\n") end |
#format_duration ⇒ Object
Get the file-level ‘duration’ metadata.
37 38 39 40 |
# File 'lib/mm_tool/mm_movie.rb', line 37 def format_duration seconds = @format_metadata[:duration] seconds ? Time.at(seconds.to_i).utc.strftime("%H:%M:%S") : nil end |
#format_size ⇒ Object
Get the file-level ‘size’ metadata.
45 46 47 48 |
# File 'lib/mm_tool/mm_movie.rb', line 45 def format_size size = @format_metadata[:size] size ? ByteSize.new(size) : 'unknown' end |
#format_table ⇒ Object
Get the rendered text of the format_table.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mm_tool/mm_movie.rb', line 84 def format_table unless @format_table @format_table = format_table_datasource.render(:basic) do |renderer| renderer.column_widths = [10,10, 160] renderer.multiline = true renderer.padding = [0,1] renderer.width = 1000 end end @format_table end |
#format_title ⇒ Object
Get the file-level ‘title’ metadata.
53 54 55 |
# File 'lib/mm_tool/mm_movie.rb', line 53 def format_title @format_metadata&.dig(:tags, :title) end |
#has_low_quality_streams? ⇒ Boolean
Indicates whether any of the streams are of a lower quality than desired by the user.
61 62 63 |
# File 'lib/mm_tool/mm_movie.rb', line 61 def has_low_quality_streams? @streams.count {|stream| stream.low_quality?} > 0 end |
#interesting? ⇒ Boolean
Indicates whether any of the streams are interesting.
77 78 79 |
# File 'lib/mm_tool/mm_movie.rb', line 77 def interesting? @streams.count {|stream| stream.interesting?} > 0 || format_title end |
#meets_minimum_quality? ⇒ Boolean
Indicates whether or not a file has at least one high- quality video stream and high-quality audio stream.
69 70 71 72 |
# File 'lib/mm_tool/mm_movie.rb', line 69 def meets_minimum_quality? @streams.count {|stream| stream.codec_type == 'audio' && !stream.low_quality? } > 0 && @streams.count {|stream| stream.codec_type == 'video' && !stream.low_quality? } > 0 end |
#stream_table ⇒ Object
For the given table, get the rendered text of the table for output.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/mm_tool/mm_movie.rb', line 100 def stream_table unless @stream_table @stream_table = stream_table_datasource.render(:unicode) do |renderer| renderer.alignments = [:center, :left, :left, :right, :right, :left, :left, :left, :left] renderer.column_widths = [5,10,10,5,10,5,23,50,35] renderer.multiline = true renderer.padding = [0,1] renderer.width = 1000 end # do end @stream_table end |