Georg Lippold
 

Importing, sorting and converting videos from your camcorder

Not Rated YetNot Rated YetNot Rated YetNot Rated YetNot Rated Yet0votes
January 17, 2010 07:54 AM  Views: 3616   Favorited: 0 Favorite It Comments: 0
Filed Under:  avi, ffmpeg, h264, linux, mts, x264
Tags:  avi, camcorder, ffmpeg, import, linux, mts, script, x264
 
You know the problem: once the HDD of your camcorder has run full, it is messy to sort all the videos out and convert them into the correct format. But never surrender to chaos! There is hope... A litte shell script that automatically copies, sorts and converts (with my mts2avi.sh script from my other tutorial) is here to help you:
 
#!/bin/bash
# Define the convert script (from MTS to AVI or MP4 or whatever) here
CONVERTSCRIPT=$HOME/bin/mts2flash.sh
if [ -z "$1" ] ; then
  # For the lazy... define your camera's default mountpoint here
  MOUNTPOINT="/media/CANON"
else
  # otherwise specify manually at each invokation
  MOUNTPOINT="$1"
fi
# Directory on the camera where MTS files are
DIR="/AVCHD/BDMV/STREAM"
# Directory where you want to store the MTS files and the converted results
COPYTO="/Media/MTS"
# $MOUNTPOINT must currently be mounted manually or must be entered in
# /etc/fstab
# or on Ubuntu it "just works" without mounting manually
# mount ${MOUNTPOINT}
 
######## DO NOT MODIFY SCRIPT BELOW ########
declare -a FILES
FILECOUNTER=0
for i in `find ${MOUNTPOINT}${DIR}/ -type f` ; do
  DATETAG="`stat $i -c %y | cut -d " " -f 1`"
  YEAR="`echo $DATETAG | cut -d "-" -f 1`"
#  YEAR="`find $i -printf "%TY"`"
#  MONTH="`find $i -printf "%Tm"`"
#  DAY="`find $i -printf "%Td"`"
  DESTDIR="${COPYTO}/${YEAR}/$DATETAG"
  FILES[${FILECOUNTER}]="${DESTDIR}/`basename ${i}`"
  echo ${FILES[${FILECOUNTER}]}
  FILECOUNTER=$(( ${FILECOUNTER} + 1))
  mkdir -p ${DESTDIR}
  cp -a $i ${DESTDIR}
done
echo "You can remove the camera now..."
echo "Encoding files..."
ENCODECOUNTER=0
declare -a ENCODEFILES
ENCODEFILECOUNTER=0
while [ ${ENCODECOUNTER} -lt ${FILECOUNTER} ] ; do
  FILE=${FILES[${ENCODECOUNTER}]}
  ENCODECOUNTER=$(( $ENCODECOUNTER + 1 ))
  if [ `du -sm $FILE | cut -f 1` -ge 1950 ] ; then
    # recording session consists of multiple files
    ENCODEFILES[${ENCODEFILECOUNTER}]=${FILE}
    ENCODEFILECOUNTER=$(( ${ENCODEFILECOUNTER} + 1 ))
    echo "large file detected"
    continue;
  else
    ENCODEFILES[${ENCODEFILECOUNTER}]=${FILE}
  fi
  echo "now encoding ${#ENCODEFILES[@]} files"
  EXECFILE=`mktemp /tmp/mts-import.XXXXXX` || exit 1
  echo -e "#!/bin/bash\n${CONVERTSCRIPT} \\" > ${EXECFILE}
  ENCODEFILECOUNTER=0
  while [ ${ENCODEFILECOUNTER} -lt ${#ENCODEFILES[@]} ] ; do
    echo "${ENCODEFILES[${ENCODEFILECOUNTER}]} \\" >> ${EXECFILE}
    ENCODEFILECOUNTER=$(( ${ENCODEFILECOUNTER} + 1 ))
  done
  echo >> ${EXECFILE}
  chmod +x ${EXECFILE}
  DIR=`dirname ${FILE}`
  cd $DIR
  ${EXECFILE}
  rm -f ${EXECFILE}
  ENCODEFILECOUNTER=0
  unset ENCODEFILES
done
 
As always, feel free to save the script in $HOME/bin and call it something like mts-import.sh. Then make it executable (chmod +x mts-import.sh) and check it out... You may have to modify the variables MOUNTPOINT, COPYTO and DIR to your actual camcorder and system setup, but only change it before the "Do not modify" part ;)

Comments





Leave A Comment

Data Entry Error
First Name:  Last Name: 
Title:
Comment: Required Information
  Required InformationIndicates Required Information
Georg Lippold
Brsibane, QLD,
Australia
Member Bio Member Skills/Specialization

Bio

close

Specializations

close
 
Privacy Policy | Terms Of Service | Contact Us | Support | Help/FAQ | News