• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
  • Created about 4 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📼 A cheatsheet for common video processing operations in FFmpeg

FFmpeg Cheatsheet

A cheatsheet for common video processing operations in FFmpeg

Operations

Use the -y flag to override the output file if it exists.

Audio-video sync

Reference

# Delay audio by 3 seconds
$ ffmpeg -i input.mov -itsoffset 3 -i input.mov -map 0:v -map 1:a -codec:a copy -codec:v copy output.mov

# Delay video by 3 seconds (ie. advance audio by 3 seconds)
$ ffmpeg -i input.mov -itsoffset 3 -i input.mov -map 1:v -map 0:a -codec:a copy -codec:v copy output.mov
  • The second -i flag must come immediately after the -itsoffset flag.

Crop

Reference

# Crop to width 360, height 640
$ ffmpeg -i input.mov -filter:v 'crop=360:640:0:0' -codec:a copy output.mov

# Crop to width 360, height 640, starting from coordinates (10, 20)
$ ffmpeg -i input.mov -filter:v 'crop=360:640:10:20' -codec:a copy output.mov

Format

Reference

# Convert to GIF
$ ffmpeg -i input.mov output.gif

# Convert from GIF
$ ffmpeg -i input.gif output.mov

# Convert between non-GIF formats
$ ffmpeg -i input.mov -codec:v copy -codec:a copy output.mp4

Frame rate

Reference

# Change the frame rate to 12
$ ffmpeg -i input.mov -filter:v 'fps=fps=12' -codec:a copy output.mov

Strip audio

Reference

# Remove audio
$ ffmpeg -i input.mov -codec:v copy -an output.mov

Resize

Reference

# Resize to width 360, height 640
$ ffmpeg -i input.mov -filter:v 'scale=360:640' -codec:a copy output.mov

# Resize to width 360, maintaining the aspect ratio
$ ffmpeg -i input.mov -filter:v 'scale=360:-1' -codec:a copy output.mov

# Resize to height 640, maintaining the aspect ratio
$ ffmpeg -i input.mov -filter:v 'scale=-1:640' -codec:a copy output.mov
  • Set either width or height to -1 to maintain the aspect ratio.

Reverse

Reference

# Reverse
$ ffmpeg -i input.mov -filter:v 'reverse' -filter:a 'areverse' output.mov

Rotate

Reference

# Rotate 90 degrees clockwise
$ ffmpeg -i input.mov -filter:v 'transpose=1' -codec:a copy output.mov

# Rotate 90 degrees counter-clockwise
$ ffmpeg -i input.mov -filter:v 'transpose=2' -codec:a copy output.mov

# Rotate 180 degrees
$ ffmpeg -i input.mov -filter:v 'transpose=1,transpose=1' -codec:a copy output.mov

Speed

Reference

# Quarter the speed
$ ffmpeg -i input.mov -filter:v 'setpts=4*PTS' -filter:a 'atempo=0.5,atempo=0.5' output.mov

# Halve the speed
$ ffmpeg -i input.mov -filter:v 'setpts=2*PTS' -filter:a 'atempo=0.5' output.mov

# Double the speed
$ ffmpeg -i input.mov -filter:v 'setpts=0.5*PTS' -filter:a 'atempo=2' output.mov

# Quadruple the speed
$ ffmpeg -i input.mov -filter:v 'setpts=0.25*PTS' -filter:a 'atempo=2,atempo=2' output.mov
  • Use the formula 1 ÷ speed to compute the value of setpts.

    • Half the speed: setpts=2*PTS since 1 ÷ 0.5 = 2.
    • Double the speed: setpts=0.5*PTS since 1 ÷ 2 = 0.5.
  • The value of each atempo filter must be between 0.5 and 2.

    • Quarter the speed: atempo=0.5,atempo=0.5 since 0.5 × 0.5 = 0.25.
    • Quadruple the speed: atempo=2,atempo=2 since 2 × 2 = 4.

Subtitles

Reference

# Write subtitles into video
$ ffmpeg -i input.mov -filter:v 'subtitles=subtitles.srt' -codec:a copy output.mov

# Write subtitles into video, with custom subtitle styles
$ ffmpeg -i input.mov -filter:v "subtitles=subtitles.srt:force_style='FontName=Menlo Bold,Fontsize=18'" -codec:a copy output.mov

Trim

Reference

# Trim from 0:05 to 0:10
$ ffmpeg -ss 0:05 -to 0:10 -i input.mov -codec:v copy -codec:a copy output.mov

