Updated to attempt repackaging the MKV if initial M2TS creation fails and some extra code modularisation cleanup.