Based on libcaption: https://github.com/szatmary/libcaption commit e8b6261090eb3f2012427cc6b151c923f82453db