Skip to content

Instantly share code, notes, and snippets.

@hardeepnarang10
Last active October 31, 2020 05:17
Show Gist options
  • Save hardeepnarang10/d4009c3a2c94435abaae07aad82bafe2 to your computer and use it in GitHub Desktop.
Save hardeepnarang10/d4009c3a2c94435abaae07aad82bafe2 to your computer and use it in GitHub Desktop.
Cluster-optimized HLS transcoder command (ffmpeg).

Transcode.sh

ffmpeg -i <input file> -hide_banner -y -c:a aac -ar 48000 -c:v h264 -profile:v baseline -crf 20 -sc_threshold 0 -pix_fmt yuv420p -hls_time 10 -strict -2 -vsync 2 -vf scale=w=XXX:h=XXX -b:v 800k -maxrate XXXk -bufsize 1200k -b:a 96k -hls_time 10 -f hls -hls_list_size 0 <output file>

Replace XXXs for scale settings to match your mediaplayer. Preferable to use an autoscaler on upper-medium settings first and let it process heavier resolutions in background. Maxrate of 1000k-1200k should work fine in most cases - keeping note that bufsize is set to 1200k.

Challenges with Transcoders

Can get stuck every now and then. Use health monitor to pass the following checks and have Kubernetes restart container:

  • Transcoder hasn’t received any message from the messaging bus topic for a while and there are still outstanding messages in the topic.
  • Fail the health check if the FFmpeg job is stuck i.e. is not producing any more HLS segments but is still running.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment