mpegvideo: Fix long standing race condition with frame threads

Since resolution change support this also was exploitable, which is
how it was found.

Fixes read after free and out of array reads.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
