FFmpeg

From csml-wiki.northwestern.edu
Revision as of 14:42, 23 February 2015 by Homa (talk | contribs) (added section on choosing suitable aspect ratios)
Jump to navigation Jump to search

Overview

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 that mobile devices with 16:9 screens can still play 4:3 aspect ratio videos, but the whole screen won't be utilized

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 -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 00001
  • 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)

Links