Fix incorrect usage of av_realloc (undefined behaviour), use posix_memalign and memcpy instead.