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