# Trim from 0:05 to the end of the video
$ ffmpeg -ss 0:05 -i input.mov -codec:v copy -codec:a copy output.mov
  • The -ss and -to flags must come before the -i flag.

Volume

Reference

# Halve the volume
$ ffmpeg -i input.mov -codec:v copy -filter:a 'volume=0.5' output.mov

# Double the volume
$ ffmpeg -i input.mov -codec:v copy -filter:a 'volume=2' output.mov

Relevant CLI flags

Reference

ffmpeg
  -an
  -ss <timestamp>
  -to <timestamp>
  -itsoffset <offset>
  -i <input>
  -map <stream>
  -codec:a <codec>
  -codec:v <codec>
  -filter:a <filtergraph>
  -filter:v <filtergraph>
  -y
  <output>

See also

More Repositories

1

vdx

🎞️ An intuitive CLI for processing video, powered by FFmpeg
TypeScript
1,665
star
2

charming

🎩 Lettering.js in vanilla JavaScript
JavaScript
1,005
star
3

create-figma-plugin

🔋 The comprehensive toolkit for developing plugins and widgets for Figma and FigJam
TypeScript
943
star
4

malarkey

⌨️ Simulate a typewriter effect in vanilla JavaScript.
JavaScript
239
star
5

figma-plugins

🔥 Monorepo for my Figma plugins
TypeScript
238
star
6

load-google-maps-api

🌏 A lightweight Promise-returning helper for loading the Google Maps JavaScript API
JavaScript
170
star
7

vim-basics

✌️ Just the basics to get you up and running with Vim
Vim Script
136
star
8

stable-diffusion-rest-api

🤗 Run Stable Diffusion locally via a REST API on an M1/M2 MacBook
TypeScript
129
star
9

line-clamp

🗜️ Line clamp a DOM element in vanilla JavaScript
JavaScript
75
star
10

autosize-input

🎈 Effortless, dynamic-width text boxes in vanilla JavaScript
JavaScript
68
star
11

figma-plugins-stats

📈 A CLI to get live and historical stats for your Figma plugins
TypeScript
61
star
12

cuba

🇨🇺 Google Sheets + SQL = JSON
JavaScript
55
star
13

single-page-markdown-website

🌶️ Create a nice single-page documentation website from one or more Markdown files
TypeScript
47
star
14

menu-aim

🎯 Instant mega menus in vanilla JavaScript.
JavaScript
40
star
15

fastmatter

👀 A fast frontmatter parser. Supports both string and stream inputs.
JavaScript
28
star
16

awesome-create-figma-plugin

26
star
17

regular-expressions-cheatsheet

🅰️ A concise cheatsheet for using Regular Expressions in JavaScript
JavaScript
16
star
18

generate-css

💥 Dynamically generate functional CSS classes from HTML and JavaScript source files
TypeScript
16
star
19

stoke

🌲 Generate the Abstract Syntax Tree (AST) of a Bash command
JavaScript
15
star
20

gulp-tape

👻 Run Tape tests in Gulp.
JavaScript
14
star
21

generate-ts-docs

📘 Utilities to parse type information and JSDoc annotations from TypeScript source files, and render Markdown documentation
TypeScript
12
star
22

shell-basics

🐚 A quick overview of the Unix shell
12
star
23

macos-keyboard-shortcuts

⌨️ A CLI to set application-specific keyboard shortcuts for macOS
TypeScript
12
star
24

rdd

📝 Preview your Markdown locally as it would appear on GitHub, with live updating
JavaScript
11
star
25

code-problems

🐫 Working through code problems in OCaml
OCaml
7
star
26

git-cheatsheet

🌳 A handy list of commonly used Git commands
6
star
27

interpolate

Simple string interpolation in PHP.
PHP
5
star
28

sketch-plugins

Monorepo for my Sketch plugins
JavaScript
5
star
29

quine

✍️ Programs that write themselves.
Shell
5
star
30

sketch-plugin-helper

Utilities to help you make Sketch plugins
JavaScript
5
star
31

grouper

Assign objects to groups by one or more properties, by object value, or by using a comparator function.
JavaScript
4
star
32

modal

Super-simple modals in vanilla JavaScript.
JavaScript
4
star
33

react-redux-modal

🔮 A React modal bound to the Redux store.
JavaScript
4
star
34

widget

TypeScript
3
star
35

yuanqing.sg

