1. A method of encoding video sequence, comprising: receiving an input video sequence containing pictures; receiving a resource budget for the sequence; and receiving a sequence cost function; and generating an optimal action sequence to produce an encoded version of the sequence to achieve a minimum sequence cost within the sequence resource budget, further comprising of generating an optimal permutation of the sequence of pictures and generating an optimal set of encoder parameters for each picture.