Quoted from Peter Jackson’s public Facebook page in Go Into the Story:
We always find there are three distinct phases in the life of a film script. First, it exists before the film starts shooting. In this period, which can last from months to years, the script is a theoretical document—an imaginative version of the movie.
Then you start shooting and things come much more into focus—usually in a very positive way. We now have actors who bring their skill to the roles and suddenly we see the characters in a more vivid and tangible way. This is both fun and satisfying, and always inspires us to embark on constant script revisions to meet the renewed potential these characters now have. I feel that much of the best writing happens during this period, but it does make a very busy time—very, very busy! Sometimes we have gotten these revisions to the actors a little late. We constantly joke to Ian McKellen that tomorrow’s script pages will be slid under his door sometime the night before… and sometimes that has been true.
The worst case of this came during The Fellowship of the Ring, when we revised Boromir’s long speech about Mordor at the last minute and only got it to Sean Bean on the day it was being shot. Sean handled it very cleverly—if you look at the movie, you’ll see he occasionally has his head bowed, as if dealing with the emotional weight of the horrors of Mordor. In actual fact, the new script page had been taped to his knee! By the time we were done with several takes and a few different camera angles, Sean had the speech down pat, and it was mainly those takes that were used in the final cut.
The final writing phase comes in post-production, when you edit the movie. No matter what you were imagining when you wrote the script, and what you imagined during the shoot, nothing now matters beyond the actual cut film. We often find that script work continues during post, including writing and shooting new scenes, reorganising the order of scenes, or recording additional dialogue to slip into shots. We do all of these things, and the writing only stops when the film is finally finished.