Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
5d235cf4
Commit
5d235cf4
authored
9 years ago
by
Mateus Rambo Strey
Browse files
Options
Downloads
Patches
Plain Diff
add video converter worker and task
parent
94405aab
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/workers/convert_video_worker.rb
+52
-0
52 additions, 0 deletions
app/workers/convert_video_worker.rb
config/sidekiq.yml
+1
-0
1 addition, 0 deletions
config/sidekiq.yml
lib/tasks/convert_video.rake
+39
-0
39 additions, 0 deletions
lib/tasks/convert_video.rake
with
92 additions
and
0 deletions
app/workers/convert_video_worker.rb
0 → 100644
+
52
−
0
View file @
5d235cf4
class
ConvertVideoWorker
include
Sidekiq
::
Worker
include
RepositoriesProxy
sidekiq_options
queue: :convert_video
def
perform
(
id
)
object
=
learning_object_repository
.
find
@learning_object
.
id
# convert if object has a flv and not a mp4
flv
=
nil
object
.
attachments
.
each
do
|
attachment
|
flv
=
attachment
if
attachment
.
name
=~
/.flv$/i
return
true
if
attachment
.
name
=~
/.mp4$/i
end
return
true
if
flv
.
nil?
dspace_client
=
DspaceService
.
create_client
# retrieve video from dspace
video
=
dspace_client
.
bitstreams
.
retrieve
(
id:
flv
.
id
)
# open video with ffmpeg
# FFMPEG.ffmpeg_binary = '/usr/local/bin/ffmpeg'
FFMPEG
.
ffmpeg_binary
=
'ffmpeg'
file
=
::
FFMPEG
::
Movie
.
new
(
video
.
path
)
return
false
unless
file
.
valid?
# if ffmpeg fails to read the movie
converted_path
=
"
#{
video
.
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:
"
#{
flv
.
name
.
split
(
'.'
)[
0
..-
2
].
join
(
'.'
)
}
.mp4"
,
description:
'converted from original flv'
)
# remove temp files
video
.
unlink
converted
.
close
FileUtils
.
rm
converted_path
,
force:
true
end
end
This diff is collapsed.
Click to expand it.
config/sidekiq.yml
+
1
−
0
View file @
5d235cf4
...
...
@@ -10,6 +10,7 @@
:queues
:
-
default
-
score
-
convert_video
-
[
high_priority
,
2
]
# :daemon: true
...
...
This diff is collapsed.
Click to expand it.
lib/tasks/convert_video.rake
0 → 100644
+
39
−
0
View file @
5d235cf4
namespace
:score
do
desc
"Generate Score"
task
:learning_object
=>
:environment
do
include
RepositoriesProxy
# Quantity of items fetched on each iteration
limit
=
500
# Start point from where items will be fetched
offset
=
0
loop
do
begin
# Get items from dspace (from offset to offset+limit)
items
=
learning_object_repository
.
all_from_offset_to_limit
(
offset
,
limit
)
rescue
# Sleeps for a while to wait database's recovery
sleep
(
10
.
seconds
)
# Goes to next iteration to retry
next
else
# Terminate loop if there are no more items to import
break
if
items
.
empty?
items
.
each
do
|
item
|
item
.
attachments
.
each
do
|
attachment
|
ConvertVideoWorker
.
perform_async
(
item
.
id
)
if
attachment
.
name
=~
/.flv$/i
end
end
# Increment offset, to get new items on next iteration
offset
+=
limit
end
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment