Added RAII for AVPacket + fixed codex close issues

TODO: RAII for codex classes