Commonly used commands to edit videos.

ffmpeg is a suite of libraries and programs to handle video and audio streams.

Add -preset slow -crf 18 to commands to retain a high image quality.

To get information on a video file use mediainfo input.mp4.

Reduce video size

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

Resizing

ffmpeg -i input.mp4 -vf scale=320:-1 output.mp4

Retains the aspect ration specifying the width.

ffmpeg -i input.mp4 -vf scale=-1:720 output.mp4

Retains the aspect ration specifying the height.

Cropping

ffmpeg -i input.mp4 -vf crop=w:h:x:y output.mp

Rotating

ffmpeg -i input.mov -vf transpose=1 output.mov

For the transpose parameter you can pass:

0 = 90° counterclockwise and vertical flip (default)
1 = 90° clockwise
2 = 90° counterclockwise
3 = 90° clockwise and vertical flip

Use -vf "transpose=2,transpose=2" for 180 degrees.

Recording

ffmpeg -f x11grab -video_size [width]x[height] -framerate 30 -i $DISPLAY+[xPos],[yPos] -pix_fmt yuv420p -c:v libx264 -preset superfast -crf 18 output.mp4

Records the screen without audio. Replace variables width, height, xPos and yPos. Omit +xPos,yPos to record at 0,0.

ffmpeg -f alsa -ac 2 -i default -acodec libmp3lame -ab 320k ouput.mp3

Records audio and stores it as compressed mp3

Cutting

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

Exports a part of the video startin at [start] with the duration of [duration].

Converting / Extracting Audio

ffmpeg -i video.mp4 -b:a 192K -vn music.mp3

Extracts the audio of a video to an mp3.

Concatenating

cat input.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
ffmpeg -f concat -safe 0 -i input.txt -c copy output.mp4

Concatenates multiple video files into one.