Skip to main content

Ruby Scripts

Feel free to modify the following script for your environment.  To process the video, this script below assumes your job is on aws in an S3 bucket for input and output. 

require 'net/http'
require 'uri'
require 'json'

url = URI.parse("https://streamengine.igolgi.com/api/v0/job")

headers = {
  'Content-Type' => 'application/json'
}

# Authentication credentials (username and password)
auth = ['INSERT_YOUR_API_KEY', 'a']

# Data to be sent in the POST request
data = {
  videoProfiles: [
    {
      output: 's3://igolgi-se-out/rb-testcwaudio3e.mp4',
      width: 1920,
      height: 1080,
      video_bitrate_mode: 'cbr',
      video_bitrate: 2400,
      video_format: 'progressive',
      video_framerate: '1x',
      audio_profiles: '1'
    }
  ],
  audioProfiles: [
    {
      audio_bitrate: 256,
      audio_channels: 2,
      audio_codec: 'aac',
      source_stream: 1
    }
  ],
  master_variant_mode: false,
  output_container: "mp4",
  video_codec: "h.264",
  input: "s3://igolgi-se-in/GOPR8297-2.7K-30-fps.MP4",
  auto_detelecine_flag: false,
  cloud_credentials: {
    input: {
      cloud_provider: "aws",
      access_key: "INSERT_YOUR_AWS_ACCESS_KEY",
      secret_key: "INSERT_YOUR_AWS_SECRET_KEY",
      region: "us-east-2"
    },
    output: {
      cloud_provider: "aws",
      access_key: "INSERT_YOUR_AWS_ACCESS_KEY",
      secret_key: "INSERT_YOUR_AWS_SECRET_KEY",
      region: "us-east-2"
    }
  }
}

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # Not recommended for production

request = Net::HTTP::Post.new(url.path, headers)
request.basic_auth(auth[0], auth[1])
request.body = data.to_json

response = http.request(request)

# Print the response content
puts response.body

Save the file as se-api-aws.rb or similar.

Run: 
ruby se-api-aws.rb

You may notice an error like this:
...error ... message: "The video bitrate for this profile and codec should set at a minimum of 2300."...

The error above means the video_bitrate variable in the code should be higher than 2300, it was already changed in the code above, but used as an example of the messages you might see.

When it runs correctly you might see something similar to this:
{"_auto_generated_id_":13453,..."updated_at":"2024-07-16T18:49:57.000Z"}

The Id number can also be found on the Job History page. 

image.png

If you want to see the status of the job from ruby you can use this code:

require 'net/http'
require 'uri'
require 'json'

# Check if an argument was provided
if ARGV.length > 0
  external_var = ARGV[0]
else
  puts "Please provide a job ID as an argument."
  exit
end

# Define the URL and API key
url = URI.parse("https://streamengine.igolgi.com/api/v0/job/#{external_var}")
api_key = "1a944b985b09c14b5001ba5cc1a1f585"

# Set up the HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url.request_uri)
request.basic_auth(api_key, '')

# Make the GET request
response = http.request(request)

# Check for a successful response
if response.code == '200'
  puts "Job Status:"
  puts "------------------------"
  puts "Job ID: #{data['status']['job_id']}"
  puts "State: #{data['status']['state']}"
  puts "Progress:"
  puts "  Transcode: #{data['status']['tcode_progress']}%"
  puts "  Transfer: #{data['status']['xfer_progress']}%"
  puts "Time:"
  puts "  Transcode: #{data['status']['tcode_time']} seconds"
  puts "  Transfer: #{data['status']['xfer_time']} seconds"
  puts "Speed:"
  puts "  Transcode: #{data['status']['tcode_speed']} x"
  puts "  Transfer: #{data['status']['xfer_speed']} MB/s"
  puts "Job Completed: #{data['status']['job_completed']}"
  
  puts "\nJob Config:"
  puts "------------------------"
  puts JSON.pretty_generate(data['config'])
else
  puts "Failed to retrieve job. Status code: #{response.code}"
  puts "Response: #{response.body}"
end

Save the file above as se_api_status.rb or similar

Run
    ruby se_api_status.rb  13453      where 13453 is the job number

Job Status:
------------------------
Job ID: 4918
State: ready
Progress:
  Transcode: 100%
  Transfer: 0%
Time:
  Transcode: 19.06 seconds
  Transfer: 28.29 seconds
Speed:
  Transcode: 0.0 x
  Transfer: 0.0 MB/s
Job Completed: true

Job Config:
------------------------
{
  "input": "s3://igolgi-se-in/GOPR8297-2.7K-30-fps.MP4",
  "videoProfiles": [
    {
      "output": "s3://igolgi-se-out/py2-testcwaudio3e.mp4",
      "width": 1920,
      "height": 1080,
      "video_bitrate_mode": "cbr",
      "video_bitrate": 2400,
      "video_framerate": "1x",
      "audio_profiles": "1"
    }
  ],
  "audioProfiles": [
    {
      "audio_codec": "aac",
      "audio_channels": 2,
      "audio_bitrate": 256,
      "source_stream": 1
    }
  ],
  "output_container": "mp4",
  "separate_audio": false,
  "segmented_output_hls": false,
  "segmented_output_dash": false,
  "video_codec": "h.264",
  "gop_length": 1,
  "scte35_passthough": false,
  "audio_volume": 100,
  "h264_quality": "good",
  "video_aspect_ratio": "passthrough",
  "picture_transform": "none"
}