Skip to content

Instantly share code, notes, and snippets.

@MichaelPaulukonis
Last active August 3, 2023 04:38
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 MichaelPaulukonis/f9fca0516c96410e3d54edd5372356cc to your computer and use it in GitHub Desktop.
Save MichaelPaulukonis/f9fca0516c96410e3d54edd5372356cc to your computer and use it in GitHub Desktop.
Commands and notes on my use of ffmpeg (and ImageMagick, as it pertains)

ffmpeg commands

Some of these DO NOT WORK and I'm not sure why they are here ugh

ffmpeg -r 15 -f image2 -s 500x500 -pattern_type glob -i '*.png' -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 3 -f image2 -pattern_type glob -i '*.png' -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 3 -f image2 -pattern_type glob -i '*.png' -vf scale=-2:2048 -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 3 -f image2 -pattern_type glob -i '*.png' -vf pad=4096:4096:0:40:black -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 15 -f image2 -pattern_type glob -i '*.png' -vf pad="max(iw\,ih):ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 15 -f image2 -pattern_type glob -i '*.jpg' -vf pad=4096:4096:0:40:black -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

ffmpeg -r 15 -f image2 -pattern_type glob -i '*.jpg' -vf pad="ceil(max(iw\,ih)/2)*2:ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'monas.mp4'

Center and pad (default blank) images that are < 1080x1080

ffmpeg -r 10 -f image2 -s 1080x1080 -pattern_type glob -i '*.jpg' -vf pad="ceil(max(iw\,ih)/2)*2:ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'combined.mp4'

Just combine them

ffmpeg -r 3 -f image2 -pattern_type glob -i '*.jpg' -vf scale=720:-2 -vcodec libx264 -crf 17 -pix_fmt yuv420p 'putin.mp4'

[libx264 @ 0x7fe2fdd0dbc0] width not divisible by 2 (1571x1048)

UGH.

ffmpeg -i *.jpg -vf scale=720:-2 putin.mp4

ffmpeg -r 6 -f image2 -pattern_type glob -i '.jpg' -vf scale=720:-2 -vcodec libx264 -crf 17 -pix_fmt yuv420p 'putin.mp4' ffmpeg -r 6 -f image2 -pattern_type glob -i '.jpg' -vf "scale=720:-2:force_original_aspect_ratio=decrease,pad=720:720:-1:-1:color=black" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'putin.mp4'

ffmpeg can only intake ONE FILE TYPE at a time

So, jpg or png, make your choice

rename "s/jpeg$/jpg/" *.jpeg

magick "*.png" -set filename: "out_%[t]" -auto-orient "%[filename:].jpg"

ffmpeg -f concat -safe 0 -i filelist.txt -c copy mergedVideo.mp4

https://stackoverflow.com/a/56002050/41153 https://video.stackexchange.com/questions/15468/non-monotonous-dts-on-concat-ffmpeg

sizes of multiple files

identify -ping -format "%f %w %h : %g\n" *.jpg  > image_info_file.txt

gif conversion

ffmpeg -i 20210627_135402.gif -q:v 1 -f mpegts squares_1.ts

ffmpeg -f concat -safe 0 -i filelist.txt -c copy mergedVideo.mp4

ffmpeg -i "concat:squares_1.ts|squares_2.ts|squares_3.ts|squares_4.ts" -pix_fmt rgb24 output.gif

ffmpeg -i output.gif -map 0 -c copy output.mp4

ffmpeg -i output.gif -c:v libx264 -c:a copy -pix_fmt yuv420p output.mp4

-pix_fmt yuv420p

ffmpeg -i "concat:output.mp4|output_2.mp4|output_3.mp4|output_4.mp4" -safe 0 -c copy output_merged.mp4

ffmpeg -f concat -safe 0 -i mergelist.txt -c copy output_merged.mp4

squares_source.gif - 628x626

ffmpeg -r 10 -f image2 -s 1080x1080 -pattern_type glob -i '2022_02_10_17_30_06_*.png' -vf pad="ceil(max(iw,ih)/2)*2:ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p '2022_02_10_17_30_06.mp4'

ffmpeg -r 10 -f image2 -s 1504x1080 -pattern_type glob -i '*.png' -vcodec libx264 -crf 17 -pix_fmt yuv420p 'drone2.mp4'

ffmpeg -r 10 -f image2 -s 3337x2396 -pattern_type glob -i '*.jpg' -vf pad="ceil(max(iw,ih)/2)*2:ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'drone2.mp4'

ffmpeg -r 5 -f image2 -s 3337x2396 -pattern_type glob -i '*.jpg' -vf pad="ceil(max(iw,ih)/2)*2:ow:(ow-iw)/2:(oh-ih)/2" -vcodec libx264 -crf 17 -pix_fmt yuv420p 'blue.mp4'

3337x2396 3391x2359

video mosaic

extract frames from mp4

ffmpeg -i 0001-0072.mp4 -vf fps=10 out%d.png

2022_02_10_17_30_06_00014

1920x1080 -> crop to -> 1504x1080 offset 208,0

convert out5.png -crop 1504x1080+208+0 cropped.png

convert *.png -crop 1504x1080+208+0 ./cropped/cropped_%2d.png

ffmpeg -i /Users/MPAULUKO/Movies/2022-02-11_22_36_55_952211/0001-0072.mp4 -vf fps=10 /Users/MPAULUKO/Movies/2022-02-12_17_10_45_175894/singles/moret%d.png

/Users/MPAULUKO/Movies/2022-02-11_22_36_55_952211/0001-0072.mp4

/Users/MPAULUKO/Movies/2022-02-12_17_10_45_175894

for f in "#moret*.png"; do mv -- "$f" "clean_$f"; done

extract frames from gif

convert -coalesce 2022_02_10_17_30_06.gif 2022_02_10_17_30_06/xx_%05d.png

convert 2022_02_10_17_30_06.gif -coalesce 2022_02_10_17_30_06/xx_%05d.png

convert 2022_02_10_17_30_06.gif -coalesce 2022_02_10_17_30_06_%05d.png

convert "2022_02_10_17_30_06.gif[1]" 2022_02_10_17_30_06/xx_%05d.png

magick identify -verbose 2022_02_10_17_30_06.gif

reprocessing for size

https://dev.to/benjaminblack/use-ffmpeg-to-compress-and-convert-videos-458l https://unix.stackexchange.com/questions/28803/how-can-i-reduce-a-videos-size-with-ffmpeg

ffmpeg -i source.mp4 -c:v libvpx-vp9 -b:v 0.33M -c:a libopus -b:a 96k -filter:v scale=960x540 target.webm

-vcodec libx265 -crf 28

/Users/MPAULUKO/Documents/monas.1776.mp4

ffmpeg -i /Users/MPAULUKO/Documents/monas.1776.mp4 -vcodec libx265 -crf 28 -filter:v scale=720x720 target.mp4

quicktime didn't like it, so

ffplay target.mp4

I Uploaded the video to Google Photos, which played it fine, and then to Instagram, which was also fine.

https://legacy.imagemagick.org/Usage/video/

resizing

https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/

mogrify -path OUTPUT_PATH -filter Triangle -define filter:support=2 -thumbnail OUTPUT_WIDTH -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -strip INPUT_PATH

concatenate

$ cat mylist.txt
file /Users/michaelpaulukonis/projects/images/tell_him_nancy/hilbert/hilbert.5.720.mp4
file /Users/michaelpaulukonis/projects/images/tell_him_nancy/hilbert/hilbert.20.720.mp4
file /Users/michaelpaulukonis/projects/images/tell_him_nancy/hilbert/hilbert.30.720.mp4
file /Users/michaelpaulukonis/projects/images/tell_him_nancy/hilbert/hilbert.10.720.mp4
    
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp4

NOTE: all files must be "the same configuration" - size, fps, etc. So those slow framerates needs to me increased to 30

ffmpeg -i hilbert.20.720.mp4 -r 30 -y remade.20.720.mp4

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