Do not re-call avcodec_get_context_defaults3(), it is already
called by avformat_new_stream() and it leaks the codec
priv_data that was already allocated.
Use avformat_free_context() instead of freeing (not)
everything manually.
Fix trac ticket #2322.