Difference between revisions of "FFmpeg"
Line 41: | Line 41: | ||
<code>-i</code> specifies input file | <code>-i</code> specifies input file | ||
− | The last argument is always the output file. Without specifying any codec or bit rate, FFmpeg will encode the video using some arbitrary default settings. | + | The last argument is always the output file. Without specifying any codec or bit rate (see examples below), FFmpeg will encode the video using some arbitrary default settings. |
===Remove audio from video file=== | ===Remove audio from video file=== |
Revision as of 11:57, 11 March 2024
Installed version | 6.1.1 |
---|---|
Development status | Active |
Operating system | Microsoft Windows, Linux, MacOSX |
License | GNU LGPL 2.1 |
Website | ffmpeg.org |
FFmpeg is an open-source command-line tool to convert audio and video files.
Installation
Windows 10
- Download the latest ffmpeg-release-full build on https://ffmpeg.org/download.html
- Unpack the 7z/zip file anywhere you like
- Add ffmpeg to Windows' Environment Variables:
- Open the start menu and start typing "Environment Variables"
- Select "Edit the system environment variables"
- Click "Environment Variables"
- Select "Path" and click "Edit"
- Click "Browse" and go to the folder where you unpacked your FFmpeg files. Select the 'bin' folder inside (e.g. "C:\ffmpeg\bin")
- Click OK on all previously opened windows.
- To test, go to the command line (Windows+R -> cmd) and type
ffmpeg
. It should tell you the installed ffmpeg version.
Usage
FFmpeg needs to be run from the command line, but you can create batch scripts to automate the process for multiple files. You can also set up FFmpeg for Python: https://www.bannerbear.com/blog/how-to-use-ffmpeg-in-python-with-examples/ The following are examples of conversions that we commonly use.
Basic Format Conversion
ffmpeg -i input.mp4 output.avi
-i
specifies input file
The last argument is always the output file. Without specifying any codec or bit rate (see examples below), FFmpeg will encode the video using some arbitrary default settings.
Remove audio from video file
ffmpeg -i input.mp4 -vcodec copy -an output.mp4
-vcodec copy
means the video won't be re-encoded, preserving the quality.
-an
strips the audio
Extract single audio channel from video file
ffmpeg -i input.mp4 -af "pan=mono|c0=c0" output.wav
-af "pan=mono|c0=c0"
extracts a single channel from the file. Use c0=c0
for left channel, c0=c1
for right channel.
Add audio to video
ffmpeg -i inputvideo.mp4 -i inputaudio.wav -vcodec copy -map 0:v -map 1:a output.mp4
Trimming video
ffmpeg -i input.mp4 -ss 00:00:04 -to 00:00:06 -vcodec h264 -b:v 8M output.mp4
-ss 00:00:04
specifies the starting time, in this case 4 seconds (use format HH:MM:SS, or HH:MM:SS.MS)
-to 00:00:06
specifies end point, in this case 6 seconds (same formatting as above)
Alternatively, instead of -to
, you can use -t 00:00:02
to cut exactly 2 seconds from the starting time.
-vcodec h264
specifies video codec.
-b:v 8M
specifies video bit rate, in this case 8Mbit/s, which determines video quality.
Note: you can use -c copy
to trim without re-encoding, but FFmpeg can only cut to the nearest keyframe, so the output may not be exactly the same length as specified.