Last active
March 11, 2019 23:23
-
-
Save Ahuge/6f2646b46dffdd28bc5e88c58ca2868a to your computer and use it in GitHub Desktop.
FFMPEG script to convert two image sequences. To Use: `bash convert.sh` and answer it's questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function join_by { local IFS="$1"; shift; echo "$*"; } | |
read -r -p $'\e[;1;4mInput path with %d format:\e[0m ' INPUT_PATH; | |
read -r -p $'\e[;1;4mOutput directory:\e[0m ' OUTPUT_DIR; | |
read -r -p $'\e[;1;4mWould you like to convert the filetype? [y/N]\e[0m ' convertType | |
if [[ "$convertType" =~ ^([yY][eE][sS]|[yY])+$ ]] | |
then | |
read -r -p $'\e[;1;4mEnter destination filetype:\e[0m ' outputFileType; | |
else | |
outputFileType=(${INPUT_PATH//./ }[-1]) | |
fi | |
read -r -p $'\e[;1;4mWould you like to scale the image? [y/N]\e[0m ' scaleImage | |
if [[ "$scaleImage" =~ ^([yY][eE][sS]|[yY])+$ ]] | |
then | |
read -r -p $'\e[;1;4mEnter output size eg 300x300:\e[0m ' outputSize; | |
scaleParam="-vf scale=$outputSize "; | |
else | |
scaleParam=""; | |
fi | |
_INPUT_PARTS=(${INPUT_PATH//./ }); | |
# echo "_INPUT_PARTS: ${join_by "|" $_INPUT_PARTS}"; | |
_INPUT_BASE=`join_by "." ${_INPUT_PARTS[@]::${#_INPUT_PARTS[@]}-2}`; | |
# echo "_INPUT_BASE: $_INPUT_BASE"; | |
_INPUT_EXT=${_INPUT_PARTS[-1]}; | |
# echo "_INPUT_EXT: $_INPUT_EXT"; | |
GLOB_PATH="${_INPUT_BASE}.*.${_INPUT_EXT}"; | |
# echo "GLOB_PATH: $GLOB_PATH"; | |
_frames=($(ls -d $GLOB_PATH)); | |
_sorted=($(sort <<< "${_frames[*]}")); | |
# echo "_sorted: $_sorted"; | |
_first_filename=${_sorted[0]}; | |
_last_filename=${_sorted[-1]}; | |
# echo "First Frame: $_first_filename"; | |
# echo "Last Frame: $_last_filename"; | |
_first_frame_number_parts=(${_first_filename//./ }); | |
_first_frame_number=(${_first_frame_number_parts[-2]}); | |
# echo "First Frame Num: $_first_frame_number"; | |
_last_parts=(${_last_filename//./ }); | |
_last_frame_number=(${_last_parts[-2]}); | |
# echo "Last Frame Num: $_last_frame_number"; | |
INPUT_FILENAME="${INPUT_PATH##*/}"; | |
# echo "INPUT_FILENAME: $INPUT_FILENAME"; | |
INPUT_FILENAME_PARTS=(${INPUT_FILENAME//./ }); | |
INPUT_FILENAME_NO_EXT=`join_by "." ${INPUT_FILENAME_PARTS[@]::${#INPUT_FILENAME_PARTS[@]}-1}`; | |
# echo "INPUT_FILENAME_NO_EXT: $INPUT_FILENAME_NO_EXT"; | |
OUTPUT_FILENAME="${INPUT_FILENAME_NO_EXT}.${outputFileType}"; | |
OUTPUT_PATTERN="$OUTPUT_DIR/$OUTPUT_FILENAME"; | |
echo -e "\e[;1mffmpeg -f image2 -start_number $_first_frame_number -i $INPUT_PATH $scaleParam $OUTPUT_PATTERN \e[0;31m\e[90m"; | |
ffmpeg -f image2 -start_number $_first_frame_number -i $INPUT_PATH $scaleParam $OUTPUT_PATTERN; | |
echo -e "\e[0m"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment