Skip to content

Instantly share code, notes, and snippets.

@sgnm
Last active November 16, 2023 13:27
Show Gist options
  • Save sgnm/2b227bdf3b584a8061372eb5c9dc6ffa to your computer and use it in GitHub Desktop.
Save sgnm/2b227bdf3b584a8061372eb5c9dc6ffa to your computer and use it in GitHub Desktop.
convert fragment shader to gif and mp4 file
#!/bin/sh
GIF_DIR="gif"
VIDEO_DIR="video"
convert_glsl2gif_mp4()
{
if [ ! -e ${OUTPUT_DIR}/${GIF_DIR}/${FILE_NAME}.gif ]; then
echo "exporting gif file to '${OUTPUT_DIR}/${GIF_DIR}/${FILE_NAME}.gif'"
glsl2gif $INPUT_FILE_DIR.frag -o ${OUTPUT_DIR}/${GIF_DIR}/${FILE_NAME}.gif -s 512x512 -r 30 -l 5
fi
if [ ! -e ${OUTPUT_DIR}/${VIDEO_DIR}/${FILE_NAME}.mp4 ]; then
echo "exporting mp4 file to '${OUTPUT_DIR}/${VIDEO_DIR}/${FILE_NAME}.mp4'"
ffmpeg -i ${OUTPUT_DIR}/${GIF_DIR}/${FILE_NAME}.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ${OUTPUT_DIR}/${VIDEO_DIR}/${FILE_NAME}.mp4
fi
}
CMDNAME=`basename $0`
while getopts i:o: OPT
do
case $OPT in
"i" ) FLG_I="TRUE" ; INPUT_FILE_DIR="${OPTARG}" ;;
"o" ) FLG_O="TRUE" ; OUTPUT_DIR="${OPTARG%/}" ;;
* ) echo "Usage: $CMDNAME [-i input file] [-o output directory]" 1>&2
exit 1 ;;
esac
done
if [ "$FLG_I" != "TRUE" ]; then echo "Usage: '${CMDNAME}' [-i input file] [-o output directory]"; exit 1; fi
if [ "$FLG_O" != "TRUE" ]; then echo "Usage: '${CMDNAME}' [-i input file] [-o output directory]"; exit 1; fi
if [ ! -d $OUTPUT_DIR/${GIF_DIR} ]; then mkdir -p $OUTPUT_DIR/${GIF_DIR}; fi
if [ ! -d $OUTPUT_DIR/${VIDEO_DIR} ]; then mkdir -p $OUTPUT_DIR/${VIDEO_DIR}; fi
BASE_NAME=`basename $INPUT_FILE_DIR`
INPUT_FILE_DIR=${INPUT_FILE_DIR%.*}
FILE_NAME=${BASE_NAME%.*}
### convert frag file to gif and mp4
convert_glsl2gif_mp4 $INPUT_FILE_DIR $OUTPUT_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment