cli: Handle SIGINT and SIGTERM more gracefully
Attempt to finish writing the current frame before exiting to avoid ending up with a partially written frame at the end of the output file.
Only try catching a signal once, falling back to the default behavior of exiting immediately the second time a given signal is raised.