Process one derivative in the background and another syncronously?

Hi there!

I’m transcoding a video to MP4 so that iOS can play it, and I’m also creating a screenshot. Here’s the code:

class VideoUploader < Shrine
  plugin :derivatives

  Attacher.derivatives do |original|
    transcoded = Tempfile.new ["transcoded", ".mp4"]
    screenshot = Tempfile.new ["screenshot", ".jpg"]

    movie = FFMPEG::Movie.new(original.path)
    movie.transcode(transcoded.path)
    movie.screenshot(screenshot.path)

    { transcoded: transcoded, screenshot: screenshot }
  end
end

We are recording from the browser and then letting the user preview an email - so the thumbnail needs to be instant / not in the background. The transcoding can take its time though - we don’t want the user waiting for it - and by the time someone opens the email, it will be done.

Is it possible somehow to only move the movie.transcode process into the background, but keep the screenshot happening synchronously?

Thank you!

You can put each derivative in a separate processor, then call one synchronously before saving the record, and the other one in the background job. The method is Attacher#create_derivatives.