ogg/wav: throw an error if the output file could not be created

This fixes a SIGSEGV when fopen fails (e.g. the user does not have
permission to create the file).