Class: TranscodingMachine::Server::MediaFileAttributes
- Inherits:
-
Hash
- Object
- Hash
- TranscodingMachine::Server::MediaFileAttributes
show all
- Defined in:
- lib/transcoding_machine/server/media_file_attributes.rb
Constant Summary
collapse
- ASPECT_RATIO_2_35_BY_1 =
2.35
- ASPECT_RATIO_16_BY_9 =
16.0 / 9.0
- ASPECT_RATIO_4_BY_3 =
4.0 / 3.0
- ASPECT_RATIO_NAMES =
{ASPECT_RATIO_2_35_BY_1 => '2.35/1', ASPECT_RATIO_16_BY_9 => '16/9', ASPECT_RATIO_4_BY_3 => '4/3'}
- ASPECT_RATIO_VALUES =
ASPECT_RATIO_NAMES.invert
- CODECS =
{'ffmp3' => :mp3, 'mp3' => :mp3, 'faad' => :aac, 'ffh264' => :h264, 'h264' => :h264, 'ffvp6f' => :flash_video}
- TRACK_FIELD_TYPES =
{
:codec => :codec,
:width => :integer,
:height => :integer,
:format => :string,
:aspect => :float,
:id => :integer,
:bitrate => :integer,
:fps => :float,
:file_name => :string,
:length => :float,
:demuxer => :string,
:rate => :integer,
:channels => :integer
}
- FIELD_TYPES =
{
:audio => :boolean,
:audio_format => :string,
:audio_rate => :integer,
:audio_bitrate => :integer,
:audio_codec => :codec,
:audio_channels => :integer,
:video => :boolean,
:video_format => :string,
:video_codec => :codec,
:width => :integer,
:height => :integer,
:aspect_ratio => :float,
:video_fps => :float,
:video_bitrate => :integer,
:ipod_uuid => :boolean,
:bitrate => :integer,
:length => :float,
:file_name => :string,
:file_extension => :string,
:demuxer => :string,
:poster_time => :float
}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MediaFileAttributes.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 58
def initialize(media_file_path)
super()
ffmpeg = FfmpegIntegrator.new(media_file_path)
mplayer = MplayerIntegrator.new(media_file_path)
puts "FFMPEG:\n#{ffmpeg.tracks.inspect}"
puts "MPLAYER:\n#{mplayer.tracks.inspect}"
store(:ipod_uuid, false)
merge!(get_video_info(get_video_track(ffmpeg.tracks), get_video_track(mplayer.tracks)))
merge!(get_audio_info(get_audio_track(ffmpeg.tracks), get_audio_track(mplayer.tracks)))
merge!(get_container_info(ffmpeg.tracks[:container], mplayer.tracks[:container]))
derive_values
if video?
atomic_parsley = AtomicParsleyIntegrator.new(media_file_path)
puts "ATOMIC_PARSLEY:\n#{atomic_parsley.tracks.inspect}"
store(:ipod_uuid, atomic_parsley.tracks[:container][:ipod_uuid])
exiftool = ExifToolIntegrator.new(media_file_path)
puts "EXIFTOOL:"
puts exiftool.inspect
store(:poster_time, exiftool.poster_time)
if exiftool.aspect_ratio and aspect_ratio != exiftool.aspect_ratio
store(:height, (width / exiftool.aspect_ratio).to_i)
store(:aspect_ratio, exiftool.aspect_ratio)
elsif exiftool.width && exiftool.height
store(:width, exiftool.width)
store(:height, exiftool.height)
derive_values
end
fix_dimensions
end
delete_if {|key, value| value.nil?}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
282
283
284
285
286
287
288
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 282
def method_missing(method_name, *args)
if (FIELD_TYPES[method_name])
self[method_name]
else
super
end
end
|
Class Method Details
.parse_values(values) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 120
def self.parse_values(values)
values.values.each do |track_values|
track_values.each do |key, value|
case TRACK_FIELD_TYPES[key]
when :integer
track_values[key] = value.to_i
when :float
track_values[key] = value.to_f
when :codec
track_values[key] = CODECS[value] || value
end
end
end
values
end
|
Instance Method Details
#audio? ⇒ Boolean
102
103
104
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 102
def audio?
audio
end
|
#thumbnail_file ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 106
def thumbnail_file
return @thumbnail_file if @thumbnail_file
return nil unless video? and height and width
time = poster_time
if time.nil? or time == 0 or time > 30
time = length / 10.0
time = 10 if time > 10
end
@thumbnail_file = FfmpegIntegrator.create_thumbnail(file_name, width, height, time)
end
|
#video? ⇒ Boolean
98
99
100
|
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 98
def video?
video
end
|