Extract file and thumbnail sketch from AWS Elastic Transcoder job

I have a rails application that loads video into an AWS S3 bucket using their CORS configuration when it is completed and a video object with rails is created, an Elastic Transcoder task is created to encode the video in .mp4 format and create a thumbnail image, AWS SNS allows you to send push notifications when the task is completed.

The process works well, and I get an SNS notification when the download is complete, however I can only get the video URL perfectly, but the notification only contains the thumbnail template and not the actual file name.

The following is a typical notification that I receive from AWS SNS. NB. This is from the hash outputs

{"id"=>"1", "presetId"=>"1351620000001-000040", "key"=>"uploads/video/150/557874e9-4c67-40f0-8f98-8c59506647e5/IMG_0587.mp4", "thumbnailPattern"=>"uploads/video/150/557874e9-4c67-40f0-8f98-8c59506647e5/{count}IMG_0587", "rotate"=>"auto", "status"=>"Complete", "statusDetail"=>"The transcoding job is completed.", "duration"=>10, "width"=>202, "height"=>360}

As you can see under thumbnailPattern, this is just the file to be used, not the actual file.

Does anyone know how I can get URLS for files created through elastic transcoder and SNS?

transcoder.rb # => I create a new transcoder object when the video was saved

class Transcoder < Video
  def initialize(video)
    @video = video
    @directory = "uploads/video/#{@video.id}/#{SecureRandom.uuid}/"
    @filename = File.basename(@video.file, File.extname(@video.file))
  end

  def create
    transcoder = AWS::ElasticTranscoder::Client.new(region: "us-east-1")
    options = {
      pipeline_id: CONFIG[:aws_pipeline_id],
      input: { 
        key: @video.file.split("/")[3..-1].join("/"), # slice off the amazon.com bit 
        frame_rate: "auto", 
        resolution: 'auto', 
        aspect_ratio: 'auto', 
        interlaced: 'auto', 
        container: 'auto' 
        },
      outputs: [
        {
          key: "#{@filename}.mp4", 
          preset_id: '1351620000001-000040', 
          rotate: "auto", 
          thumbnail_pattern: "{count}#{@filename}"
        }
      ],
      output_key_prefix: "#{@directory}"
    }
    job = transcoder.create_job(options)
    @video.job_id = job.data[:job][:id]
    @video.save!
  end
end

VideoController #create

class VideosController < ApplicationController
  def create
    @video = current_user.videos.build(params[:video])
    respond_to do |format|
      if @video.save
        transcode = Transcoder.new(@video)
        transcode.create
        format.html { redirect_to videos_path, notice: 'Video was successfully uploaded.' }
        format.json { render json: @video, status: :created, location: @video }
        format.js 
      else
        format.html { render action: "new" }
        format.json { render json: @video.errors, status: :unprocessable_entity }
      end
    end
  end
end
+4
source share
2 answers

It doesn't seem that the actual name of the thumbnails is passed back either from SNS notifications or from a response to a request when creating a job:

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html#create-job-examples

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/notifications.html

/ , 00001, , , / . , HEAD- S3, ; 10 , LIST.

+6

4 . , , .

: (/) . , , . S3 ObjectCreate(All) SNS. backend endpoint - , - . regexp, , .

+1

Source: https://habr.com/ru/post/1533263/


All Articles