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

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 and WebM

(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 for each respective file type (.mp4 and .webm). 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 (one for H.264 and one for WebM). The variable substitution is ruby-style.

  • vcodec = "-vcodec libx264 -pix_fmt yuv420p -vf 'scale=trunc((a*oh)/2)*2:720' -g 30 -b:v 2000k -vprofile high -bf 0"
    acodec = "-strict experimental -acodec aac -ab 160k -ac 2"
    ffmpeg -i #{src_file} #{acodec} #{vcodec} -f mp4 #{dest_file_mp4}
    vcodec = " -pix_fmt yuv420p -vcodec libvpx -vf 'scale=trunc((a*oh)/2)*2:720' -g 30 -b:v 2000k -vpre 720p -quality realtime -cpu-used 0 -qmin 10 -qmax 42"
    acodec = "-acodec libvorbis -aq 60 -ac 2"
    ffmpeg -i #{src_file} #{acodec} #{vcodec} -f webm #{dest_file_webm}

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

  • ffmpeg -r 24 -i #{src_file} #{acodec} #{vcodec} -f webm #{dest_file_webm}
    

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 -r #{frame_count/seconds} -i #{src_file} -f image2 #{thumb_files}-%02d.jpeg
montage #{thumb_files}-* -geometry #{frame_width}x+0+0 -tile x1 -format jpeg -quality #{quality} #{filmstrip_path}

Automatic transcoding

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

Follow

16 Comments

  • 0
    Avatar
    Mark Visser

    For anyone else doing your own encoding: you also need to set sg_uploaded_movie_frame_rate, otherwise the overlay player will assume 24fps and the frame numbers will be incorrect for non-24fps media.

  • 1
    Avatar
    Stijn Calis

    Did anyone else experienced weird colorspace-shifts in the converted video?  Like certain frames that look brighter then others?

  • 0
    Avatar
    Dave Lajoie

    Hello Guys, how does filmstrip is being created? rvio? ffmpeg?

  • 0
    Avatar
    Matt Welker

    Hi Dave,

    Yes, it is ffmpeg. We've added the code for making the filmstrip thumbnails. Thanks for pointing that out.

  • 0
    Avatar
    Dave Lajoie

    Hello Mark, I am having the same problem as you. it seems like you need to pass -r 24 to ffmpeg. I am testing it now. kyp

  • 0
    Avatar
    Dave Lajoie

    -r does the trick!

  • 0
    Avatar
    Tony Aiello

    Hey folks, we have found that the ffmpeg encoder call provided here for generating webm's does not transcode the whole movie properly. There are often a couple of frames missing, typically at the end of the clip. This isn't a playback issue with Firefox; we verified that the frames are not in the webm by using ffprobe.  We do see all the frames are present in the mp4 version, so that call seems ok.  Anyone else experience this?  Suggestions for altered webm params?  We're about to test with adding -r 24 but not sure that will be enough.

  • 0
    Avatar
    Dave Lajoie

    we had the same problem, and it was due to the argument position, where it needs to be right after the ffmpeg exec

     

    ffmpeg -r 24.0 .... > ok

    ffmpeg .... -r 24.0 ... > not ok, you might get 23.97 DF

     

  • 0
    Avatar
    Rob Aitchison

    So, it's a little confusing around thumbnail generation - can I set the JPEG quality or do I need to send a support request?

    Thanks!

  • 0
    Avatar
    Mark Visser

    Hi Rob, I had the same request (control over thumbnail jpeg quality), so there should be an open ticket for it. 

    cheers,

    -Mark

  • 0
    Avatar
    Rob Aitchison

    Thanks Mark, I guess it's not quite ready then? :)

  • 0
    Avatar
    Jos'h Fuller

    Is it possible to outsource the transcode of /most/ of our movies while still allowing Shotgun to transcode things that people upload from the web GUI? We have a self-hosted install.

    We don't want to turn it off completely, we just want to lighten the load...

    Thanks!

  • 0
    Avatar
    Kym Watts

    Yes.

    So the filed "sg_uploaded_movie", is what triggers shotgun to internally transcode the version.

    So if you want to transcode the files your self, then you need to update the following fields on a version:

    Using sg.upload("Version",version_id,path_to_file, varible_listed_below)

    For videos:

    the h264/ mp4 is uploaded to: sg_uploaded_movie_mp4

    the webm is uploaded to: sg_uploaded_movie_webm

    for hires images:

    sg_uploaded_movie_image

     

    then the thumbs and filmstrip are done with:

    sg.upload_thumbnail() and sg.upload_filmstrip_thumbnail()

     

     

  • 0
    Avatar
    Jos'h Fuller

    Hi!

    So, you're talking about doing something like this:

    mp4 = open("monster.mp4", "rb").read()

    wbm = open("monster.webm", "rb").read()

    sg.update("Version", 9999, {"sg_uploaded_movie_mp4": mp4, "sg_uploaded_movie_webm": wbm}).

    Thanks!

    P.S. Have you moved to wet-phase 3D printing yet?

  • 0
    Avatar
    Andy Jones

    Might be worth clarifying that the "montage" command is coming from ImageMagick in the thumbnail section.  We figured it out, but initially we were reading it as one big command with word wrap, thinking maybe "montage" was an ffmpeg argument.

  • 0
    Avatar
    Alexandra Lefève-Gourmelon

    Hi Stijn,

    We have the same colorshift problem. Dud you manage to get rid of it?

    Cheers,

    Alex

Please sign in to leave a comment.