Class: SmartVideoPosterExtractionWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/smart_video_poster_extraction_worker.rb

Overview

Sidekiq worker: smart video poster extraction.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(video_id, options = {}, redirect_to = nil) ⇒ Object

Parameters:

  • video_id (Integer)
  • options (Hash) (defaults to: {})

    optional: min_start, threshold, fallback

  • redirect_to (String) (defaults to: nil)

    optional redirect path to return to when done



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/workers/smart_video_poster_extraction_worker.rb', line 13

def perform(video_id, options = {}, redirect_to = nil)
  video = Video.find(video_id)

  min_start = (options['min_start'] || 5.0).to_f
  threshold = (options['threshold'] || 0.40).to_f
  fallback  = (options['fallback'] || 10.0).to_f

  total(100)
  at(0, "Starting smart poster detection for #{video.title}")
  store redirect_to: redirect_to if redirect_to.present?

  at(25, 'Detecting representative timestamp...')
  svc = SmartVideoPosterExtractionService.new(
    video,
    min_start_seconds: min_start,
    scene_threshold: threshold,
    fallback_seconds: fallback
  )

  svc.extract_poster

  at(100, 'Smart poster extraction completed successfully!')
rescue VideoPosterExtractionService::ExtractionError => e
  store error_message: e.message
  raise
end