From csml-wiki.northwestern.edu
Revision as of 07:07, 26 October 2021 by Administrator (talk | contribs) (→‎Video Encoder Settings)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


FFmpeg is a powerful tool for handling multimedia files and compiling videos from the command line. It is extremely versatile and allows the user control over many aspects of the encoding process.

Mobile Device Compatiblity

Aspect Ratio

The standard aspect ratios for NTSC and PAL videos are 4:3 (standard screen) and 16:9 (widescreen). Most mobile devices nowadays use screens with a 16:9 aspect ratio, so simulation images/videos should be rendered with either of those aspect ratios so that they will appear undistorted on the mobile device screen.

Note: mobile devices with 16:9 screens can still play 4:3 aspect ratio videos, but only a fraction of the screen will be utilized

Typical standard (4:3) resolutions: 320x240, 640x480, 800x600, 1024x768

Typical widescreen (16:9) resolutions: 640x360, 800x450, 960x540, 1024x576, 1280x720, 1920x1080

Video Encoder Settings

Media is digested increasingly through mobile phones and tablet devices. Therefore, it is important to be aware of possible compatibility issues when encoding videos for these devices. Here is a command that compiles a series of .png images into a .mp4 video that is compatible with Android and Apple devices (see links at the bottom for more detailed information).

ffmpeg -r 20 -i mov%5d.png -vcodec libx264 -profile:v baseline -level 3.1 -pix_fmt yuv420p -crf 20 -g 250 -r 20 output.mp4

Some notes on the above command:

  • compiles .png files named movXXXXX.png, where XXXXX are sequentially numbered strings of 5 digits starting from 00000
  • the -profile:v command, and the accompanying -level command, ensure compatibility with iPhone/iPad. Different profiles and levels, as detailed here, can be used which result in varying levels of compatibility and video compression quality.
  • -pix_fmt yuv420p must be used to ensure that FFmpeg uses a correct color formatting for these devices (this command should be researched further, esp. for how it relates to video quality)
  • -crf (constant rate factor) specifies the compression quality desired (i.e., how lossy your video will be). The command takes a single number between 0 and 51 as an argument, with 0 corresponding to no loss and 51 to the greatest amount of loss. The value 23 is the default, and the range 18-28 contains typical values. A value of 18 is not lossless but should be visually equivalent (or nearly equivalent) to a lossless video. Smaller numbers will result in better quality videos at the expense of larger file sizes.
  • -r controls the framerate of the video (frames/second); the first instance of -r refers to the rate of the input, whereas the second instance sets the framerate of the output.