FFmpeg

From SDA Knowledge Base

Revision as of 09:13, 12 October 2014 by HDL (Talk | contribs)

Jump to: navigation, search

Main Websites

ffmpeg.org


Encoding

Note: When encoding for SDA submissions just use Yua. It's much simpler and decreases the likelihood of mistakes. Use FFmpeg only if you know exactly what you're doing, are not encoding for SDA, or simply want more options than Yua affords.


FFmpeg is a command line application, used with Terminal (Unix) or Command Prompt (Windows). With the exception of 3rd-party options it doesn't have a GUI, so it may be tricky to learn at first. The advantages are that it's cross-platform so it can be used on any modern operating system, highly up-to-date as development is active, and it offers more flexibility than any other encoding software. Here are examples of usage on Unix systems:


D4 Source

./ffmpeg -y -i InputVideo.avi -c:v libx264 -preset veryslow -b:v 4000k -pass 1 -pix_fmt yuv420p -vf separatefields,setdar=dar=4/3 -af volume=3 -strict -2 -c:a aac -cutoff 48000 -b:a 320k OutputVideo.mp4 && ./ffmpeg -y -i InputVideo.avi -c:v libx264 -preset veryslow -b:v 4000k -pass 2 -pix_fmt yuv420p -vf separatefields,setdar=dar=4/3 -af volume=3 -strict -2 -c:a aac -cutoff 48000 -b:a 320k OutputVideo.mp4


D1 Source

./ffmpeg -y -i InputVideo.avi -c:v libx264 -preset veryslow -b:v 5000k -pass 1 -pix_fmt yuv420p -vf yadif=3:1,mcdeint,scale=640:480:interl=0 -strict -2 -c:a aac -cutoff 48000 -b:a 320k OutputVideo.mp4 && ./ffmpeg -y -i InputVideo.avi -c:v libx264 -preset veryslow -b:v 5000k -pass 2 -pix_fmt yuv420p -vf yadif=3:1,mcdeint,scale=640:480:interl=0 -strict -2 -c:a aac -cutoff 48000 -b:a 320k OutputVideo.mp4


Commands

Let's break down what these commands mean so it's easier to understand how to use them.


  • ./ ("Dot slash." Required on Unix systems to run applications via Terminal.)
  • -y (Yes; used for automatically overwriting on the 2nd pass.)
  • -i (Input, use this before specifying the source video.)
  • -c:v (codec for video; used to choose codecs like “libx264”)
  • -preset (Quality setting for x264, veryslow is best quality.)
  • -b:v (bit rate for video; used to determine visual quality in Kbps.)
  • -pass (used for 2-pass encoding.)
  • -pix_fmt (pixel format; yuv420p is standard.)
  • -vf (video filter; used for various effects like scaling, field separation, deinterlacing, etc.)
  • -af (audio filter; used for various audio effects like volume.)
  • -strict -2 (allows usage of experimental codecs like aac.)
  • -c:a (codec for audio; used to choose codecs like “libvo_aacenc” which is the non-experimental AAC.)
  • -cutoff (used to set the maximum audio frequency.)
  • -b:a (bit rate for audio; used to determine aural quality in Kbps.)
  • && (Allows you to combine more than one command on Unix systems into a single line; helpful for 2-pass encoding.)


Besides these commands there are also various video and audio filter options you can use.


Filters

  • separatefields (This splits the fields for interlaced video at half height and doubles the frame rate; use for D4 only.)
  • setdar (Use this to set the aspect ratio after separating fields or deinterlacing. Corrects the resolution without specifying values.)
  • yadif (Widely used deinterlacing filter; used for D1 video instead of field separation.)
  • mcdeint (Motion compensating filter used in conjunction with yadif; use to prevent pixel shift [bobbing] on D1 sources.)
  • scale (Use this if you want a specific resolution. Add "interl=0" at the end to prevent scaling with interlacing.)
  • volume (Increase/decrease the audio levels.)
  • fps (Do not use for full frame rate videos. Useful for MQ and LQ SDA submissions.)


Note: Some commands must be entered in the correct order. For example, scaling must be done after deinterlacing, not before.


For more information on commands, filters, and usage you can check the FFmpeg Documentation.


Trimming

It's rare that one wants to encode all recorded footage from start to finish. Usually you want to choose a start frame and end frame. The easiest way to do this with ffmpeg is to divide the frame number by the frame rate of the video. Use a media player that can display the frame count. If you want to start on frame 117 and your source video is 30 FPS, then just divide 117 ÷ 30 = 3.9. Example:


  • ./ffmpeg -i FullVideo.avi -ss 3.9 -to 17.2 -vcodec copy -acodec copy Trimmed.avi


This will start the video on frame 117 and end on frame 516. Quick breakdown of the important commands:


  • -ss (Starts video at that time in seconds.)
  • -to (Trims to that time from the start of the video.)
  • -t (Can be used in lieu of -to for trimming the video to the specified duration.)


Screen Recording

FFmpeg can also capture your desktop. Refer to this page to see how this is done. This feature is currently unavailable for OS X.


Streaming

Harder to use than common solutions, but FFmpeg is capable of streaming to services like Twitch and Hitbox. Read this guide for more details.

Personal tools