Skip to content
Snippets Groups Projects
Commit d3c5fee1 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add flags to run in server

parent b14acc74
No related branches found
No related tags found
No related merge requests found
......@@ -5,50 +5,55 @@ class ConvertVideoWorker
sidekiq_options queue: :convert_video
def perform(id)
object = learning_object_repository.find id
# convert if object has a flv and not a mp4
video = nil
object.attachments.each do |attachment|
video = attachment if attachment.name =~ /(.flv|.wmv|.mov|.mpg)$/i
return true if attachment.name =~ /.mp4$/i
begin
object = learning_object_repository.find id
# convert if object has a flv and not a mp4
video = nil
object.attachments.each do |attachment|
video = attachment if attachment.name =~ /(.flv|.wmv|.mov|.mpg)$/i
return true if attachment.name =~ /.mp4$/i
end
return true if video.nil?
dspace_client = DspaceService.create_client
# retrieve video from dspace
original_bitstream = dspace_client.bitstreams.retrieve(id: video.id)
# open video with ffmpeg
# FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
FFMPEG.ffmpeg_binary = 'ffmpeg'
file = ::FFMPEG::Movie.new(original_bitstream.path)
return false unless file.valid? # if ffmpeg fails to read the movie
converted_path = "#{original_bitstream.path}.mp4"
# transcode (convert video to mp4)
options = {
video_codec: "libx264",
x264_preset: "fast",
custom: '-movflags +faststart -pix_fmt yuv420p -profile:v main -level 3.1 -refs 4 -b:a 160k -strict -2',
validate: true
}
file.transcode(converted_path, options)
converted = File.open converted_path
# send converted video to dspace
dspace_client.items.add_bitstream(converted, id: object.id_dspace, name: "#{video.name.split('.')[0..-2].join('.')}.mp4", description: 'converted from original flv')
p "Converted video for learning object #{id}"
ensure
# remove temp files
original_bitstream.unlink unless original_bitstream.nil?
unless converted.nil?
converted.close
FileUtils.rm converted_path, force: true
end
end
return true if video.nil?
dspace_client = DspaceService.create_client
# retrieve video from dspace
original_bitstream = dspace_client.bitstreams.retrieve(id: video.id)
# open video with ffmpeg
# FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
FFMPEG.ffmpeg_binary = 'ffmpeg'
file = ::FFMPEG::Movie.new(original_bitstream.path)
return false unless file.valid? # if ffmpeg fails to read the movie
converted_path = "#{original_bitstream.path}.mp4"
# transcode (convert video to mp4)
options = {
video_codec: "libx264",
x264_preset: "fast",
custom: '-movflags +faststart -pix_fmt yuv420p -profile:v main -level 3.1 -refs 4 -c:a libfdk_aac',
validate: true
}
file.transcode(converted_path, options)
converted = File.open converted_path
# send converted video to dspace
dspace_client.items.add_bitstream(converted, id: object.id_dspace, name: "#{video.name.split('.')[0..-2].join('.')}.mp4", description: 'converted from original flv')
# remove temp files
original_bitstream.unlink
converted.close
FileUtils.rm converted_path, force: true
p "Converted video for learning object #{id}"
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment