Skip to content

Instantly share code, notes, and snippets.

@actarian
Last active February 4, 2021 08:24
Show Gist options
  • Save actarian/96cdbdfa404994491ac0e5f193e65c0a to your computer and use it in GitHub Desktop.
Save actarian/96cdbdfa404994491ac0e5f193e65c0a to your computer and use it in GitHub Desktop.
FFMPEG alpha merge, color, clipping, jpg2000, webp, frame tiles

FFMPEG alpha merge, color, clipping, jpg2000, webp, frame tiles

sequence to jpeg2000

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -pix_fmt yuv420p -vcodec jpeg2000 "c:\ffmpeg\out\hero\cover_%04d.jpeg"

sequence to webp

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -pix_fmt yuv420p -codec libwebp "c:\ffmpeg\out\hero\cover_%04d.webp"


ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -filter_complex "[1:v]alphaextract[alf];[0:v][alf]alphamerge" -pix_fmt yuv420p -vcodec jpeg2000 "c:\ffmpeg\out\hero\cover_alpha_%04d.jpeg"

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -filter_complex "[1:v]split[a];[a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];[0:v][al]alphamerge,format=yuva420p" -pix_fmt yuv420p -vcodec jpeg2000 "c:\ffmpeg\out\hero\cover_alpha_%04d.jpeg"

sequence grayscale to alpha

ffmpeg -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -vf format=yuva444p,geq='r=255:g=255:b=255:alpha_expr=r(X,Y)' -codec png "c:\ffmpeg\in\hero\alpha_%04d.png"


sequence merge grayscale to alpha input 1 png

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -filter_complex "[1:v]format=yuva444p,geq='r=255:g=255:b=255:alpha_expr=r(X,Y)'[a1];[a1]format=yuva444p,alphaextract[alf];[0:v][alf]alphamerge" -pix_fmt rgba -codec png -q:v 1 "c:\ffmpeg\out\hero\cover_alpha_%04d.png"

sequence merge grayscale to alpha input 1 jpeg2000

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -filter_complex "[1:v]format=yuva444p,geq='r=255:g=255:b=255:alpha_expr=r(X,Y)'[a1];[a1]format=yuva444p,alphaextract[alf];[0:v][alf]alphamerge" -pix_fmt rgba -codec libopenjpeg -format 2 -compression_level 100 "c:\ffmpeg\out\hero\cover_alpha_%04d.jp2"

sequence merge grayscale to alpha input 1 webp

ffmpeg -i "c:\ffmpeg\in\hero\gbuffer_%05d.png" -i "c:\ffmpeg\in\hero\alpha_%04d copy.jpg" -filter_complex "[1:v]format=yuva444p,geq='r=255:g=255:b=255:alpha_expr=r(X,Y)'[a1];[a1]format=yuva444p,alphaextract[alf];[0:v][alf]alphamerge" -pix_fmt yuva420p -codec libwebp "c:\ffmpeg\out\hero\cover_alpha_%04d.webp"

sequence convert png to jpeg2000

ffmpeg -i "c:\ffmpeg\out\cover_alpha_%04d.png" -pix_fmt rgba -codec libopenjpeg -format 2 -compression_level 100 "c:\ffmpeg\out\cover_alpha_%04d.jp2"


sequence convert png to jpeg2000 with color

ffmpeg -f lavfi -i color=c=#eef1f4:s=1280x1280 -i "c:\ffmpeg\out\hero\cover_alpha_%04d.png" -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out];[out]crop=650:995:360:40[out]" -map "[out]" -pix_fmt rgb24 -codec libopenjpeg -format 2 -compression_level 100 "c:\ffmpeg\out\hero\cover_alpha_%04d.jp2"

sequence convert png to webp with color

ffmpeg -f lavfi -i color=c=#eef1f4:s=1280x1280 -i "c:\ffmpeg\out\hero\cover_alpha_%04d.png" -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out];[out]crop=650:995:360:40[out]" -map "[out]" -pix_fmt bgra -codec libwebp "c:\ffmpeg\out\hero\cover_alpha_%04d.webp"

video to jpeg2000 with color

ffmpeg -i "c:\ffmpeg\in\video\gbuffer_%05d.jpg" -pix_fmt rgb24 -codec libopenjpeg -format 2 -compression_level 20 "c:\ffmpeg\out\video\video_%04d.jp2"

video to webp with color

ffmpeg -i "c:\ffmpeg\in\video\gbuffer_%05d.jpg" -pix_fmt bgra -codec libwebp "c:\ffmpeg\out\video\video_%04d.webp"


hero to jpg

ffmpeg -f lavfi -i color=c=#eef1f4:s=1280x1280 -i "c:\ffmpeg\out\hero\cover_alpha_0001.png" -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out];[out]crop=650:995:360:40[out]" -map "[out]" -pix_fmt yuvj444p -q:v 15 "c:\ffmpeg\out\hero\cover_alpha_0001.jpg"

ffmpeg -f lavfi -i color=c=#eef1f4:s=1280x1280 -i "c:\ffmpeg\out\hero\cover_alpha_%04d.png" -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out];[out]crop=650:995:360:40[out]" -map "[out]" -pix_fmt yuvj444p -q:v 15 "c:\ffmpeg\out\hero\cover_alpha_%04d.jpg"

jpg compression

ffmpeg -i "c:\ffmpeg\in\video\gbuffer_%05d.jpg" -pix_fmt yuvj444p -q:v 15 "c:\ffmpeg\out\video\video_%04d.jpg"


50x1 frame tiles

ffmpeg -f lavfi -i color=c=#eef1f4:s=1280x1280 -i "c:\ffmpeg\out\hero\cover_alpha_%04d.png" -filter_complex "[0:v][1:v]overlay=shortest=1,format=yuv420p[out];[out]crop=650:995:360:40,select=not(mod(n\,2)),tile=50x1[out]" -map "[out]" -pix_fmt yuvj444p -q:v 15 "c:\ffmpeg\out\hero\hero.jpg"

50x1 frame tiles

ffmpeg -i "c:\ffmpeg\in\video\gbuffer_%05d.jpg" -filter_complex "[0:v]select=not(mod(n\,2)),tile=50x1[out]" -map "[out]" -pix_fmt yuvj444p -q:v 15 "c:\ffmpeg\out\video\video.jpg"

mac os batch

for i in *.tif; do ffmpeg -i "$i" -vf scale=1920:-1 -pix_fmt yuvj444p -q:v 15 "${i%.*}.jpg"; done

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