Documentation

Radiant Media Player

Working with FFmpeg

Installing FFmpeg

This article describes how to produce MP4 and WebM video files compatible with Radiant Media Player and HTML5 video in general.

General instruction for installing FFmpeg can be found here. Make sure you have the latest release version available for better results.

Guidelines for compiling FFmpeg can be found here.

Enabling some encoding/decoding options with FFmpeg can trigger licensing requirements depending on your use-case. Radiant Media Player does not provide licensing for encoding/decoding media content. This guide is information only.

On-demand video transcoding to MP4 with AVC (H.264) video and AAC-LC audio - keyframes aligned renditions

In this section we will review how to produce MP4 files that will work with HTML5 video on devices where H.264 video and AAC-LC audio are supported. Specifically we will produce keyframes aligned video files at different bitrates and resolutions. This is a requirement for proper adaptive bitrate streaming in DASH and HLS.

We use a 16:9 1920x1080 24fps (a.k.a. True HD 1080p24) MOV input video file named input.mov. If you need a sample to play around, can get one from blender.org site.

ffmpeg -i input.mov -s 640x360 -c:v libx264 -b:v 560k -r 24 -x264opts keyint=48:min-keyint=48:no-scenecut -profile:v main -preset fast -movflags +faststart -c:a libfdk_aac -b:a 128k -ac 2 out-low.mp4

Explanation:

  • -i input.mov: this is our input video file
  • -s 640x360: we tell FFmpeg to resize our input file to 640x360 while transcoding
  • -c:v libx264: we tell FFmpeg to use x264 as the video encoding library
  • -b:v 650k: the target video bitrate should be 650 kbps
  • -r 24: we want a constant framerate at 24 fps (which is the same as our source video file in this case)
  • -x264opts keyint=48:min-keyint=48:no-scenecut: we should have one keyframe every 48 frames (every 2 seconds). The keyframe injection should be constant
  • -profile:v main: we want H.264 main profile which is supported by most devices on the market while offering good transcoding quality and options
  • -preset fast: we use a fast preset for x264 transcoding
  • -movflags +faststart: the file should be web ready (moov box before mdat box)
  • -c:a libfdk_aac: we use libfdk_aac as our audio encoding library
  • -b:a 128k: the target audio bitrate should be 128 kbps
  • -ac 2: we want a stereo (2 audio channels) output
  • out-low.mp4: our output file should be a MP4 file named out-low.mp4

Once we have created our first rendition we can create others at different resolutions and bitrates.

ffmpeg -i input.mov -s 960x540 -c:v libx264 -b:v 1260k -r 24 -x264opts keyint=48:min-keyint=48:no-scenecut -profile:v main -preset fast -movflags +faststart -c:a libfdk_aac -b:a 128k -ac 2 out-med.mp4
ffmpeg -i input.mov -s 1280x720 -c:v libx264 -b:v 2240k -r 24 -x264opts keyint=48:min-keyint=48:no-scenecut -profile:v main -preset fast -movflags +faststart -c:a libfdk_aac -b:a 128k -ac 2 out-high.mp4
ffmpeg -i input.mov -s 1920x1080 -c:v libx264 -b:v 5050k -r 24 -x264opts keyint=48:min-keyint=48:no-scenecut -profile:v main -preset fast -movflags +faststart -c:a libfdk_aac -b:a 128k -ac 2 out-max.mp4

Here is a suggestive encoding table for H.264/AAC-LC (16:9 aspect ratio at 24fps up to 4K resolution) for adaptive bitrate streaming:

  • 480x270 @ 315 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 640x360 @ 560 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 960x540 @ 1260 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 1280x720 @ 2240 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 1920x1080 @ 5050 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 2560x1440 @ 9000 kbps video with 128 kbps audio (bits/pixel: 0.1)
  • 3840x2160 @ 20000 kbps video with 128 kbps audio (bits/pixel: 0.1)

Generally a 0.1 bits/pixel ratio is good enough (but that may depend on content type) for H.264 encoding.

Feel free to play around with the numerous audio and video encoding settings that provide FFmpeg. An AAC encoding guide is available here. A H.264 encoding guide is available here.

On-demand video transcoding to MP4 with HEVC (H.265) video and HE-AACv2 audio - keyframes aligned renditions

Now that you know about everything on H.264/AAC-LC encoding we can go ahead with H.265/HE-AACv2 encoding. H.265 claims to reduce file size up to 50% versus H.264 without loss of quality (in reality H.265 most notable gains are obtained at lower and higher bitrate). HE-AACv2 is a newer version of AAC which works well for low bitrate audio encoding.

Here is a FFmpeg command line that will produce H.265/HE-AACv2 content:

