This has been discussed before, try to find the old thread (I can't remember if anyone cooked up a real script for this).
In short, this is possible but not reliable for shooting car crashes because it's very likely that the camera will lose power during the crash (or when parking, actually, unless you build smarter power handling for the camera). Loss of power means the camera will fail to save the video file properly, possibly losing or corrupting the entire file or the entire filesystem on the SD card. A DIY computer forensics sort of a person may be able to retrieve the video data of interest, though.
it is possible to write a Lua script that will shoot video for a given time, stop, delete an older one and restart. If you shoot reasonably long videos, those pauses are not excessively likely to happen during a crash. It is also possible to set any script autostart at camera power-on, and it is possible to have the camera startup upon rise of external power by mechanically forcing the power button down permanently or (the better choice) rewiring it to external electronics.
But basically... to make sure your SD card filesystem won't get corrupted (even during normal car crash free use), you need to build external power electronics to buffer some energy for your camera power supply and e.g. use the USB remote trigger to start and stop to signal the script to stop video record and power off whenever car 12 V voltage is lost (and to not start until you have enough energy buffered for a safe startup + shutdown sequence).