AWS-Ruby SDK and Elastic Transcoder Example

AWS Elastic Transcoder is a very handy service if you looking for a cost effective, scalable solution to Transcode your audio or video files. AWS Elastic Transcoder takes input from a S3 bucket, transcodes it, and writes the resulting file to another S3 bucket - well you could also use the same bucket if you prefer.

Here is a very quick code extracted from one of a project I'm currenly working on. Here the uploaded .m4a audio files will be transcoded to HLS (HTTP Live Streaming) - m4a files will be first uploaded to a S3 bucket let’s call it “”. Files will be saved on the root of the input s3 bucket{UUID}.m4a and transcoded HLS audio will be saved on{UUID}/index.m3u8

#### transcoder.rb ####
class Transcoder < Message

  STATUS_SUBMITTED =  "Submitted"
  STATUS_PROGRESSING =  "Progressing"
  STATUS_COMPLETE =  "Complete"
  STATUS_CANCELED =  "Canceled"
  STATUS_ERROR =  "Error"

  def initialize(message)
    @message = message

  def create
    uuid =
    transcode_job_uuid = uuid.generate

    transcoder =
      :access_key_id => "YOUR_AWS_ACCESS_KEY_ID",
      :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY",
      :region => "us-east-1")


    options = {
      pipeline_id: "1432361831290-XXXXX",
      input: {
        key: "ACB685E9-8C3C-4E5D-A49A-8F3BB5298DDC-201509021233.m4a"
      outputs: [
          key: "hls_64k",
          preset_id: '1351620000001-200071',
          segment_duration: "10"
      playlists: [
          name: "index",
          format: "HLSv4",
          output_keys: ["hls_64k"]
      output_key_prefix: "hlsv4/#{}-#{transcode_job_uuid}/"
    job = transcoder.create_job(options)

      transcode_job_uuid: transcode_job_uuid,
      state: Message::STATE_PUBLISHED)



As you have already noticed, I'm using an UUID to keep track of the data submited to S3, Trancoder pipeline with active record - (MySQL database).

The example above writes the resulting job data to active record object immediately after submit the job to transcoder service.[:job][:id] is the uniqe identification (Usually looks like 1441177406727-xxxxx) returned from AWS which you can use for further querying the transcoder API and get the details of the submited job.

      transcode_job_uuid: transcode_job_uuid,
      state: Message::STATE_PUBLISHED)

You can also configure Elastic transcoder to work with SNS. AWS transcoder service will trigger SNS notifications to a predefined topic based on these events.

  • On Progressing Event
  • On Warning Event
  • On Completion Event
  • On Error Event

For example once the transcode job is finished SNS will notify the status of the job to an endpoint you have configured on your SNS topic.

Hope this helps - Happy coding :)


How to deploy rails 3.1 app on heroku Cedar stack

Linux tips: Check whether the mongrel port 3000 is open

Linux tips: How To Search Shell Command History

How to Install Ruby 1.9.2 and Rails 3.0 on Ubuntu

Most of the developers still use package managers to install ruby. This approach works, but most of the times it leads to dependency issues every now and then. Usually I don't use package managers to install ruby, instead I use ruby version manager (RVM) by wayneeseguin

In this post I'm going to install ruby 1.9.2 on Ubuntu with the help of rvm.

Usually I use "aptitude" to install packages as It's a better way to track the dependencies. If you don't have it installed on your system, you can get it by executing these command on a shell prompt.

Great everything is ready for you now. Have fun with rails 3.