⚪ My personal website
HTML
3
star
36

figmake

🍦 A tiny CLI for making Figma plugins in HTML, CSS, and vanilla JavaScript
TypeScript
3
star
37

sketch-handbook

📙 A concise handbook on working precisely and effectively in Sketch
Shell
3
star
38

figma-plugins-monetization-stats

JavaScript
3
star
39

figma-add-auto-layout-item

TypeScript
2
star
40

versus

Compare two variables with the comparison operator specified as a string.
JavaScript
2
star
41

google-sheets-rest-api

JavaScript
2
star
42

q

🍦 An opinionated CLI for creating lightweight, vanilla HTML/CSS websites
JavaScript
2
star
43

jockey

Modelling a playlist that supports shuffle, repeat, and reordering.
JavaScript
2
star
44

xoxo

🎧 A YouTube mixtape maker thing.
JavaScript
2
star
45

asset-versioning

🗃️ Version your assets by appending a hash to the filename.
JavaScript
2
star
46

shared-event-listeners

A utility for minimising the number of event listeners bound on a given DOM element.
JavaScript
2
star
47

Q.js

A micro JavaScript library.
JavaScript
2
star
48

create-figma-plugin-react-example

JavaScript
2
star
49

sketch-add-artboard-borders-and-titles

JavaScript
2
star
50

extract

Sugar for getting data out of strings in PHP.
PHP
2
star
51

fi

Query a collection of text files like a document database in PHP.
PHP
2
star
52

string-extractor

Regular expression sugar for getting data out of strings.
JavaScript
1
star
53

cli

TypeScript
1
star
54

cors

JavaScript
1
star
55

savoy

Higher-order functions (synchronous and asynchronous each/eachSeries/map/filter/fold) and functions for flow control (parallel/series/waterfall) in under 1 KB.
JavaScript
1
star
56

kontact

An extensible contact form in PHP and vanilla JavaScript/AJAX.
JavaScript
1
star
57

abstract-backup

💾 Download a local backup of the Sketch files from all your Abstract projects
JavaScript
1
star
58

sketch-sort-layer-list

JavaScript
1
star
59

npm-boilerplate

Barebones boilerplate using `npm run-script`.
JavaScript
1
star
60

clinical

💊 A minimum-viable arguments parser in ~90 LOC with zero dependencies
TypeScript
1
star
61

google-sheets

🍃 An easier interface to read from and write to Google Sheets
JavaScript
1
star
62

sketch-clean-document

JavaScript
1
star
63

gulp-boilerplate

A Gulp-powered boilerplate for Node and JavaScript projects.
JavaScript
1
star
64

segue

Enqueue functions, and call them in series.
JavaScript
1
star
65

unfurl

Extract the query string and hash of a URL.
JavaScript
1
star
66

sketch-extract-text

JavaScript
1
star
67

bbqr

JavaScript
1
star
68

sketch-move-layers

JavaScript
1
star
69

pppath

Join strings to form a valid file path.
JavaScript
1
star
70

simple-code-editor

TypeScript
1
star
71

resizable

TypeScript
1
star
72

svg-inserter

TypeScript
1
star
73

build-website

TypeScript
1
star
74

.github

1
star
75

eslint-config-yuanqing

⚙️ An opinionated ESLint configuration for TypeScript and Preact projects
JavaScript
1
star
76

append-js-extension-to-local-imports

JavaScript
1
star
77

screen-recorder

JavaScript
1
star
78

sketch-select-layers

JavaScript
1
star
79

sketch-draw-slice-over-selection

JavaScript
1
star
80

sketch-align-to-grid

JavaScript
1
star
81

frontend-boilerplate

🌱 Super basic web boilerplate with Sass and vanilla JavaScript.
HTML
1
star
82

isomorphic

JavaScript
1
star
83

tsu

Utilities and functional wrappers over `through2`.
JavaScript
1
star
84

sketch-rename-layers

🖋️ [WIP] A Sketch plugin to automate layer renaming
JavaScript
1
star
85

johnson-trotter

An implementation of the Johnson-Trotter permutation algorithm.
JavaScript
1
star
86

rectify

Unsmarten your quotes, dashes, and ellipses.
JavaScript
1
star
87

stylelint-config-yuanqing

🕴️ An opinionated stylelint configuration
JavaScript
1
star
88

react-autocomplete

[UNMAINTAINED] React autocomplete component with an opinionated UX.
JavaScript
1
star