ffmpeg -i input.mov -s 640x360 -c:v libx265 -b:v 390k -r 24 -x265-params "keyint=48:min-keyint=48:no-open-gop=1:no-scenecut=1" -preset fast -movflags +faststart -c:a libfdk_aac -profile:a aac_he_v2 -b:a 96k -ac 2 out-low.mp4

Here is a suggestive encoding table for H.265/HE-AACv2 (16:9 aspect ratio at 24fps up to 4K resolution) for adaptive bitrate streaming:

  • 480x270 @ 220 kbps video with 96 kbps audio (bits/pixel: 0.071)
  • 640x360 @ 390 kbps video with 96 kbps audio (bits/pixel: 0.071)
  • 960x540 @ 880 kbps video with 96 kbps audio (bits/pixel: 0.071)
  • 1280x720 @ 1550 kbps video with 96 kbps audio (bits/pixel: 0.070)
  • 1920x1080 @ 3500 kbps video with 96 kbps audio (bits/pixel: 0.070)
  • 2560x1440 @ 6200 kbps video with 96 kbps audio (bits/pixel: 0.070)
  • 3840x2160 @ 14000 kbps video with 96 kbps audio (bits/pixel: 0.070)

Generally a 0.07 bits/pixel ratio is an acceptable conservative ratio for H.265 encoding. You can go down to a 0.06 bits/pixel ratio for smaller bitrate.

An example of H.265/AAC file in a MP4 container encoded with the above command line can be downloaded here.

A H.265 encoding guide is available here.

On-demand video transcoding to MP4 with AV1 video and AAC audio

AOMedia Video 1 (AV1) is an open, royalty-free video coding format designed for video transmissions over the Internet. It was developed as a successor to VP9 by the Alliance for Open Media (AOMedia)

AV1 promises to offer 10-20% better quality than HEVC at similar bitrate and 20-30% better quality than VP9 at similar bitrate.

Here is a FFmpeg command line that will produce AV1/AAC content:

ffmpeg -i input.mov -c:v libaom-av1 -b:v 335k -s 640x360 -strict experimental -movflags +faststart -c:a aac -b:a 128k -ac 2 -cpu-used 8 -row-mt 1 -tiles 2x2 -r 24 av1-360p.mp4

A guide to AV1 encoding with FFmpeg is available here.

Here is a suggestive encoding table for AV1/AAC (16:9 aspect ratio at 24fps up to 4K resolution) for adaptive bitrate streaming:

  • 480x270 @ 187 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 640x360 @ 335 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 960x540 @ 750 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 1280x720 @ 1330 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 1920x1080 @ 3000 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 2560x1440 @ 5350 kbps video with 96 kbps audio (bits/pixel: 0.06)
  • 3840x2160 @ 12000 kbps video with 96 kbps audio (bits/pixel: 0.06)

Generally a 0.6 bits/pixel ratio is an acceptable semi-conservative ratio for AV1 encoding.

An example of AV1/AAC file in a MP4 container encoded with the above command line can be downloaded here.

On-demand video transcoding to WebM with VP9 video and opus audio

VP9 is an open and royalty-free video coding format developed by Google. VP9 is the successor to VP8 and competes mainly with MPEG's High Efficiency Video Coding (HEVC/H.265).

Here is a FFmpeg command line that will produce VP9/Opus content:

ffmpeg -i input.mov -s 640x360 -c:v libvpx-vp9 -minrate 445k -maxrate 445k -b:v 445k -r 24 -c:a libopus -b:a 96k -ac 2 -cpu-used 2 -row-mt 1 out-low.webm

A guide to VP9 encoding with FFmpeg is available here. In the above example we used a constant bitrate (CBR) encoding approach. Achieving CBR or CVBR with VP9 encoding is quite straight forward - for H.264 it can be done but you are going to need to do some research about the bufsize setting (help for H.264 CBR encoding can be found here).

Here is a suggestive encoding table for VP9/Opus (16:9 aspect ratio at 24fps up to 4K resolution) for adaptive bitrate streaming:

  • 480x270 @ 250 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 640x360 @ 445 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 960x540 @ 996 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 1280x720 @ 1770 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 1920x1080 @ 4000 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 2560x1440 @ 7100 kbps video with 96 kbps audio (bits/pixel: 0.08)
  • 3840x2160 @ 16000 kbps video with 96 kbps audio (bits/pixel: 0.08)

Generally a 0.8 bits/pixel ratio is an acceptable semi-conservative ratio for VP9 encoding.

An example of VP9/Opus file in a WebM container encoded with the above command line can be downloaded here.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.

©2015-2021 Radiant Media Player. All rights reserved.