Do it yourself (DIY) transcoding

You have the option to do your own transcoding, which might be desirable if you already have render processes in place that produce images or movies in a web-streamable format.

DIY transcoding tips

Note: The information on this page is provided as a reference only. Different versions of FFmpeg and/or codecs will produce different results.
Shotgun transcoding uses a custom build of FFmpeg that does not correspond to public releases.

Here are some details you'll want to keep in mind should you decide to go this route:

Automatic transcoding must be disabled

Make sure we disable automatic transcoding for uploaded images and movies if you are doing your own transcoding, otherwise uploaded media files will continue to be automatically transcoded, and may overwrite your own transcoded movies on the server. Just send us a support ticket and we'll deactivate transcoding for your site.

Shotgun’s transcoder generates MP4

(We can make it so these fields show up in the UI for you while you're setting up your transcoding scripts; just send us a support ticket to request this.)

Name movies with extensions for their file type

Best practice is to name the movies you create with the proper extensions (.mp4). Some browsers may not properly detect the movie format without these specific extensions, which may lead to playback errors.

The frames per second (FPS) defaults to 24

The field sg_uploaded_movie_frame_rate defaults to 24, so for media that is not 24 FPS you will need to set the correct sg_uploaded_movie_frame_rate.

DIY transcoding code

This is the FFmpeg code we run to generate the streamable movie files. The variable substitution is ruby-style.

  • vcodec = "-vcodec libx264 -pix_fmt yuv420p -vf 'scale=trunc((a*oh)/2)*2:%{height}' -g 30 -vprofile high -bf 0 -crf 23"
    acodec = "-strict experimental -acodec aac -ab 160k -ac 2"
    ffmpeg -i #{src_file} #{acodec} #{vcodec} -f mp4 #{dest_file_mp4}

The height variable above is the minimum between 1080 and the source resolution (so we don’t upscale).

If you need to force the frame rate, you can add the -r flag to the transcoding calls. So to force 24 FPS, you'd have something like this:

  • ffmpeg -r 24 -i #{src_file} #{acodec} #{vcodec} -f mp4 #{dest_file_mp4}
    

Note that it is important for this flag to remain the first in the list, otherwise we have seen FFmpeg drop some frames in the encoding.

  • For image files, Shotgun's Transcoder generates a single high resolution (maximum 2k) image file (PNG if the original contains transparency, JPG otherwise) that is used by all supported browsers. The high resolution image file is stored in a hidden field in the UI, but you can update them via the API. The field name is sg_uploaded_movie_image. (We can make it so these fields show up in the UI for you while you're setting up your transcoding scripts, just drop us an email at support@shotgunsoftware.com to request this.)

This is the ImageMagick code we run to generate the still image files.

  • convert #{src_file} -resize #{2048}x{2048}\\> #{dest_file}

Shotgun's built-in transcoder creates thumbnails in addition to generating the streamable movie formats. If you choose to do your own transcoding, you'll probably want to build in API calls that replicate this functionality. Check the API docs for upload_thumbnail() and upload_filmstrip_thumbnail() for more information.

If you want to create your own Filmstrip Thumbnails using FFmpeg, here is the code we use to generate the image from a set of individual thumbnail images:

ffmpeg -threads #{self.threads_to_use} -i #{src_file} -vf select=\"not(mod((n-#{offset})\\,#{frame_increment}))\",setpts=\"N/(#{fps_f}*TB)\",scale=#{frame_width}:-1 -sws_flags lanczos -qscale:v 2 -pix_fmt yuvj420p -f image2 #{thumb_files}-%02d.jpeg"

Automatic transcoding

For more information on how Shotgun automatically transcodes movies and images, see the article "Transcoding."

Follow