Skip to content

Instantly share code, notes, and snippets.

@dogtopus
Last active November 5, 2018 21:03
Show Gist options
  • Select an option

  • Save dogtopus/a273bba8af16f595905dbb1b18b4c955 to your computer and use it in GitHub Desktop.

Select an option

Save dogtopus/a273bba8af16f595905dbb1b18b4c955 to your computer and use it in GitHub Desktop.
Washing Machine Video generator

Washing Machine Video generator

>Why is she in a washing machine?
>No anon, YOU are in the washing machine

wmv

(Not actual output)

Usage

ffmpeg -i <input> -f image2 -loop 1 -i <mask-generated-by-maskgen> -shortest -filter_complex_script wmvfilter.fff -map "[output]:0:v" <output-params> <output>

For maskgen.sh see the comments in the file.

Example

Generates a ready-to-use WMV from a 16:9 video file bga.mp4 (audio not included)

./maskgen.sh maskgen.config.sh
ffmpeg -i bga.mp4 -f image2 -loop 1 -i mask.png -shortest -filter_complex_script wmvfilter.fff -map "[output]:0:v" -c:v wmv2 -q:v 4 -an bga.wmv
#!/bin/bash
# Aspect ratio
ARX=16
ARY=9
# Darkness of the reflection part
DR=.65
# Output filename
OUT='mask.png'
#!/bin/bash
# Generates mask parametrically for wmvfilter
# Requires imagemagick
# Do not touch
declare -i BC_SCALE=12
declare -i OUTPUT_SCALE=10
WIDTH=600
if [[ $# < 1 ]]; then
echo "Usage ${0} <config>"
exit 1
fi
declare -i ARX
declare -i ARY
declare DR
declare OUT
source "${1}"
populate_and_run_bc_exp() {
printf "%.${OUTPUT_SCALE}f\n" "$(bc <<< $(echo "scale=${BC_SCALE}; ""$@"))"
}
height=$(populate_and_run_bc_exp "${WIDTH}/${ARX}*${ARY}")
padding_height=$(populate_and_run_bc_exp "${WIDTH}/${ARX}*((${ARX}-${ARY})/2)")
echo "Dimension: ${WIDTH}x${height}"
echo "Gradient Region: ${WIDTH}x${padding_height}"
echo "Darkness: ${DR}"
magick -size "${WIDTH}x${height}" -define "gradient:vector=300,0,300,${padding_height}" "gradient:rgba(0,0,0,${DR})-rgba(0,0,0,1)" "${OUT}"
[0:v] scale=600:-1,split [main][copy];
[main] pad=0:ih*2:0:0:black [main];
[copy] vflip [flipped];
[flipped][1:v] overlay=0:0 [reflect];
[main][reflect] overlay=0:H/2:shortest=1,pad=0:(600-ih/2)/2+ih:0:(600-ih/2)/2:black,crop=600:600:0:0 [output];
[output] setsar=1:1,setdar=1:1 [output]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment