Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #####################################################################################################################
- # ffprogress v1.12 - turns ffmpeg output into a simple progress bar #
- # Handshake: #
- # $FF_LOG contains the path & name of the log file (default: "/media/ramdisk/log") #
- # $FF_CMD contains the path & name of the script with the ffmpeg command line (default: "/media/ramdisk/cmd") #
- # $FF_INPARAMS contains the input parameters (default: none) #
- # $FF_INPUT contains the input path and file name (default: none) #
- # $FF_OUTPUT contains the output path and file name (default: "/dev/null") #
- # $FF_ARGS contains additional arguments passed to ffmpeg (default: none) #
- # The input file name is mandatory, output is optional. FF_ARGS must contain the remaining ffmpeg command line. #
- #####################################################################################################################
- . progress.sh
- FF_LOG=/media/ramdisk/log_$(date +%y%m%d%H%M%S%3N)
- FF_CMD=/media/ramdisk/cmd_$(date +%y%m%d%H%M%S%3N)
- FF_OUTPUT=/dev/null
- FF_TIME_PAST=0
- PROGRESS_R1=" "
- PROGRESS_FT=S
- PROGRESS_TC=5
- FF_PROGRESS(){
- if [ -z "$FF_INPUT" -o ! -e "$FF_INPUT" ]; then
- FF_ERROR="wrong input path or file name."
- return 1
- elif [ "$FF_OUTPUT" != /dev/null -a -e "$FF_OUTPUT" ]; then
- read -r -p "Output file already exists. Overwrite (y/N)? " OPT
- case $OPT in
- y|Y)
- FF_ARGS="$FF_ARGS -y"
- ;;
- *)
- FF_ERROR="output flile already exists and won't be replaced."
- return 1
- ;;
- esac
- fi
- printf "Starting ffmpeg...\r"
- echo "ffmpeg $FF_INPARAMS -i \"$FF_INPUT\" $FF_ARGS \"$FF_OUTPUT\" 2>> $FF_LOG" > $FF_CMD
- chmod +x $FF_CMD
- $FF_CMD &
- while ! grep -qs Duration $FF_LOG; do sleep 0.2s; done
- PROGRESS_MAX1=$(grep "Duration:" $FF_LOG | awk -F '[:.]' '{print ($2*3600)+($3*60)+$4}')
- [ -n "$VIDEO_LIMIT" ] && PROGRESS_MAX1=$(($VIDEO_LIMIT*100/$(grep -m1 " fps," $FF_LOG | awk -F " fps," '{print $1}' | awk -F "[, .]" '{print $(NF-1)$NF}')))
- grep "Duration:" $FF_LOG | awk -F '[, ]' '{printf $3" "$4}'
- printf " Processing $PROGRESS_MAX1 seconds of the video...\n"
- while [ -n "$(ps -e | grep ffmpeg)" ]; do
- FF_TIME_CUR=$(grep -Eo 'time=[0-9]+:[0-9]+:[0-9]+' $FF_LOG | tail -n1 | awk -F '[=:]' '{print ($2*3600)+($3*60)+$4}')
- if [ -n "$FF_TIME_CUR" ] && [ $FF_TIME_CUR -ne $FF_TIME_PAST ]; then
- PROGRESS_BAR $FF_TIME_CUR
- sleep 0.1s
- FF_TIME_PAST=$FF_TIME_CUR
- fi
- done
- PROGRESS_BAR $PROGRESS_MAX1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement