Fix malloc error when using ffmpeg multiple times