Copy all input streams to output
ffmpeg -i input.ts -c:v copy -c:a copy -map 0:? output.mkv
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)
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
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
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 -