从AWS Elastic Transcoder作业中检索文件和缩略图URL

我有一个rails应用程序,使用他们的CORS配置将video上传到AWS S3存储桶,当完成此操作并创建railsvideo对象时,会创建Elastic Transcoder作业以将video编码为.mp4格式并生成缩略图图像,AWS SNS可以在作业完成时发送推送通知。

这个过程都运行良好,上传完成后我收到SNS通知,但我可以获取videourl,但通知只包含缩略图模式而不是实际文件名。

以下是我从AWS SNS收到的典型通知。 NB。 这是来自输出哈希

{"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} 

正如您在thumbnailPattern下看到的那样,只是要使用的文件模式,而不是创建的实际文件。

有谁知道我如何获得通过弹性转码器和SNS创建的文件的URLS?

transcoder.rb#=>我在保存video时创建了一个新的转码器对象

 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 

VideosController #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 

似乎没有从SNS通知或创建作业时的请求响应传回缩略图的实际名称:

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开始,因此您可以从那里进行迭代以确定作业完成时是否存在多少缩略图。 确保对S3中的对象使用HEAD请求以确定它们的存在; 它比做LIST请求便宜10倍左右。

它在最后一次回复后通过了4年。 新冷战提出,存在很多政治紧张局势,但亚马逊的基石并没有解决这个问题。

作为解决方法,我找到了另一种解决方案:通常将转码后的文件(video/缩略图)放入新存储桶中。 或者至少在一些前缀下。 我为ObjectCreate(All)为目标存储桶和指定的前缀创建了新的S3事件,并将其连接到预先创建的SNS主题。 这个主题两次ping我的后端的端点 – 第一次是video转码,第二次是缩略图创建。 使用regexp很容易区分出什么是什么。