【发布时间】:2014-05-02 16:19:02
【问题描述】:
我有一个 rails 应用程序,它使用他们的 CORS 配置将视频上传到 AWS S3 存储桶,当这完成并创建 rails 视频对象时,会创建一个 Elastic Transcoder 作业以将视频编码为 .mp4 格式并生成缩略图如图所示,AWS SNS 已启用以在作业完成时发送推送通知。
整个过程运行良好,上传完成后我会收到一条 SNS 通知,但是我可以正常获取视频 url,但通知只包含缩略图模式而不是实际文件名。
以下是我从 AWS SNS 收到的典型通知。注意。这是来自输出哈希
{"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 创建的文件的 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
视频控制器#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
【问题讨论】:
标签: ruby-on-rails video amazon-web-services amazon-s3 amazon-sns