audio

ffmpeg

# default invocation
ffmpeg -i accordion.wav converted.mp3

#(https://stackoverflow.com/questions/3255674/convert-audio-files-to-mp3-using-ffmpeg)
ffmpeg -i input.wav -vn -ar 44100 -ac 2 -b:a 192k output.mp3

sox

#convert to wave
sox recital.au recital.wav
sox recital.au -r 12k -b 8 -c 1 recital.wav vol 0.7 dither
#convert to wave
sox -r 8k -u -b 8 -c 1 voice-memo.raw voice-memo.wav
#speed adjusttment
sox slow.aiff fixed.aiff speed 1.027
#concatanate
sox short.au long.au longer.au
#mix
sox -m music.mp3 voice.wav mixed.flac

video

utils

# list supported protocols
ffmpeg -protocols

rotate

# rotate 90 degree (clockwise)
ffmpeg -i sunset.mp4 -vf "transpose=1" sunset_v.mp4

crop

# detect crop parameters
ffmpeg -ss 90 -i cc_cut.mp4 -vframes 10 -vf cropdetect -f null ...

# crop and rescale
ffmpeg -i cc_cut.mp4 -vf "crop=1648:928:8:96;scale=-2:1080"  -b:a 320k cc_crop.mp4

# cut the top 30% of the video
ffmpeg -i input.mp4 -vf "crop=in_w:in_h*0.7:0:in_h*0.3" output.mp4

trim

#trim and convert (00:08 to last)
ffmpeg -i IMG_6226.mov -ss 00:00:08 -vcodec h264 -acodec aac -s hd480 IMG_6226_cut.mp4

# simple trim,keep others (re-encode the audio to keep video-audio synchronization)
ffmpeg  -ss 00:00:03 -to 00:4:54 -i aynur.mp4 -c:v copy -c:a copy aynur2.mp4

#trim & re-encode with duration
ffmpeg -ss 00:00:03 -accurate_seek -i aynur.mp4 -t 00:04:54 -c:v libx264 -c:a aac aynur2.mp4

#-ss should be at the beginning otherwise the first few seconds will freeze
ffmpeg -ss 02:05 -i Dobrogosz.mp4 -vcodec copy -acodec copy  -copyinkf output.mp4

format

#compress existing mp4 file
ffmpeg -i myvideo.mp4 -vcodec h264 -acodec aac -s hd480 myvideo.mp4

#format conversion. common resolutions: qhd hd480 hd720 nhd 
ffmpeg -i IMG_1326.mov -vcodec h264 -acodec aac -s hd480 IMG_1326.mp4

#resolution conversion, specify the width,keep aspect ratio
ffmpeg -i input.mp4 -vf scale=480:-1 output.mp4

#specify the video and audio quality
ffmpeg -i bride_cut.mp4 -vf "scale=-2:720" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 320k bride_cut_conv.mp4

create video

## create left-right collage, mute the 2nd clip,  trim the 2nd clip to the length of the first
ffmpeg -i clip1.mp4 -i clip2.mp4 -filter_complex "[1:v]scale=-1:ih[v2];[0:v][v2]hstack" -map 0:a -t $(ffprobe -v error -select_streams v:0 -show_entries stream=duration -of csv=p=0 clip1.mp4) output.mp4

## create video from single image and audio
ffmpeg -loop 1 -i 253-124_1.jpg -i ~/Music/Logic/Bounces/blueDove_faded.mp3 -c:v libx264 -c:a aac -b:a 192k -shortest -vf "scale=1280:720" output.mp4

## create stop motion from numbered images
ffmpeg -framerate 10 -pattern_type glob -i '*.JPG' -vf scale=640:-1 -c:v libx264 -pix_fmt yuv420p out.mp4

## create stop motion from video; setpts=0.5*PTS means doubling playback speed
ffmpeg -i chicken.mp4  -vf "fps=4,framestep=5,setpts=0.5*PTS" -c:a copy stop_motion.mp4

## double exposure; the videos need to be of the same dimension; starting from 5 seconds
ffmpeg -i background.mp4 -itsoffset 5 -i overlay.mp4 -filter_complex "[0:v][1:v]blend=all_mode='overlay':all_opacity=0.7"  -c:a copy output_double_exposure.mp4

image

# convert all pngs to jpg
mogrify -quality 70 -format jpg *.png

# resize images
convert /path/to/your/image.jpg -resize 800x600 -quality 85 /path/to/your/resized_image.jpg

convert /path/to/your/image.jpg -resize 50% -quality 85 /path/to/your/resized_image.jpg

# crop (the full width is 632)
sips -c 750 631 --cropOffset 1 1 blue_mosque.jpg --out cropped_image.jpg

pdf

combine images into pdf

#convert a folder of jpg files to pdf
convert *.jpg output.pdf

#convert selected images
convert movie1.jpg movie2.jpg movie3.jpg movie4.jpg output.pdf

decrypt pdf

#output: 1d.pdf
qpdf --decrypt 1.pdf 1d.pdf

combine pdfs

pdfunite *.pdf output.pdf