This is cherrypicked from libav commit 721bc37522. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
721bc37522