ruby-on-rails – 从AWS Elastic Transcoder作业中检索文件和缩
我有一个rails应用程序,使用他们的CORS配置将视频上传到AWS S3存储桶,当完成此操作并创建rails视频对象时,会创建Elastic Transcoder作业以将视频编码为.mp4格式并生成缩略图图像,AWS SNS可以在作业完成时发送推送通知.
这个过程都运行良好,我在上传完成时收到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下看到的那样,只是要使用的文件模式,而不是创建的实际文件. 有谁知道我如何获得通过弹性转码器和SNS创建的文件的URLS? 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 #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倍左右. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |