Class: RademadeAdmin::VideoService
- Inherits:
-
Object
- Object
- RademadeAdmin::VideoService
- Defined in:
- app/services/video_service.rb
Instance Method Summary collapse
- #duration_in_seconds ⇒ Object
-
#initialize(file_path) ⇒ VideoService
constructor
A new instance of VideoService.
- #take_random_screenshot(thumb_path) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ VideoService
Returns a new instance of VideoService.
4 5 6 |
# File 'app/services/video_service.rb', line 4 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#duration_in_seconds ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'app/services/video_service.rb', line 14 def duration_in_seconds output = `ffmpeg -i #{@file_path} 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//` if output =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/ (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) + ($4.to_i / 100) else nil end end |
#take_random_screenshot(thumb_path) ⇒ Object
8 9 10 11 12 |
# File 'app/services/video_service.rb', line 8 def take_random_screenshot(thumb_path) duration = duration_in_seconds screenshot_time = 1 + (duration.nil? ? 0 : Random.rand(duration - 1)) `ffmpeg -ss #{screenshot_time} -i #{@file_path} -f image2 -vframes 1 #{thumb_path}` end |