ruby on rails - Retrieve file and thumbnail url from AWS Elastic Transcoder job -


i have rails app uploads videos aws s3 bucket using cors configuration, when completed , rails video object created elastic transcoder job created encode video .mp4 format , generate thumbnail image, aws sns enabled send push notifications when job complete.

the process works nicely , receive sns notification when upload complete, can fetch video url fine notification contains thumbnail pattern rather actual filename.

below typical notification receive aws sns. nb. outputs hash

{"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 completed.", "duration"=>10, "width"=>202, "height"=>360} 

as can see under thumbnailpattern filepattern use, , not actual file created.

does know how can urls files created on elastic transcoder , sns?

transcoder.rb # => create new transcoder object when video has been 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 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 

videoscontroller #create

class videoscontroller < applicationcontroller   def create     @video = current_user.videos.build(params[:video])     respond_to |format|       if @video.save         transcode = transcoder.new(@video)         transcode.create         format.html { redirect_to videos_path, notice: 'video 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 

it doesn't appear actual name of thumbnails passed back, either sns notifications or request response upon creation of 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

because base path/name of thumbnails known, , sequence number start @ 00001, can iterate there determine if/how many of thumbnails exist upon job completion. ensure use head requests against objects in s3 determine presence; 10x cheaper doing list request.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -