Class: EnMasse::Dragonfly::FFMPEG::Encoder
- Inherits:
-
Object
- Object
- EnMasse::Dragonfly::FFMPEG::Encoder
- Includes:
- Dragonfly::Configurable
- Defined in:
- lib/dragonfly-ffmpeg/encoder.rb,
lib/dragonfly-ffmpeg/encoder/profile.rb
Defined Under Namespace
Classes: Profile
Instance Method Summary collapse
-
#encode(temp_object, format, profile = :html5, options = {}) ⇒ Object
Encodes a Dragonfly::TempObject with the given format.
Instance Method Details
#encode(temp_object, format, profile = :html5, options = {}) ⇒ Object
Encodes a Dragonfly::TempObject with the given format.
An optional profile may be specified by passing a symbol in as the optional profile parameter. Profiles are defined by the configurable attribute ‘encoder_profiles’ - by default one profile is defined for major web formats, :html5.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dragonfly-ffmpeg/encoder.rb', line 77 def encode(temp_object, format, profile = :html5, = {}) [:meta] = {} unless [:meta] format = format.to_sym original_basename = File.basename(temp_object.path, '.*') raise UnsupportedFormat, "Format not supported - #{format}" unless supported_format?(format) unless profile.is_a?(Profile) raise UnknownEncoderProfile unless profile_defined?(format, profile.to_sym) profile = get_profile(format, profile.to_sym) end .merge!(profile.) origin = ::FFMPEG::Movie.new(temp_object.path) tempfile = new_tempfile(format, original_basename) transcoded_file = origin.transcode(tempfile.path, ) if(format.to_s == 'mp4' && `qt-faststart`) `qt-faststart #{transcoded_file.path} #{transcoded_file.path}.tmp.mp4` `mv #{transcoded_file.path}.tmp.mp4 #{transcoded_file.path}` end content = ::Dragonfly::TempObject.new(File.new(transcoded_file.path)) = { :name => (original_basename + ".#{format}"), :format => format, :ext => File.extname(transcoded_file.path) }.merge([:meta]) [ content, ] end |