Skip to content

Instantly share code, notes, and snippets.

@handledexception
Created September 9, 2019 23:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handledexception/30aaef5d99c8681dfe8244293156d188 to your computer and use it in GitHub Desktop.
Save handledexception/30aaef5d99c8681dfe8244293156d188 to your computer and use it in GitHub Desktop.
FFMPEG Cheat Sheet

FFMPEG Cheat Sheet

Remux Video/Audio

Copy all input streams to output

ffmpeg -i input.ts -c:v copy -c:a copy -map 0:? output.mkv

Video Scaling

References:

Basic

ffmpeg -i input.mov -vf "scale=1920:1080" output.mov

Pillarbox/Letterbox

ffmpeg -i input.mov -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output.mov

Specify Scaling Algorithm (full list of flags)

ffmpeg -i input.mov -vf "scale=1920:1080:flags=lanczos" output.mov

or 

ffmpeg -i input.mov -vf "scale=1920:1080" -sws_flags "bicubic+full_chroma_inp" output.mov

Color Space Transform

ffmpeg -i input.mov -vf "scale=out_color_matrix=bt709" -color_primaries bt709 -color_trc bt709 -colorspace bt709 -c:v prores -profile:v 3 output.mov

Trimming

Trim video without transcode (fast method)

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

Trim video without transcode (frame accurate) - This method causes the video to be decoded up to the start point which is slower than the fast trim method.

ffmpeg -i in.mp4 -ss [start] -t [duration] -c copy out.mp4

Trim video with transcode (slowest method)

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac out.mp4
  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip (same format)
  • -to specifies the end time (only in modern FFMPEG)
  • -c copy copies the first video, audio and subtitle streams

Piping

Pipe video out of FFMPEG to stdout

ffmpeg -i my_file.mov -c:v rawvideo -video_size 640x480 -pix_fmt yuv420p -f image2pipe -
```# FFMPEG Cheat Sheet

#### Remux Video/Audio
Copy all input streams to output

ffmpeg -i input.ts -c:v copy -c:a copy -map 0:? output.mkv


#### Video Scaling

References:
- https://ffmpeg.org/ffmpeg-scaler.html
- https://trac.ffmpeg.org/wiki/Scaling
- https://superuser.com/questions/547296/resizing-videos-with-ffmpeg-avconv-to-fit-into-static-sized-player/547406

Basic

ffmpeg -i input.mov -vf "scale=1920:1080" output.mov


Pillarbox/Letterbox

ffmpeg -i input.mov -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output.mov


Specify Scaling Algorithm ([full list of flags](https://ffmpeg.org/ffmpeg-scaler.html#toc-Scaler-Options))

ffmpeg -i input.mov -vf "scale=1920:1080:flags=lanczos" output.mov

or

ffmpeg -i input.mov -vf "scale=1920:1080" -sws_flags "bicubic+full_chroma_inp" output.mov


Color Space Transform

ffmpeg -i input.mov -vf "scale=out_color_matrix=bt709" -color_primaries bt709 -color_trc bt709 -colorspace bt709 -c:v prores -profile:v 3 output.mov


#### Trimming

Trim video without transcode (fast method)

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4


Trim video without transcode (frame accurate) - This method causes the video to be decoded up to the start point which is slower than the fast trim method.

ffmpeg -i in.mp4 -ss [start] -t [duration] -c copy out.mp4


Trim video with transcode (slowest method)

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac out.mp4


- `-ss` specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
- `-t` specifies the duration of the clip (same format)
- `-to` specifies the end time (only in modern FFMPEG)
- `-c copy` copies the first video, audio and subtitle streams

#### Piping

Pipe video out of FFMPEG to stdout

ffmpeg -i my_file.mov -c:v rawvideo -video_size 640x480 -pix_fmt yuv420p -f image2pipe -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment