Skip to content

Instantly share code, notes, and snippets.

@mmcc
Created January 22, 2013 21:46
Show Gist options
  • Save mmcc/4598751 to your computer and use it in GitHub Desktop.
Save mmcc/4598751 to your computer and use it in GitHub Desktop.
Really simple Ruby script to make a basic Live request to Zencoder with a few HLS outputs.
require 'rubygems'
require 'zencoder'
# Change these settings
s3_bucket = ''
Zencoder.api_key = ''
# Quick test to make sure the variables above are set...
if s3_bucket == '' || Zencoder.api_key == ''
puts "It appears you haven't set your S3 bucket or Zencoder API key..."
exit
end
outputs = %Q{
{
"live_stream": true,
"outputs": [
{
"label": "hls_300",
"size": "480x270",
"video_bitrate": 300,
"url": "s3://#{s3_bucket}/awesomeness_300.m3u8",
"type": "segmented",
"live_stream": true,
"headers": { "x-amz-acl": "public-read" },
"access_control": [
{
"permission": "FULL_CONTROL",
"grantee": "[email protected]"
},
{
"permission": "READ",
"grantee": "http://acs.amazonaws.com/groups/global/AllUsers"
}
]
},
{
"label": "hls_600",
"size": "640x360",
"video_bitrate": 600,
"url": "s3://#{s3_bucket}/awesomeness_600.m3u8",
"type": "segmented",
"live_stream": true,
"headers": { "x-amz-acl": "public-read" },
"access_control": [
{
"permission": "FULL_CONTROL",
"grantee": "[email protected]"
},
{
"permission": "READ",
"grantee": "http://acs.amazonaws.com/groups/global/AllUsers"
}
]
},
{
"label": "hls_1200",
"size": "1280x720",
"video_bitrate": 1200,
"url": "s3://#{s3_bucket}/awesomeness_1200.m3u8",
"type": "segmented",
"live_stream": true,
"headers": { "x-amz-acl": "public-read" },
"access_control": [
{
"permission": "FULL_CONTROL",
"grantee": "[email protected]"
},
{
"permission": "READ",
"grantee": "http://acs.amazonaws.com/groups/global/AllUsers"
}
]
},
{
"url": "s3://#{s3_bucket}/master.m3u8",
"type": "playlist",
"streams": [
{
"bandwidth": 300,
"path": "awesomeness_300.m3u8"
},
{
"bandwidth": 600,
"path": "awesomeness_600.m3u8"
},
{
"bandwidth": 1200,
"path": "awesomeness_1200.m3u8"
}
],
"headers": { "x-amz-acl": "public-read" },
"access_control": [
{
"permission": "FULL_CONTROL",
"grantee": "[email protected]"
},
{
"permission": "READ",
"grantee": "http://acs.amazonaws.com/groups/global/AllUsers"
}
]
}
]
}
}
response = Zencoder::Job.create(outputs)
response_code = response.code.to_i
puts "Response Code: #{response_code}"
if response_code.between?(200, 299)
puts "Stream URL: #{response.body['stream_url']}"
puts "Stream Name: #{response.body['stream_name']}"
else
puts "OH NOS! Everything Broke!"
puts "Response Body: #{response.body}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment