Commit e927fbd7 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Conversion module separated in classes and create action implemented with dspace calls

Signed-off-by: Israel Barreto Sant'Anna's avatarIsrael B. Sant'Anna <ibsa14@inf.ufpr.br>
parent 8934adbe
Showing with 53 additions and 29 deletions
+53 -29
......@@ -47,3 +47,5 @@ gem 'execjs'
gem 'therubyracer'
gem 'dspace-rest-client'
gem 'streamio-ffmpeg'
......@@ -14,13 +14,31 @@ class AulasController < ApplicationController
end
def create
request=DSpaceRest::Client.new(:dspaceurl => @@dspaceurl)
request.login('admin@dspace.com','admin')
new_item = request.new_item
new_item.set_metadata("dc.title",params[:title], "pt_BR")
new_item.set_metadata("dc.description",params[:description],"pt_BR")
uploaded_io = params[:file]
File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
end
file_path = Rails.root.join('public', 'uploads', uploaded_io.original_filename)
File.open(file_path, 'wb'){ |file| file.write(uploaded_io.read) }
=begin
converter = FFMPEGConverter.new(Rails.root.join('public', 'uploads'))
converter.convert(file_path) do |file,progress|
#check status of each conversion and do something with the new files
end
=end
coll = request.get_collection(1)
item = coll.post_item(new_item)
file = item.post_bitstream(file_path)
file.name = uploaded_io.original_filename
file.put_metadata
redirect_to :action => 'index'
end
def edit
......
require 'rubygems'
require 'streamio-ffmpeg'
class FFMPEGConverter < VideoConverter
module VideoConversion
def self.save_path
@@save_path
end
def self.save_path=(save_path)
@@save_path = save_path
end
def convert(video_path, &block)
super(video_path, &block)
def self.convert(video_path, &block)
@block = block
@movie = FFMPEG::Movie.new(video_path)
array = video_path.split('/')
file = array[array.length-1].split('.')
@video = {path: video_path, name: file[0], format: file[1]}
@options = {video_codec: "libx264", x264_preset: "ultrafast",
custom: "-movflags +faststart -threads 0"}
......@@ -32,32 +20,33 @@ module VideoConversion
return true
end
private_class_method def self.original_quality
private
def original_quality
@crf = "-crf 18"
@scale = @movie.width/@movie.height == 16/9 ?
"" : "-vf scale=-2:#{@movie.height*16/9}"
transcode(@@save_path+@video[:name]+"_oq.mp4")
transcode(@save_path+@video[:name]+"_oq.mp4")
end
private_class_method def self.high_quality
def high_quality
@crf = "-crf 18"
@scale = "-vf scale=-2:720"
transcode(@@save_path+@video[:name]+"_hq.mp4")
transcode(@save_path+@video[:name]+"_hq.mp4")
end
private_class_method def self.medium_quality
def medium_quality
@crf = "-crf 23"
@scale = "-vf scale=-2:480"
transcode(@@save_path+@video[:name]+"_mq.mp4")
transcode(@save_path+@video[:name]+"_mq.mp4")
end
private_class_method def self.low_quality
def low_quality
@crf = "-crf 28"
@scale = "-vf scale=-2:360"
transcode(@@save_path+@video[:name]+"_lq.mp4")
transcode(@save_path+@video[:name]+"_lq.mp4")
end
private_class_method def self.transcode(filepath)
def transcode(filepath)
opt = @options[:custom]
@options[:custom] = opt+" "+@crf+" "+@scale
@movie.transcode(filepath, @options) do |progress|
......@@ -65,4 +54,4 @@ module VideoConversion
end
@options[:custom] = opt
end
end
end
\ No newline at end of file
class VideoConverter
attr_acessor :save_path
def initialize(save_path)
@save_path = save_path
end
def convert(video_path, &block)
@block = block
array = video_path.split('/')
file = array[array.length-1].split('.')
@video = {path: video_path, name: file[0], format: file[1]}
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment