The idea is to end your movie when you do not need to add any additional input to reach the wnd of the game. Usually the end of the game would mean something like getting to the credits or whatever the equivalent would be.
So for example, the last input could mean something like mashing away a menu that pops up after completing the game (EX: in game dialogue, "level cleared" screen, etc"). Some games though end inputs even when still fighting the final boss. Some good examples of this are in these movies:
[3117] SNES Donkey Kong Country by Tompa in 07:50.08
[3261] SNES Donkey Kong Country 2: Diddy's Kong Quest by hidaigai, Comicalflop, Dooty & Umihoshi in 37:29.40
Notice how the characters stop moving around the end of the boss battle. That's because there's no reason to have any extra input. Now I'm not sure if this will be the case for a game you're probably doing, but it's something to keep in mind.
Finally, make sure there's no blank input frames at the end of your movie, TAS timing goes by the amount of frames a movie has, and blank frames can mess up what the final time is.
Hopefully this helps answer your question.