#!/bin/bash
## mffpeger -- filter a video file in mencoder, then convert it's format in ffmpeg.
##
## mffpeger4 uses mencoder's "filmdint" filter to remove the pulldown on Canon 24P AVCHD files with the 3:2 
## cadence starting on the second interlaced frame (frame #4, as designated by the mencoder detc filter).
##
## Please send any modified versions of this script to me at h_munster@gmx.com.  Thanks,  -Dale

for i in *mts;
do

  ORIGINAL=`basename $i .mts`
  INTERMED=${ORIGINAL}.avi
  FINAL=${ORIGINAL}.mov

  ## Use mencoder to filter the original video file into an "almost raw" ffvhuff-avi file.
  mencoder $i -fps 60000/1001 -oac pcm -demuxer lavf -vf filmdint,softskip -ofps 24000/1001 -ovc lavc -lavcopts vcodec=ffvhuff:format=YV12:vstrict=-1:aspect=16/9 -o $INTERMED

  ## Convert to final file format in ffmpeg.
  ffmpeg -i $INTERMED -vcodec mpeg4 -b 35000k -f mov -acodec copy $FINAL

  ## Remove intermediate file after encoding the final file (keeps the current partition from filling up).
  rm -v $INTERMED

done
