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; wherein generating an optimal action sequence is performed by solving the optimization problem min a , π ⁢ f ⁡ ( a π ) ⁢ ⁢ subject ⁢ ⁢ to ⁢ ⁢ r ⁡ ( a π ) ≤ r 0 where a=(a 1 ,. .. , a n ) is the encoder action for the sequence, a i is the set of encoder parameters for the ith picture and N is the number of pictures in the sequence; π is a permutation of the picture indices 1,. .. , N, and a π =(a π(1) ,. .. , a π(N) ) is the action sequence for the permuted sequence of pictures; ƒ is the sequence cost function; r(r 1 ,. .. , r K ) is the vector of K resources required to encode the sequence with action a; and r 0 is the vector of budgeted resources; wherein the optimal permutation π* and optimal action sequence a* are found by performing the following steps Start: set best cost ρ* to infinity; For each candidate permutation π of the indices {1,. .. , N} perform Step 1: Verify whether π is an admissible permutation; If yes, continue to next step; otherwise, skip to next candidate permutation; Step 2: Find the optimal action sequence a and its cost ρ on the sequence of pictures π 1 ,. .. , π n ; Step 3: If ρ<ρ*, update a*=a,. .. , π*=π, and ρ*=ρ; End.