Skip to content

Instantly share code, notes, and snippets.

@mrflix
Created December 30, 2022 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrflix/2f3f24d0ee3f0432fa991a6b10ade4da to your computer and use it in GitHub Desktop.
Save mrflix/2f3f24d0ee3f0432fa991a6b10ade4da to your computer and use it in GitHub Desktop.
ffmpeg & imagemagick receipts
convert for html5: ffmpeg -i "einladungsvideo-roh.mp4" -acodec aac -strict -2 -vcodec libx264 -vb 2500k -pix_fmt yuv420p -movflags +faststart -f mp4 "einladungsvideo.mp4"
high quality mp4: ffmpeg -i $1 -acidic aac -vcodec libx264 -vb 8000k -f mp4 $file.hq.mp4
mov to gif: ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
cut movie: ffmpeg -i 170208_KK_REELv03_.mp4 -ss 00:00:05 -c copy -to 00:01:10 kk_reel.mp4
scale down: ffmpeg -i zign-gif-women.mp4 -vf scale=640:-1 zign-women@640.mp4
screenshot: ffmpeg -i EKD_Schiffe_WEB.mp4 -qscale:v 5 -frames:v 1 ekd-schiffe-poster3.jpg
screenshot at time: ffmpeg -ss 00:03:30 -i helen-keller-2.4.mp4 -qscale:v 5 -frames:v 1 helen-keller-2.4.mp4.jpg
screenshot all: for i in *.mp4; do ffmpeg -n -i "$i" -qscale:v 8 -frames:v 1 "${i%}.jpg"; done
oder ffmpeg -ss 00:00:15 -i PE_Erklärfilm_26.02.mp4 -vframes 1 -q:v 2 poster.jpg
zuschneiden: ffmpeg -i in.mp4 -filter:v "crop=in_w/2:in_h/2:in_w/2:in_h/2" -c:a copy out.mp4
landscape to 16/10 portrait: ffmpeg -i in.mp4 -vf "crop=in_h*10/16:in_h:(in_w-in_h*10/16)/2:0" -c:a copy out.mp4
remove audio: -an flag
mov to web mp4: ffmpeg -i in.mov -pix_fmt yuv420p -vcodec h264 -strict -2 out.mp4
gif palette from .JPGs: ffmpeg -i %*.JPG -vf palettegen palette.png
gif to mp4: ffmpeg -i animated.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
gif to still gifs: convert -coalesce lena.gif lena_%05d.png
edit all videos in a folder: for i in *.mp4; do ffmpeg -i "$i" -an -strict -2 -vcodec libx264 -vb 600k -pix_fmt yuv420p -f mp4 "600kb/${i%}_600kb.mp4"; done
add reversed video to the video: ffmpeg -i kairos_studio_girl_01.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" kairos_studio_girl_01-loop.mp4
add reversed video to the video (no audio): ffmpeg -i kids_02_him.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" kids_02_him-loop.mp4
put index to the start (fast start in safari): ffmpeg -i kids_01_720-loop.mp4 -codec copy -map 0 -movflags +faststart kids_01_720-loop.faststart.mp4
convert in place: input="topic_01_q1_intro.mp4"; ffmpeg -i "$input" -an -vf scale=1478:1080 -c:v libx264 -vb 2000k -pix_fmt yuv420p -map 0 -movflags +faststart "/tmp/$input"; rm "$input"; mv "/tmp/$input" .;
turn images into a video: ffmpeg -f image2 -framerate 1 -pattern_type sequence -start_number 9568 -r 3 -i DSC_%d.JPG -s 2144x1424 -c:v libx264 -pix_fmt yuv420p -crf 23 frames.mp4
speed up video, remove audio (times 1.39 in this example): ffmpeg -i seriousmanual.mp4 -filter:v "setpts=PTS/1.39" -an seriousmanual-1.39.mp4
only intra frames (i frames): ffmpeg -i coverr-lofoten-coast-1576260891130.mp4 -c:v libx264 -an -strict -2 -vb 12500k -pix_fmt yuv420p -movflags +faststart -g 1 drone12500.mp4
only intra frames #2: ffmpeg -i original.mov -vf scale=960:-1 -movflags faststart -vcodec libx264 -crf 20 -g 1 -pix_fmt yuv420p output_960.mp4
notify after finish: && notify
reverse video: ffmpeg -i video.mp4 -vf reverse reversed.mp4
scale down to fixed width, convert with slow preset for better quality, limit quality to 500k, faststart for web: ffmpeg -i scrollupmemoji.mov -vf scale=140:-2 -an -c:v libx264 -vb 500k -pix_fmt yuv420p -preset slow -crf 22 -movflags +faststart -tune film -f mp4 scrollupmemoji-500@140.mp4
get frame count: ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 scrollupmemoji-500\@140.mp4
cut out frame 168 (one less than the count): ffmpeg -i headermemoji-500@140.mp4 -vf "select='eq(n,168)'" -vframes 1 headermemoji-still.png
convert pngs in subdirectories to jpgs: find . -name '*.png' -execdir mogrify -format jpg -quality 95 -background white {} \;
resize all files bigger than 7 megabytes: find . -name '*.jpg' -type f -size +7M -execdir mogrify -format jpg -resize 6000x6000\> -quality 85 -background white {} \;
convert heic’s to jpg’s find . -name '*.HEIC' -type f -execdir mogrify -format jpg -quality 90 {} \;
export jpeg: convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg
delete the pngs: find . -name '*.png' -execdir rm {} \;
resize jpgs: mogrify -verbose -resize 1400x1400\> -quality 75 +profile "*" *.jpg
grayscale: mogrify -type Grayscale *.jpg
add background to png: convert flyer_vorne.png -background black -flatten flyer_vorne.jpg
find . -name '*.jpg' -execdir mogrify -profile ~/Material/sRGB2014.icc {} \;
resample images greater than 2mb: find . -type f -name "*.jpg" -size +2M -print0 | xargs -0 mogrify -resize 5120">" -quality 60
slice of 1px of each side: mogrify -shave 1 "*" *.jpg
all svgs to pngs inkscape --batch-process --export-type=png --actions="select-by-selector:[width='2048'];FitCanvasToSelection;export-do;" *.svg
append images together: convert -append isometry-*.png out.png
add background to pngs and crop them: find . -name '*.png' -execdir convert {} -background 'hsl(46,38%,96%)' -crop 4118x2600+1426+282 +repage -flatten {} \;
crop background and place central on canvas: convert isometry-01.png -fuzz 1% -trim -gravity center -extent 4118x2600 +repage isometry-01-trimmed.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment