Refactored TextureBuffer image loading and FFmpeg C code

Fixed memory leak