Fix race condition in transcode script

Protect logrotation with a lock to avoid a race when multiple
transcoders are running simultaneously.
Additionally the size check was moved to its own test block so it only
runs if the logfile actually exists.