检索文件和缩略图URL从AWS弹性跨codeR工作 [英] Retrieve file and thumbnail url from AWS Elastic Transcoder job

查看:222
本文介绍了检索文件和缩略图URL从AWS弹性跨codeR工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序中使用自己的CORS的配置,在此完成,铁轨视频对象被创建CR作业创建连接code视频的弹性横贯$ C $其中上传视频到AWS S3存储为.MP4​​格式,并生成一个缩略图,AWS SNS允许发送推送通知时,作业完成。

该过程中的所有工作得很好,我收到SNS通知时上传完成,不过,我可以获取视频网址就好了,但通知仅包含缩略图模式,而不是实际的文件名。

下面是一个典型的通知,我从AWS SNS接收。 NB。这是从输出散列

  {ID=>中1,presetId=>中1351620000001-000040,键=>中上传/视频/ 150 /557874e9-4c67-40f0-8f98-8c59506647e5/IMG_0587.mp4,thumbnailPattern=>中上传/视频/ 150 / 557874e9-4c67-40f0-8f98-8c59506647e5 / {数} IMG_0587,旋转=&GT ;自动,状态=>中完成,statusDetail=>中的转码作业完成。,持续时间=> 10,宽度=> 202,高度= > 360}
 

正如你可以thumbnailPattern下看到的是刚刚创建的filepattern使用,而不是实际的文件。

有谁知道我如何能得到的URL超过弹性跨codeR和SNS?

创建的文件

跨coder.rb#=>创建时的视频被保存一个新的跨codeR对象

 类泛$ C $为CR视频
  高清初始化(视频)
    @video =视频
    @directory =uploads/video/#{@video.id}/#{SecureRandom.uuid}/
    @filename = File.basename(@ video.file,File.extname(@ video.file))
  结束

  DEF创建
    跨codeR = AWS :: ElasticTrans codeR :: Client.new(区:美东-1)
    选项​​= {
      pipeline_id:CONFIG [:aws_pipeline_id]
      输入:{
        关键:@ video.file.split(/)[3 ..- 1]。加入(/),#片落amazon.com位
        帧频:自动,
        解析:自动,
        aspect_ratio:自动,
        隔行扫描:'汽车',
        集装箱:自动
        },
      输出:
        {
          键:#{@filename}.mp4
          preset_id的:1351620000001-000040,
          转:自动,
          thumbnail_pattern:{数量}#{@文件名}
        }
      ]
      output_key_ preFIX:#{@目录}
    }
    工作=反coder.create_job(选项)
    @ video.job_id = job.data [:工作] [:ID]
    @ video.save!
  结束
结束
 

VideosController #create

 类VideosController<的ApplicationController
  DEF创建
    @video = current_user.videos.build(PARAMS [:视频])
    respond_to代码做|格式|
      如果@ video.save
        跨code =反coder.new(@video)
        跨code.create
        的format.html {redirect_to时videos_path,注意:视频被上传成功 }
        format.json {渲染JSON:@video,状态:创建,地点:@video}
        format.js
      其他
        的format.html {渲染的动作:新}
        format.json {渲染JSON:@ video.errors,状态:unprocessable_entity}
      结束
    结束
  结束
结束
 

解决方案

它不会出现缩略图的实际名称被传递回来,无论是从SNS通知或在创建工作的请求响应:

<一个href="http://docs.aws.amazon.com/elastictrans$c$cr/latest/developerguide/create-job.html#create-job-examples">http://docs.aws.amazon.com/elastictrans$c$cr/latest/developerguide/create-job.html#create-job-examples

<一个href="http://docs.aws.amazon.com/elastictrans$c$cr/latest/developerguide/notifications.html">http://docs.aws.amazon.com/elastictrans$c$cr/latest/developerguide/notifications.html

由于缩略图的基本路径/名称已知,序列号总是从00001开始,你可以从那里重复,以确定是否/作业完成后如何缩略图许多存在。确保您使用针对S3对象HEAD请求,以确定他们的presence;它的10倍左右不是做一个LIST请求便宜。

I have a rails app which uploads videos to an AWS S3 bucket using their CORS configuration, when this is completed and the rails video object is created an Elastic Transcoder job is created to encode the video to .mp4 format and generate a thumbnail image, AWS SNS is enabled to send push notifications when the job is complete.

The process all works nicely and I receive a SNS notification when the upload is complete, however I can fetch the video url just fine but the notification only contains the thumbnail pattern rather than the actual filename.

Below is a typical notification I receive from AWS SNS. NB. This is from the outputs hash

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

As you can see under thumbnailPattern is just the filepattern to use, and not the actual file created.

Does anyone know how I can get the URLS to the files created over elastic transcoder and SNS?

transcoder.rb # => I create a new transcoder object when a video has been saved

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

解决方案

It doesn't appear that the actual name of the thumbnails are passed back, either from SNS notifications or from the request response upon creation of a job:

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/create-job.html#create-job-examples

http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/notifications.html

Because the base path/name of your thumbnails is known, and the sequence number will always start at 00001, you can iterate from there to determine if/how many of the thumbnails exist upon job completion. Ensure you use HEAD requests against the objects in S3 to determine their presence; its about 10x cheaper than doing a LIST request.

这篇关于检索文件和缩略图URL从AWS弹性跨codeR工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