4

我有一個使用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 

回答

7

它不會出現一個新的轉碼器對象的實際名稱縮略圖從創建作業時的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倍。

+3

似乎很瘋狂,這個網址沒有發送/更新的工作或在SNS通知 – dodgerogers747

+0

我同意;希望AWS ETS團隊會接受這個基於AWS論壇帖子的增強/功能請求。 –

相關問題