FFMPEG

A cross-platform solution to record, convert and stream audio and video. Download from ffmpeg.org

Syntax
      ffmpeg [global_options] {[infile_options] -i infile}... {[outfile_options] outfile}...

Global options:
   -y                Overwrite output files
   -n                Never overwrite output files
   -stats            Print progress report during encoding
   -formats          Show available formats
   -codecs           Show available codecs

infile_options:
   -c codec          Codec name
   -codec codec      Codec name
   -c:a codec        Audio codec
   -c:v codec        Video codec

Video options:
   -vframes number  set the number of video frames to output
   -r rate          set frame rate (Hz value, fraction or abbreviation)
   -s size          set frame size (WxH or abbreviation)
   -aspect aspect   set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
   -vn              disable video
   -c:v codec       force video codec ('copy' to copy stream)
   -timecode hh:mm:ss[:;.]ff  set initial TimeCode value.
   -b:v             video bitrate

Audio options:
   -an              disable audio
   -c:a codec       force audio codec ('copy' to copy stream)
   -b:a bitrate     audio bitrate
   -vol volume      change audio volume (256=normal)
   -af filter_graph  set audio filters

Most media files consist of a container file with one or more streams of content. For example an .mp3 audio file may contain channels for the left and right channels or a .mpg video file may contain a video stream plus left and right channels, but it might also include 5+1 audio channels plus a channel for subtitles.

Do not mix input and output files – first specify all input files, then all output files. Also do not mix options which belong to different files.
All options apply ONLY to the next input or output file and are reset between files.

Most of the time ffmpeg will automatically select the correct settings from the requested file extension without any complex configuration.

You can specify the codecs you want to use, ffmpeg -codecs will print all the codecs that your version of FFmpeg can handle, typically including at least the following:

==Video==
binkvideo        Bink video
h264             H.264 / AVC / MPEG-4 AVC/ MPEG-4 part 10 (decoders: h264 h264_vda ) (encoders: libx264 libx264rgb )
mpeg4            MPEG-4 part 2 (encoders: mpeg4 libxvid )
vp9              Google VP9
webp             WebP
wmv3             Windows Media Video 9
rawvideo         raw video

==Audio==
aac              AAC (Advanced Audio Coding) (encoders: aac libvo_aacenc )
alac             ALAC (Apple Lossless Audio Codec)
flac             FLAC (Free Lossless Audio Codec)
mp3              MP3 (MPEG audio layer 3)
vorbis           Vorbis (decoders: vorbis, libvorbis ) (encoders: vorbis, libvorbis )
wmalossless      Windows Media Audio Lossless
wmapro           Windows Media Audio 9 Professional

==Images==
bmp              BMP (Windows bitmap)
dvvideo          DV (Digital Video)
gif              GIF
png              PNG image
vc1image         Windows Media Video 9 Image v2
wmv3image        Windows Media Video 9 Image

==Text==
bintext          Binary text
dvb_subtitle     DVB subtitles
dvb_teletext     DVB teletext
dvd_subtitle     DVD subtitles

The codec to be used can be specified with the -c codec option

To specify the audio codec -codec:a codec
or abbreviate to -acodec codec or just -c:a codec

To specify the video codec -codec:v codec
or abbreviate to -vcodec codec or just -c:v codec

To copy a stream without re-encoding it, just specify the codec as 'copy'

If 'copy' is applied to both the audio and video (-c:av) then ffmpeg will convert from one container format to another without any re-encoding: ffmpeg -i input.webm -c:av copy output.mkv

The name ffmpeg is short for 'Fast Forward MPEG' files although the utility now does far more than that.

Examples

Convert file formats:

$ ffmpeg -i input.mp4 output.avi

$ ffmpeg -i input.mp3 output.ogg

Specify the codecs for both video (-c:v) and audio (-c:a)

ffmpeg -i input.mp4 -c:v vp9 -c:a mp3 output.mkv

Encode the audio as mp3 and copy the video stream unchanged:

ffmpeg -i input.mp4 -c:v copy -c:a mp3 output.mkv

Copy from .webm (a container format) to .mkv (another container format) without any additional stream encoding. 'av' is the default so this could also be specified with just -c copy:

ffmpeg -i input.webm -c:av copy output.mkv

Copy only the first 60 seconds of a video:

ffmpeg -i input.mp4 -t 60 -c copy output.mp4

Convert a .webm file to .mp3 specifying a high bitrate (-b) audio for best quality sound.

ffmpeg -i ~/input.webm -b:a 192k ~/output.mp3

Convert a .webm file to .mp4 specifying a high bitrate (-b) audio for best quality sound.

ffmpeg -i ~/input.webm -c:v libx264 -c:a aac -strict experimental -b:a 192k output.mp4

Batch convert a folder of .mp4 files to .mp3 (Windows CMD, see stackoverflow for bash and PowerShell versions.)

for %i in (*.mp4) do ffmpeg -i "%i" "%~ni.mp3"

Merge together 2 or more files of the same type, create a file with the filenames (one file per line)
input.txt
file 'ex1.aiff'
file 'ex2.aiff'

Then run: ffmpeg -f concat -i input.txt -c copy output.aiff

Trim a video without re-encoding it, start/end times are in hh:mm:ss.msec format:

ffmpeg -ss "00:00:55.30" -i "input.mp4" -c copy -map 0 -to "00:03:32.00" "output.mp4"

Change the Sample Aspect Ratio (SAR) of a video from 720p to 540 (4:3) This re-encodes the file:

ffmpeg -i "input.mp4" -vf scale=720:540 -c:v [Video_Codec] "output.mp4"

Change the Display Aspect Ratio (DAR) of a video from 720p to 540 (4:3) [x] this sets a metadata flag at the container level:

ffmpeg -i "input.mp4" -aspect 720:540 -c copy "output.mp4"

Television and the media are everywhere and they are taking over so powerfully. They don't shut up for a second. So you are unable to think. It is very difficult to think independently when you are surrounded by all that noise. What I most aspire to is to be alone. Not lonely, but alone. To stop all this noise. That is what I do when I go to Umbria. There is no television there, no telephone” ~ Terry Gilliam

Related

ffmpeg - Full documentation.
youtube-dl - Download Video.
A simple PowerShell GUI front end for ffmpeg (compression only).


 
Copyright © 1999-2020 SS64.com
Some rights reserved