Skip to content

Instantly share code, notes, and snippets.

@whoo
Forked from pruperting/ffmpeg-progress.sh
Last active March 25, 2020 18:32
Show Gist options
  • Save whoo/64cad8a85d24a66e263e to your computer and use it in GitHub Desktop.
Save whoo/64cad8a85d24a66e263e to your computer and use it in GitHub Desktop.
#!/bin/bash
#updated ffmpeg progress indicator
#by Rupert Plumridge
#for updates visit www.prupert.co.uk
#Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales Licence
# Based on the ffmpegprogress bar from: http://handybashscripts.blogspot.com/2011/01/ffmpeg-with-progress-bar-re-work.html
# which was based on my initital progress script - circle of life and all that ;)
# version 2.0
# 07.04.2011
# now uses apparently better progress detection, based on duration of overall video and progress along the conversion
####################################################################################
# USAGE #
# 1) Run the script with the name of the file to be converted after the name of the script
# (e.g. ./ffmpeg-progress.sh "My Awesome Video.mpg)
# 2) Pipe to zenity to show progress
# (e.g ./ffmpeg-progress.sh video.mpg | zenity --auto-close --time-remaining --progress
###################################################################################
# Please adjust the following variables as needed.
# It is recommended you at least adjust the first variable, the name of the script
display()
{
FR_CNT=0
while [ -e /proc/$PID ]; do
sleep 2
VSTATS=$(awk '{gsub(/frame=/, "")}/./{line=$1-1} END{print line}' /tmp/vstats)
if [ $VSTATS -gt $FR_CNT ]
then
FR_CNT=$VSTATS
PER=$(( 100 * FR_CNT / frame ))
echo -e "$PER\n#$NAME $FR_CNT / $frame ($PER%)"
fi
done
}
trap "killall ffmpeg ; rm -f "/tmp/vstats*"; exit" INT TERM EXIT
getinfo(){
eval $(ffprobe -v error -select_streams v:0 -of flat=s=_ -show_entries stream=height,width,avg_frame_rate -show_entries format=duration "$FILE")
if [ ${streams_stream_0_width} -gt 1024 ]
then
H=$(echo "${streams_stream_0_height} * 1024 / ${streams_stream_0_width}" | bc)
size="1024x${H}"
else
size=${streams_stream_0_width}x${streams_stream_0_height}
fi
frame=$(echo "${streams_stream_0_avg_frame_rate} * ${format_duration}" | bc)
frame=${frame/.*}
OPT="-s $size -f mp4 -vstats_file /tmp/vstats -profile:v high -c:v libx264 -c:a libfdk_aac -b:a ${ABR}k -b:v ${VBR}k"
}
##### Main
#init global variable
FILE=$1
OPT=""
frame=""
VBR=579
ABR=128
OUT=outfile.mp4
getinfo
ffmpeg -i "${FILE}" ${OPT} "$OUT" 2>/dev/null &
PID=$!
display
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment