Fixed some bugs, and fixed problems with libavcodec