The Shotstack SDK for Ruby will get your video editing application up and running in days, not months.
The Ruby video editing SDK is available as a Ruby gem or directly from the Shotstack Github repo. The SDK works directly with Shotstack, the fully managed cloud based video editor, meaning you don't need to spend time or money on the infrastructure and can focus on creativity.
The Ruby gem simplifies the process of working with the Shotstack API, unlocking all the video editing features you need, including cut and trim, stitching clips, transitions, filters and effects.
The Shotstack Ruby video editing library is available as a gem and can be installed directly from Ruby Gems or downloaded from GitHub.
gem install shotstack
Add the library to your script.
require "shotstack"
Use your own API key and point the base path to stage or v1. In production, make sure you pass the key via environment variables to keep it secure.
Shotstack.configure do |config|
config.api_key['x-api-key'] = "H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD"
config.host = "api.shotstack.io"
config.base_path = "stage"
end
One of the many features the video editing API can do is trim a video. For this example we trim the start and end of a video clip. Setting the video asset trim to 3 will remove the first 3 seconds from the start. Setting the length to 8 will play the next 8 seconds. A start value of 0 makes the video play straight away, at second 0.
video_asset = Shotstack::VideoAsset.new(
src: "https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4",
trim: 3
)
video_clip = Shotstack::Clip.new(
asset: video_asset,
start: 0,
length: 8
)
Tracks are layers composed of titles, images, audio, html or video segments added on top of each other. This edit has a single clip added to a track.
track = Shotstack::Track.new(clips: [video_clip])
The timeline represents all the content (video, audio, images) of the edit over time, made up of one or more tracks.
timeline = Shotstack::Timeline.new(
background: "#000000",
tracks: [track]
)
Set the output format and resolution. For this edit, the output format is set to mp4 and the resolution to SD.
output = Shotstack::Output.new(
format: "mp4",
resolution: "sd"
)
Add the timeline and the output format to the final edit.
edit = Shotstack::Edit.new(
timeline: timeline,
output: output
)
The SDK will generate the JSON payload based on your config and will post it to the API, returning a response object, containing the ID.
api_client = Shotstack::EditApi.new
response = api_client.post_render(edit).response
Finally, query the render status and output the video URL when the render is done.
api_client = Shotstack::EditApi.new
response = api_client.get_render(id, { data: false, merged: true }).response
if response.status == "done"
puts ">> Asset URL: #{response.url}"
end
The Ruby code above prepares a JSON payload, describing the video editing parameters to trim a video clip, POST's it to the Shotstack API and generate this video.
This application is the perfect example of a well executed and documented API. In less than 10 mins, set up, web hook done, and first render!
There are a couple of other options out there that attempt to provide the same or similar solution, but none of them come close in terms of quality, ease of use, and speed.
Shotstack was EXACTLY what I was looking for, and incredibly easy to get started with. You guys are killing it.