Fix a crash in the destructor of external output.

Two issues:

1. calling av_write_trailer() without having called avformat_write_header is a party foul
2. dereferencing audio_stream_/video_stream_ without checking for null is also a party foul.
Merge pull request #132 from jnoring/master

Fix a crash in the destructor of external output.