-
-
Save lyarinet/8550a93d2ca3d3d31efa54419e339e03 to your computer and use it in GitHub Desktop.
Outputs ffmpeg progress to console as percentage of work completed.
This file contains hidden or 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
# Get video duration in frames | |
duration=$(ffmpeg -i [filename] 2>&1 | sed -n "s/.* Duration: \([^,]*\), start: .*/\1/p") | |
fps=$(ffmpeg -i [filename] 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p") | |
hours=$(echo $duration | cut -d":" -f1) | |
minutes=$(echo $duration | cut -d":" -f2) | |
seconds=$(echo $duration | cut -d":" -f3) | |
FRAMES=$(echo "($hours*3600+$minutes*60+$seconds)*$fps" | bc | cut -d"." -f1) | |
# Start ffmpeg, use awk to flush the buffer and remove carriage returns | |
ffmpeg -i [filename] [options] [outputfile] 2>&1 | awk '1;{fflush()}' RS='\r\n'>[errorlog] & | |
# Get ffmpeg Process ID | |
PID=$( ps -ef | grep "ffmpeg" | grep -v "grep" | awk '{print $2}' ) | |
# While ffmpeg runs, process the log file for the current frame, display percentage progress | |
while ps -p $PID>/dev/null ; do | |
currentframe=$(tail -n 1 [errorlog] | awk '/frame=/ { print $2 }') | |
if [[ -n "$currentframe" ]]; then | |
PROG=$(echo "scale=3; ($currentframe/$FRAMES)*100.0" | bc) | |
echo PROGRESS: $PROG | |
sleep 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment