Class: MmTool::MmMovieStream
- Inherits:
-
Object
- Object
- MmTool::MmMovieStream
- Defined in:
- lib/mm_tool/mm_movie_stream.rb
Overview
A stream of an MmMovie. Instances contain simple accessors to the data made available by ffmpeg, and have knowledge on how to generate useful arguments for ffmpeg and mkvpropedit.
Instance Attribute Summary collapse
-
#file_number ⇒ Object
———————————————————— Attribute accessors ————————————————————.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Class Method Summary collapse
-
.streams(with_files:, owner_ref:) ⇒ Object
———————————————————— Given an array of related files, this class method returns an array of MmMovieStreams reflecting the streams present in each of them.
Instance Method Summary collapse
-
#action_label ⇒ Object
———————————————————— Property - returns a convenient label indicating the recommended actions for the stream.
-
#channel_layout ⇒ Object
———————————————————— Property - returns the channel layout of the stream.
-
#channels ⇒ Object
———————————————————— Property - returns the number of channels of the stream.
-
#codec_name ⇒ Object
———————————————————— Property - returns the codec name of the stream.
-
#codec_type ⇒ Object
———————————————————— Property - returns the codec type of the stream.
-
#coded_height ⇒ Object
———————————————————— Property - returns the coded height of the stream.
-
#coded_width ⇒ Object
———————————————————— Property - returns the coded width of the stream.
-
#copy? ⇒ Boolean
———————————————————— Property - stream action includes :copy? ————————————————————.
-
#default? ⇒ Boolean
———————————————————— Property - indicates whether or not the stream is the default stream per its dispositions.
-
#dispositions ⇒ Object
———————————————————— Property - returns the disposition flags of the stream as a comma-separated list for compactness.
-
#drop? ⇒ Boolean
———————————————————— Property - stream action includes :drop? ————————————————————.
-
#index ⇒ Object
———————————————————— Property - returns the index of the stream.
-
#initialize(stream_data:, source_file:, file_number:, streams_ref:, owner_ref:) ⇒ MmMovieStream
constructor
———————————————————— Initialize ————————————————————.
-
#input_specifier ⇒ Object
———————————————————— Property - returns the input specifier of the stream.
-
#instruction_action ⇒ Object
———————————————————— Property - returns an instruction for handling the stream, according to the action(s) determined.
-
#instruction_disposition ⇒ Object
———————————————————— Property - returns an instruction for setting the stream’s default disposition, if necessary.
-
#instruction_input ⇒ Object
———————————————————— Property - returns the -i input instruction for this stream.
-
#instruction_map ⇒ Object
———————————————————— Property - returns the -map instruction for this stream, according to the action(s) determined.
-
#instruction_metadata ⇒ Object
———————————————————— Property - returns instructions for setting the metadata of the stream, if necessary.
-
#interesting? ⇒ Boolean
———————————————————— Property - stream action includes :interesting? ————————————————————.
-
#language ⇒ Object
———————————————————— Property - returns the language of the stream, or ‘und’ if the language is not defined.
-
#low_quality? ⇒ Boolean
———————————————————— Property - indicates whether or not the stream is considered “low quality” based on the application configuration.
-
#one_of_a_kind? ⇒ Boolean
———————————————————— Property - indicates whether or not this stream is the only one of its type.
-
#output_index ⇒ Object
———————————————————— Property - returns the index of the stream in the output file.
-
#output_specifier ⇒ Object
———————————————————— Property - returns a specific output specifier for the stream, such as v:0 or a:2.
-
#output_unique? ⇒ Boolean
———————————————————— Property - indicates whether or not the stream will be unique for its type at output.
-
#quality_01 ⇒ Object
———————————————————— Property - returns an appropriate “quality” indicator based on the type of the stream.
-
#quality_02 ⇒ Object
———————————————————— Property - returns a different appropriate “quality” indicator based on the type of the stream.
-
#set_language? ⇒ Boolean
———————————————————— Property - stream action includes :set_language? ————————————————————.
-
#title ⇒ Object
———————————————————— Property - returns the title of the stream, or nil.
-
#transcode? ⇒ Boolean
———————————————————— Property - stream action includes :transcode? ————————————————————.
Constructor Details
#initialize(stream_data:, source_file:, file_number:, streams_ref:, owner_ref:) ⇒ MmMovieStream
Initialize
36 37 38 39 40 41 42 43 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 36 def initialize(stream_data:, source_file:, file_number:, streams_ref:, owner_ref:) @defaults = MmUserDefaults.shared_user_defaults @data = stream_data @source_file = source_file @file_number = file_number @streams = streams_ref @owner_ref = owner_ref end |
Instance Attribute Details
#file_number ⇒ Object
Attribute accessors
48 49 50 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 48 def file_number @file_number end |
#source_file ⇒ Object
Returns the value of attribute source_file.
49 50 51 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 49 def source_file @source_file end |
Class Method Details
.streams(with_files:, owner_ref:) ⇒ Object
Given an array of related files, this class method returns an array of MmMovieStreams reflecting the streams present in each of them.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 18 def self.streams(with_files:, owner_ref:) # Arrays are passed around by reference; when this array is created and # used as a reference in each stream, and *also* returned from this class # method, everyone will still be using the same reference. It's important # below to build up this array without replacing it with another instance. streams = [] with_files.each_with_index do |path, i| ff_movie = FFMPEG::Movie.new(path) ff_movie.[:streams].each do |stream| streams << MmMovieStream.new(stream_data: stream, source_file: path, file_number: i, streams_ref: streams, owner_ref: owner_ref) end end streams end |
Instance Method Details
#action_label ⇒ Object
Property - returns a convenient label indicating the
recommended actions for the stream.
175 176 177 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 175 def action_label "#{output_specifier} #{actions.select {|a| a != :interesting}.join(' ')}" end |
#channel_layout ⇒ Object
Property - returns the channel layout of the stream.
103 104 105 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 103 def channel_layout @data[:channel_layout] end |
#channels ⇒ Object
Property - returns the number of channels of the stream.
96 97 98 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 96 def channels @data[:channels] end |
#codec_name ⇒ Object
Property - returns the codec name of the stream.
68 69 70 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 68 def codec_name @data[:codec_name] end |
#codec_type ⇒ Object
Property - returns the codec type of the stream.
75 76 77 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 75 def codec_type @data[:codec_type] end |
#coded_height ⇒ Object
Property - returns the coded height of the stream.
89 90 91 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 89 def coded_height @data[:coded_height] end |
#coded_width ⇒ Object
Property - returns the coded width of the stream.
82 83 84 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 82 def coded_width @data[:coded_width] end |
#copy? ⇒ Boolean
Property - stream action includes :copy?
212 213 214 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 212 def copy? actions.include?(:copy) end |
#default? ⇒ Boolean
Property - indicates whether or not the stream is the
default stream per its dispositions.
183 184 185 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 183 def default? @data[:disposition][:default] == 1 end |
#dispositions ⇒ Object
Property - returns the disposition flags of the stream as
a comma-separated list for compactness.
137 138 139 140 141 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 137 def dispositions MmMovie.dispositions .collect {|symbol| @data[:disposition][symbol]} .join(',') end |
#drop? ⇒ Boolean
Property - stream action includes :drop?
205 206 207 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 205 def drop? actions.include?(:drop) end |
#index ⇒ Object
Property - returns the index of the stream.
54 55 56 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 54 def index @data[:index] end |
#input_specifier ⇒ Object
Property - returns the input specifier of the stream.
61 62 63 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 61 def input_specifier "#{@file_number}:#{index}" end |
#instruction_action ⇒ Object
Property - returns an instruction for handling the stream,
according to the action(s) determined.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 295 def instruction_action if copy? "-codec:#{output_specifier} copy \\" elsif transcode? if codec_type == 'audio' encode_to = @defaults[:codecs_audio_preferred][0] elsif codec_type == 'video' encode_to = @defaults[:codecs_video_preferred][0] else raise Exception.new "Error: somehow the program branched where it shouldn't have." end "-codec:#{output_specifier} #{encoder_string(for_codec: encode_to)} \\" else nil end end |
#instruction_disposition ⇒ Object
Property - returns an instruction for setting the stream’s
default disposition, if necessary.
334 335 336 337 338 339 340 341 342 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 334 def instruction_disposition set_disposition = output_unique? && !default? && !drop? ? "default " : nil if set_disposition "-disposition:#{output_specifier} #{set_disposition}\\" else nil end end |
#instruction_input ⇒ Object
Property - returns the -i input instruction for this
stream.
274 275 276 277 278 279 280 281 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 274 def instruction_input src = if @file_number == 0 File.join(File.dirname(@source_file), File.basename(@source_file, '.*') + @defaults[:suffix] + File.extname(@source_file)) else @source_file end "-i \"#{src}\" \\" end |
#instruction_map ⇒ Object
Property - returns the -map instruction for this stream,
according to the action(s) determined.
287 288 289 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 287 def instruction_map drop? ? nil : "-map #{input_specifier} \\" end |
#instruction_metadata ⇒ Object
Property - returns instructions for setting the metadata
of the stream, if necessary.
316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 316 def return [] if @actions.include?(:drop) # We only want to set fixed_lang if options allow us to fix the language, # and we want to set subtitle language from the filename, if applicable. fixed_lang = @defaults[:fix_undefined_language] ? @defaults[:undefined_language] : nil lang = subtitle_file_language ? subtitle_file_language : fixed_lang result = [] result << "-metadata:s:#{output_specifier} language=#{lang} \\" if set_language? result << "-metadata:s:#{output_specifier} title=\"#{title}\" \\" if title && ! @defaults[:ignore_titles] result end |
#interesting? ⇒ Boolean
Property - stream action includes :interesting?
233 234 235 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 233 def interesting? actions.include?(:interesting) end |
#language ⇒ Object
Property - returns the language of the stream, or ‘und’
if the language is not defined.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 111 def language if @data.key?(:tags) lang = @data[:tags][:language] lang = @data[:tags][:LANGUAGE] unless lang lang = 'und' unless lang else lang = 'und' end lang end |
#low_quality? ⇒ Boolean
Property - indicates whether or not the stream is
considered "low quality" based on the application
configuration.
192 193 194 195 196 197 198 199 200 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 192 def low_quality? if codec_type == 'audio' channels.to_i < @defaults[:min_channels].to_i elsif codec_type == 'video' coded_width.to_i < @defaults[:min_width].to_i else false end end |
#one_of_a_kind? ⇒ Boolean
Property - indicates whether or not this stream is the
only one of its type.
249 250 251 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 249 def one_of_a_kind? @streams.count {|s| s.codec_type == codec_type && s != self } == 0 end |
#output_index ⇒ Object
Property - returns the index of the stream in the output
file.
257 258 259 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 257 def output_index @streams.select {|s| !s.drop? }.index(self) end |
#output_specifier ⇒ Object
Property - returns a specific output specifier for the
stream, such as v:0 or a:2.
265 266 267 268 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 265 def output_specifier idx = @streams.select {|s| s.codec_type == codec_type && !s.drop?}.index(self) idx ? "#{codec_type[0]}:#{idx}" : ' ⬇ ' end |
#output_unique? ⇒ Boolean
Property - indicates whether or not the stream will be
unique for its type at output.
241 242 243 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 241 def output_unique? @streams.count {|s| s.codec_type == codec_type && !s.drop? } == 1 end |
#quality_01 ⇒ Object
Property - returns an appropriate “quality” indicator
based on the type of the stream.
147 148 149 150 151 152 153 154 155 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 147 def quality_01 if codec_type == 'audio' channels elsif codec_type == 'video' coded_width else nil end end |
#quality_02 ⇒ Object
Property - returns a different appropriate “quality”
indicator based on the type of the stream.
161 162 163 164 165 166 167 168 169 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 161 def quality_02 if codec_type == 'audio' channel_layout elsif codec_type == 'video' coded_height else nil end end |
#set_language? ⇒ Boolean
Property - stream action includes :set_language?
226 227 228 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 226 def set_language? actions.include?(:set_language) end |
#title ⇒ Object
Property - returns the title of the stream, or nil.
125 126 127 128 129 130 131 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 125 def title if @data.key?(:tags) @data[:tags][:title] else nil end end |
#transcode? ⇒ Boolean
Property - stream action includes :transcode?
219 220 221 |
# File 'lib/mm_tool/mm_movie_stream.rb', line 219 def transcode? actions.include?(:transcode) end |