我有一個使用CORS配置將視頻上傳到AWS S3存儲桶的rails應用程序,當完成此操作並創建rails視頻對象時,將創建Elastic Transcoder作業以編碼將視頻轉換爲.mp4格式並生成縮略圖圖像,AWS SNS可在作業完成時發送推送通知。從AWS Elastic Transcoder作業中檢索文件和縮略圖url
該過程一切正常,當上傳完成時我收到SNS通知,但是我可以獲取視頻網址,但通知只包含縮略圖模式而非實際文件名。
下面是我從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只是使用filepattern,而不是實際創建的文件。
有誰知道我可以如何獲得通過彈性代碼轉換器和SNS創建的文件的URL?
transcoder.rb#=>創建當視頻被保存
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#創建
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通知 – dodgerogers747
我同意;希望AWS ETS團隊會接受這個基於AWS論壇帖子的增強/功能請求。 –