moviemasher.js | angular-moviemasher | moviemasher.rb

Ruby library for mashing up video, images and audio utilizing FFmpeg and Ecasound

moviemasher.rb

Use moviemasher.rb to encode mashups of video, audio, and images together with titles and other visual effects.

Overview

The project aims to simplify common audio/video editing operations by turning your job into a series of shell commands, and then overseeing their execution. As part of job processing, media inputs can be downloaded from remote hosts and rendered outputs can be uploaded as well. Using the same request mechanisms, external systems can be alerted by callbacks triggered when a job is started, during its processing and/or when it's completed.

In addition to the raw media assets (video, audio and images), jobs can contain mash inputs that describe more complex compositing, titling and other effects. The related moviemasher.js project can be used to generate and display JSON formatted mash descriptions within a web browser, and angular-moviemasher can be used to package these into job descriptions.

Jobs are provided to the system for processing in different ways, depending on how it's been configured and deployed. At the lowest level, the MovieMasher.process method is sent a job as a hash, a JSON/YAML formatted string or a local path to one. The MovieMasher.process_queues method calls it with any jobs it finds while scanning a preconfigured watch folder or queue. This scanning can be done for a certain number of seconds, until no jobs are found, just once or forever. There are rake tasks for each of these methods, to simplify calling from shell scripts, cron jobs and other tasks.

Job Syntax

Each transcoding job specifies multiple media inputs to be encoded together into one or more outputs, as well as metadata like destination which defines where to put the final rendered file(s).

Scale down local image
{
  "inputs": [{ "source": "/path/to/local.png", "type": "image" }],
  "outputs": [{ "type": "image", "name": "smaller.png", "dimensions": "1536x864" }],
  "destination": { "type": "file", "path": "/path/to", "method": "move" }
}

AWS Integration

The system optionally supports Amazon Web Services for media storage and job queueing, through the ruby aws-sdk gem. The following mechanisms are available through configuration or job options:

Additionally, the Movie Masher AMI is launchable with OneClick in Marketplace as a deployment of all related projects and supporting applications. It includes an upstart task that executes rake moviemasher:init to merge any User Data supplied in JSON format into the configuration plus a cron job that continually executes rake moviemasher:process_queues, so it's possible to run in a headless mode polling an SQS queue for jobs. Without User Data, the instance will start up Apache and serve the angular-moviemasher project for demonstration - the instance id acts as a shared password.

Docker Usage

Docker's moviemasher/moviemasher.rb image is based off the official ruby image, adding builds of FFmpeg, Ecasound and supporting audio/visual libraries. It can be used to process jobs supplied directly on the command line, or to grab them from a directory/queue - either approach supports running in interractive or daemon mode. The Dockerfile contains a VOLUME instruction for each directory it works with, including queue_directory so that job files residing on the host can be easily processed.

JOB can be a JSON or YAML formatted string, or a path to one in the container.

Note the t switch - it's required for Ecasound to function properly. You'll need to subsequently execute docker stop moviemasher and docker rm moviemasher to stop processing and remove the container created.

URL points to an existing SQS Queue that provides read/write access to the owner of the access key with ID and SECRET. Messages can be in JSON or YAML format.

The last example demonstrates overriding the configuration with command line arguments - all commands support this. The MOVIEMASHER_CONFIG environmental variable can also be set to a configuration file residing on the container in JSON/YAML format, though arguments take precedence.

When processing jobs in a directory or queue, the process_seconds configuration option ultimately controls how long polling continues and therefore how long the container runs. The following values are supported:

The Dockerfile specifies an ENTRYPOINT that provides several convenience commands, but calls exec with any it doesn't recognize so that containers behave as expected. The following commands are supported:

Requirements

Tested in Ruby 1.9.3 and 2.1.5 (the dockerfile/ruby and ruby docker images) and on multiple UNIX flavors including OSX. Suggested audio/video libraries are only needed if you're decoding or encoding in their formats. Likewise, the aws-sdk gem is only needed when utilizing Amazon's services.

How to Install

Transcoding audio and video is extremely processor intensive, so while installation might be possible on most machines it isn't reccommended for all environments. In particular, running alongside a web server is only practical for demonstration purposes. Typically in production a pool of machines is deployed with each instance running a single process solely engaged in transcoding.

  1. Review Dockerfile for commands that work on the ruby image

  2. Install av libraries for supported formats and codecs

  3. Install sox, ecasound and ffmpeg applications (in that order)

  4. Install ruby and bundler gem

  5. To install required gems cd to project directory and execute:

bundle install

  1. Edit config/config.yml configuration file to match paths on system and configure logging/debugging options

  2. To scan watch folder and/or queue for jobs cd to project directory and execute:

rake moviemasher:process_queues

  1. optionally add crontab entry from config/aws/moviemasher.cron, after checking its binary paths

User Feedback

If any problems arise while utilizing this repository, a GitHub Issue Ticket should be filed. Please include the job description that's causing problems and any relevant log entries - issues with callbacks can typically be resolved faster after seeing entries from the receiving web server's log. Please post your issue ticket in the appropriate repository and refrain from cross posting - all projects are monitored with equal zeal.

Contributing

Please join in the shareable economy by gifting your efforts towards improving this project in any way you feel inclined. Pull requests for fixes, features and refactorings are always appreciated, as are documentation updates. Creative help with graphics, video and the web site is also needed. Please contact through MovieMasher.com to discuss your ideas.

Developer Setup

Docker is used extensively to develop this project. Additionally, the spec tests rely on the other two Movie Masher projects which should both be cloned into the same directory that contains this repository:

To run spec tests utilizing options from .rspec file:

All files generated by tests appear in tmp/spec sub directories. Each job has its own log file in tmp/spec/temporary.

To run rubocop with options from config/docker/rubocop/rubocop-rules.yml file:

To rebuild Gemfile.lock from Gemfile: - docker-compose -f config/docker/bundler/docker-compose.yml run --rm bundler

To have rdoc rebuild documentation in doc from source code:

Known issues in this version
Migrating from Version 4.0.7