Command-Line Interface (CLI) is an amazing way to perform common tasks involving digital media (converting, cropping, downloading, merging, ...) without a graphical user interface (GUI). These tools are open-source (free) and written to perform single tasks really well. Once you install the following tools, you'll be surprised how rarely you need some big software programs.
- Basics - Let's get started
- Package Manager - Installing tools
- Imagemagick - Images
- FFmpeg - Movies
- youtube-dlp - Download Videos
Once setting the working directory (aka folder) to use, you write single line commands. These start with the name of the command to use, followed by arguments commonly using a flag to signify options ie. -i may set the input file, additional options and output destination. All commands are followed by the ENTER key to run.
commandinputoptionsoutput
Commands are sometimes alone, ls to list files in current directory,
or with one input mkdir blah creates a new directory called 'blah'.
Usually a few arguments are needed following the command.
We enter these commands into the... Command-Line Interface.
- MacOS, built-in CLI is
Terminal, in Utilities directory (iTerm is also nice). - Windows, built-in CLI is
Command Prompt, some suggest msys2 + conemu. - Linux, yeah yeah...
cd(change directory), used to set working dir for accessing files.pwd(print working dir), check which directory you're in.ls(list), lists all files within working directory.mkdir(make directory), creates a new directory with name of passed.../(parent directory), used as part of path to navigate/save one directory up.open .(open working directory), view in Finder.man(manual), place before command, to read about its options.say hello world(MacOS text-to-speech), never gets old...
TAB(autocomplete), completes command or directory/filename.UP ARROW(history), toggle through recent commands.CTRL + R(reverse search), search through previous commands.CTRL + A(start of line), move cursor to start of line.CTRL + E(end of line), move cursor to end of line.CMD + K(clear), clears window of previous commands.CTRL + C(cancel), stop any task mid process.
You usually set the directory you're working in to simplify typing filename's by relative path for processing or saving items to that specific location.
cd path/to/directory
The easiest way to do this is just type cd + spacebar, then drag and drop the folder into the CLI window. Hit Enter and you're now working in that directory. Test you're there with pwd to print the path or ls to list all items within it.
Use caution when snippets include the following commands
rm/rmdir(remove / remove directory), permanently removes files!sudo(root), sometimes needed for system changes, but gives admin privledges.
A package manager keeps track of open source tools and makes installation easy. It takes a while to setup, but is worth it to quickly access these tools as you dive deeper.
Homebrew is a great package manager with a HUGE updated list of formulae.
To install, just copy + paste into the following into Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It will confirm you want to install XCode dev tools (a few Gb), press ENTER to continue, then enter your computer's password (only time it should be needed).
FYI: you won't see your password while typing, just press ENTER when done.
Since 10.12+, once the install is complete, you need to copy the 2 suggested lines, paste and press ENTER. Starts with (echo...
Once done ($ or % reappear), then to install packages
(this is generic code.. scroll down for actual packages):
brew install package_name
There is a manager called 'pacman' that comes with above CLI (msys2 + conemu), but it hasn't been tested and may not be necessary. Instead, you should use imagemagick's binary installer (which includes FFMPEG as an option!?)
- Press WIN+R
- Type : Winget install ffmpeg
- Wait 10 seconds.
- Done
Imagemagick deals with images.
Convert image into ANY format, quickly assemble gifs, and especially batch process a directory of images.
brew install imagemagick
(Windows, see Package Manager for tip on installing)
Once installed, you call it with convert (Windows use magick),
then pass any number of input and output arguments. mogrify is for batch processing.
You don't need to set an active directory, you can simply type convert (spacebar) then drag + drop original file, drag + drop again, replacing the suffix with a new filetype:
convert INPUT_FILE.xxx OUTPUT_FILE.yyy
convertlaunches ImagemagickINPUT_FILE.png, drag + drop desired image to changeOUTPUT_FILE, drag + drop again, adjusting extension to desired format
But, you'll find the command super long with the absolute filepath, which then might be frustrating to edit options within, it's ideal to cd *path* into working directory withfiles and access by relative filename path only.
Navigate to a directory of images, as described above in Set active directory.
Grab all *.png or *.jpg and output GIF:
convert *.png -loop 0 test.gif
convertlaunches Imagemagick*.pngsearches for PNGs-loop 0sets # (0 = infinite) loops (ignored in MacOS preview!)test.gifname of output file (customize).
Navigate to a directory of images, as described above in Set active directory.
Create a directory for your output using mkdir:
mkdir thumbs
Batch process using mogrify:
mogrify -resize 128x128 -quality 100 -format jpg -path ./thumbs *.jpg
mogrifylaunch batch tool of Imagemagick,-resize #x#resizes (can also use percentages)-quality 100sets compression-format jpgoptional suffix to convert formats-path ./thumbsspecifies where to put outputs*.jpgsearches for JPGs in active dir
- Imagemagick CLI
- Imagemagick Formats
- Mogrify Batch Guide
- Fred's ImageMagick Scripts
- gifsicle - for everything GIF!
FFmpeg deals with audio/video.
It's the underlying tech beneath most online/offline media converters.
brew install ffmpeg
(Windows, see Package Manager for tip on installing)
Once installed, call with ffmpeg,
pass -i INPUTFILE.xxx, options, output file:
ffmpeg -i myfile.mov myfile.mp4
It's really as easy as above! You don't even need to set an active directory, you can simply type ffmpeg -i then drag + drop original file, drag + drop again, replacing the suffix with a new filetype:
ffmpeg -i input.xxx output.yyy
Get the loooong list of formats + codecs:
ffmpeg -formats
ffmpeg -codecs
Then apply them while converting:
ffmpeg -i myfile.mp4 -vcodec libx265 myfile_265.mp4
Similar to above, but with an added parameter:
ffmpeg -i input.mp4 -pix_fmt rgb24 output.gif
Extract segment from movie without re-encoding
ffmpeg -ss 10 -i input.mp4 -c copy -t 15 output.mp4
ffmpeglaunches FFmpeg-ss ##start from __ in sec-i input.mp4input file-c copyuse existing codec (instant, no re-encoding)-t ##duration for new clip in sec (use-to ##for time in clip)output.mp4name/path for new output file
Navigate to directory of video, as described above in Set active directory.
Create directory for output using mkdir:
mkdir frames
Set input file, frames per second for output, file path/type:
ffmpeg -i input.mp4 -vf fps=1 frames/out_%04d.png
-vf fps=1exports # frames per second%04duse 4 padded digits (0000, 0001, ...)
Navigate to directory of video, as described above in Set active directory.
Extract audio and convert to mp3 (or other format):
ffmpeg -i in.mp4 -vn -ac 2 out.mp3
Navigate to directory of video, as described above in Set active directory.
We can merge an audio + video, using the shortest one as the file length:
ffmpeg -i input.mov -i input.mp3 -c:v copy -map 0:v:0 -map 1:a:0 -shortest output.mov
Navigate to directory of images, as described above in Set active directory.
ffmpeg -framerate 30 -pattern_type glob -i '*.png'
-c:v libx264 -pix_fmt yuv420p out.mp4
-framerate 30sets number of frames per second*.pngsearches for PNGs (or use*.jpg)
Useful to speed up long screen-recordings:
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4
-filter:v "setpts=0.5*PTS"0.5 = faster, 1.0 = normal, 1.5 = slower
FFmpeg ships with a minimal audio/video player ffplay.
Basic usage:
ffplay input.mp4
Useful shortcuts:
q/ESC(quit)f(toggle fullscreen)p/SPACEBAR(toggle pause)m(toggle mute)left/right(seek backward/forward 10 seconds)up/down(seek backward/forward 1 minute)
Loop endless at fullscreen:
ffplay -fs -loop 0 input.mp4
View audio waveform:
ffplay -showmode 1 input.mp4
View audio frequency (FFT) spectrogram:
ffplay -showmode 2 input.mp4
View debug Motion Vectors:
ffplay -flags2 +export_mvs -vf codecview=mv=pf+bf+bb input.mp4
Export Motion Vectors only:
ffmpeg -flags2 +export_mvs -i input.mp4 -vf "split[src],codecview=mv=pf+bf+bb[vex],[vex][src]blend=all_mode=difference128,eq=contrast=7:brightness=-1:gamma=1.5" -c:v libx264 output.mp4
- FFmpeg CLI guide
- FFmpeg video codecs
- Rick Companje - FFMpeg Tips
- Complete list of ffmpeg flags / commands
- Werner Robitza FFmpeg guide
- 20 FFmpeg commands for beginners
- Fancy (ffplay) Filtering Examples
- More tips for converting images to video
- Ludwig Zeller FFmpeg Cheatsheet
youtube-dlp is a great fork from the original youtube-dl project, which is an online media extractor.
The ultimate tool for downloading and archiving media files from almost any website.
brew install yt-dlp
(Windows, see Package Manager for tip on installing, or download binary)
cd the desired directory for saving to, then as simple as:
yt-dlp VIDEO_URL
Most hosted videos have multiple files to stream depending on connection speed / quality.
List formats:
yt-dlp VIDEO_URL -F
It will return a long list of available formats, starting with an ID.
Then download the one you prefer:
yt-dlp VIDEO_URL -f ##
Or download the best mp4 or similar format:
yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' VIDEO_URL
Or download the best m4a or audio format:
yt-dlp -f 'bestaudio[ext=m4a]' VIDEO_URL
Then use ffmpeg above to convert to desired format.
- yt-dlp options, laundry list of features to use
- youtube-dlg, a GUI approach for yt-dl(p)
Read the man (manual) pages to become an expert, ie man say.
Learn more by doing web-search (usually Stack-Overflow discussion) for command + task you'd like to perform.
Enjoy more productivity with less interface!
Missing crucial tools or tips? Make an issue on GitHub.
Updated 2026.04.21
cc teddavis.org 2019 –
additional contributions: Ya-No, Hansi3D