This is cherrypicked from libav commit 3933b86bb9. Signed-off-by: Martin Storsjö <martin@martin.st>
3933b86bb9