lib/dragonfly-ffmpeg/encoder.rb in dragonfly-ffmpeg-0.0.4 vs lib/dragonfly-ffmpeg/encoder.rb in dragonfly-ffmpeg-0.1.0
- old
+ new
@@ -14,18 +14,17 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'streamio-ffmpeg'
require 'pathname'
-require 'dragonfly-ffmpeg/encoder/profile'
module EnMasse
module Dragonfly
module FFMPEG
class Encoder
+ autoload :Profile, 'dragonfly-ffmpeg/encoder/profile'
include ::Dragonfly::Configurable
configurable_attr :encoder_profiles, {
:mp4 => [
@@ -67,27 +66,34 @@
configurable_attr :output_directory, '/tmp'
def encode(temp_object, format, profile = :html5, options = {})
format = format.to_sym
+
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
options.merge!(profile.encoding_options)
origin = ::FFMPEG::Movie.new(temp_object.path)
- tempfile = new_tempfile(format)
- transcoded = origin.transcode(tempfile.path, options)
- ::Dragonfly::TempObject.new(File.new(transcoded.path))
+ tempfile = new_tempfile(format, File.basename(temp_object.path, '.*'))
+ transcoded_file = origin.transcode(tempfile.path, options)
+
+ [
+ ::Dragonfly::TempObject.new(File.new(transcoded_file.path)),
+ :name => File.basename(transcoded_file.path),
+ :format => format,
+ :ext => File.extname(transcoded_file.path)
+ ]
end
private
- def new_tempfile(ext = nil)
- tempfile = ext ? Tempfile.new(["dragonfy-video", ".#{ext}"]) : Tempfile.new("dragonfly-video")
+ def new_tempfile(ext = nil, name = 'dragonfly-video')
+ tempfile = ext ? Tempfile.new(["#{name}-", ".#{ext}"]) : Tempfile.new("#{name}-")
tempfile.binmode
tempfile.close
tempfile
end