Following my previous post about iMovie and MTS I always had random trouble with my converter failing/hanging with some MTS files. And when repeated for the same file – no problems. This way I couldn’t just set the converter to work with tens of files and go for a coffee – I always had to look for hangs and stop the process only to restart it again.
And after I had problems with QuickTime refusing to open the new .mov files and iMovie having no sound, I thought it to be prime time to revisit the script.
A few times before I have imported my short clips from the Sony HDR-CX106 camcoder directly using iMovie camera import features. Now, that I had a bit longer videos on the camera, I got to thinking why it takes so long and how come it reports that 60 GB of my hard drive will fit only 1 hour or so full-quality video. It turns out that by importing, iMovie probably converts all the clips into HDV compliant format, thus MPEG2 and thus resulting in wasting my hard drive space.
I had a shell wrapper script to convert MTS files with FFmpeg, but somehow, when running on multiple files, only the very first one got converted.
Turns out that FFmpeg swallows the stdin from the bash script when it is run and therefore nothing remains in the stdin for the next iterations. To remedy this, I had to fake input to ffmpeg:
while read movie
echo "" | ffmpeg -i "$movie" -vcodec copy -acodec copy "$movie".mov
Without the echo command this would’ve ended after first iteration, regardless of the number of files in the input.
BTW, the above command is useful for turning MTS files into MOV files, while preserving the audio-video streams, for software that does not support MTS.