SVA-CS2-24

Command Line Tools for Artists

Here are three useful tools and some tips on getting started.

ImageMagick - command line image manipulation

FFmpeg - everything audio/video related

Youtube DL - streaming video extractor!

If you get stuck with something, you can always look at the help manual for any command using the -h flag. For example, ffmpeg -h, will show you the options when running the ffmpeg command.

Imagemagick

Imagemagick is a powerful command line image editor that can do a lot of the functions that you probably use Photoshop for.

Installation

On a mac, type brew install imagemagick

On windows, use the binary to install: Imagemagick - Windows Binary Release

Anatomy of a Command

convert inputName.ext -some_command options outputName.ext

On Windows, use magick to run a command instead of convert

Useful Commands

Convert Filetypes

Gif Magick!

Resize and convert!

Trim and Crop

Batch with mogrify

Warning, mogrify overwrites file by default! Can do permanent damage if you don’t have it write to a new file!

Resources

FFmpeg

FFmpeg is a command line tool for audio/video. It is used a lot in other conversion tools.

Installation

On a mac, type brew install ffmpeg

On a PC, use this link to download an build from source. link

Anatomy of a Command

ffmpeg -i input.xyz options output.xyz

Useful Commands

Convert between Formats and Codecs

ffmpeg -i input.xyz output.xyz

See the list of formats + codecs:

Movie to GIF

ffmpeg -i input.mp4 -f gif output.gif - convert a movie file to a gif

You can lower the frame rate by adding -r 10 changing the frame rate to 10. Similarly, adding -r 320x240 will change the image size.

Too Big? Try using imagemagick to optimize the gif convert -layers Optimize output.gif output_optimized.gif

Trim

ffmpeg -ss 10 -i input.mp4 -c copy -t 15 output.mp4 - trim a video without re-encoding

Explainer:

Extract frames

Use the -vf flag to output video frames.

Make a directory for the frames mkdir frames

Set input file, frames per second for output, file path/type: ffmpeg -i input.mp4 -vf fps=1 frames/out_%04d.png

Explainer:

Extract Audio

ffmpeg -i in.mp4 -vn -ac 2 out.mp3 - Extract audio and convert to mp3 (or other format):

Merge Audio + Video

Merge an audio and video, uses 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

Video from directory

Create a movie from a directory of images! ffmpeg -framerate 30 -pattern_type glob -i '*.png' \ -c:v libx264 -pix_fmt yuv420p out.mp4

Explainer:

Speed

Useful to speed up long screen-recordings: ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" output.mp4

Explainer:

Playback

FFmpeg ships with a minimal audio/video player ffplay that you can launch from the terminal.
ffplay input.mp4

Useful shortcuts:

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

youtube-dl

youtube-dl is an online media extractor.
The ultimate tool for downloading and archiving media files from almost any website.
Lately, there’s been more activity and updates on a fork, youtube-dlp, so might be better to use this one.

Install

On a mac, type brew install yt-dlp for the forked version that works with more sites and has more options.

For Windows, download the .exe from here

Anatomy of a command

cd into the directory where you want to save the video.

yt-dlp *some url**

Formats

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*

After using yt-dlp you can use ffmpeg to trim video, make it a gif, or perform other tasks!