Automatically encoding rendered frames to a movie

It is often very useful to get a movie file as a result of a render, but it is almost always necessary to use a frame sequence in order to make use of multiple machines for a project. So, how can you automate the process of rendering a frame sequence, then generating a movie out of those rendered frames? This post will take a look.

We will use ffmpeg as the encoding application, which is freely available, open source, and able to read and write a very large number of formats, but you could use any command line controlled encoding application.

There are lots of ways to accomplish this type of pipeline. For this article, we will use the idea that any farm node will also be able to do encoding jobs, and so the system will submit a new “encode” job when the “render” job finishes. To do this, we will make use of Smedge’s Job Finished Event field. This event is run on the Master when it has determined that all pending work from a job has been finished or permanently canceled.

Where do you set this parameter

From the GUI

This parameter is set on the Event Commands tab of the Submit Job window.

I don't see the event commands

  • This tab may be hidden by a system restriction

  • In Administrator Mode all restrictions are lifted

  • You can remove the Restriction in the Configure Master settings

From a Job File

Job files are INI format text files where each job is a section with key/value pairs. The parameter name to add to the file is JobFinishedEvt

Use the syntax Submit -FromFile filename

If both the first and last characters are double quotes, these will be removed when the file is read. You can add an extra set of quotes around the whole line to avoid this issue.

From the CLI

You can submit single jobs by passing parameters directly to the Submit tool as parameters with a starting dash:

Submit Script ... -JobFinishedEvt "your command goes here"

Be careful with quotes and dashes in your command string, if you use this method. Be sure to quote and escape as needed for the operating system and shell you are using.

What to set it to

The value you set as the Job’s handler for the JobFinishedEvt will have any parameters expanded, and then will be executed as a separate process. Determine the command line that works to generate the movies you want. The basic ffmpeg command line syntax is:

ffmpeg -i input output

You may need to add more flags to get the encoding options, and you will need full paths for the input and output files.

The input file is a format string to specify the input image sequence, using the printf style formatting for the frame number. This format uses %04d to represent a 4 digit padded number, for example. This happens to be the same format that Smedge will auto-detect from the renderers it knows about. The Smedge parameter you use is ImageFormat.

The output file is the movie that will be created. You may want to use the $(Name) advanced substitution syntax to get the movie file to be next to the frames it was generated from. For example, if we knew we were generating PNG frames and wanted to make an MP4 movie next to the frame files, the entire command could be this:

C:\ffmpeg\ffmpeg.exe -i $(ImageFormat) $(ImageFormat.Replace:%04d.png|mp4)

If the original format is: X:\RENDERS\MyProject\Scene004\Beauty\Frames.%04d.png
The replaced value will be: X:\RENDERS\MyProject\Scene004\Beauty\Frames.mp4

The next step is to figure out how to submit this command as a new job to Smedge. Here is a simple Smedge Submit command line to submit this as a “generic script” type job:

$(SmedgeDir)Submit Script -Type Generic Script -Command "C:\ffmpeg\ffmpeg.exe -i $(ImageFormat) $(ImageFormat.Replace:%04d.png|mp4)" -Range 1 -Name Encode $(ImageFormat.Leaf.CutExtension)

$(SmedgeDir) expands to the Smedge program folder. In that folder we want the Submit program, and pass the Script option to indicate that we are sending a job by command line.

The entire ffmpeg command string is wrapped in quote marks so that the Submit tool knows that the parameters inside the quotes are copied to the value being read and not interpreted as new parameters to the Submit tool itself.

-Range 1 is set to indicate that this job has 1 work unit. Movies should be encoded as a single task by a single machine in order to correctly encode and compress.

-Name Encode $(ImageFormat.Leaf.CutExtension) is set to give the job a name in the system that makes sense. The name is the word “Encode” followed by the filename (without the path or extension) from the ImageFormat that is being used.

Of course you can add other Smedge options to this command line as needed (like -Priority or -Pool) to control how the encode job will be prioritized or processed.

Set this command string as the value to your Job’s Job Finished Event handler, and you have automated the process of generating a movie from your rendered frames!

How to automate this

Smedge includes submit scripts that integrate with several different animation and compositing applications. These scripts work by using data available inside of the artist tool to generate either a Job file or the command line to submit a new job. You can easily modify these scripts to add the command you need to encode your frames before you even submit the job.

You are not required to use the ImageFormat parameter. You could use the Note field instead, which is a field that allows you to attach any data you want to a job. Use $(Note) to access the value in your command. If you know the expected frame filename format ahead of time, you can also supply it to the Submit tool using the InitImageFormat parameter when you submit the render job.

Finally, another option is to submit both your render and your encode jobs at the same time, but to make the encode job wait for the render job to finish using the WaitForJobID parameter, rather than using the Job Finished Event pipeline we have been discussing.


This is just a taste of some of the things you can do, and I hope it gives you a start on building an advanced automated pipeline that fills your needs. As ever, please feel free to contact Uberware support if you have any questions or need help building the perfect pipeline.

Artist, Engineer, and Dad