Monday, August 12, 2019

Batch Conversion of .MOV files to .MP4 using VLC and ffmpeg

Here's How I Convert Apple Quicktime .MOV Video to .MP4


Convert it using MSDOS Batch Scripting and VLC player


for %%a in (*.mov) do cmd /c "C:\program files (x86)\VideoLan\VLC\vlc.exe" ^
-I dummy -vvv %%a ^
--stop-time=60 ^
--sout=#transcode{vcodec=h264,vb=7000,fps=25.000,size=4:3,width=722,height=578,^
vfilter=croppadd{croptop=2,cropbottom=0,cropleft=2,cropright=0,paddright=0},^
acodec=mp4a,ab=128,channels=2,samplerate=44100,deinterlace}^
:standard{access=file,mux=mp4,dst=%%~na.mp4} ^
vlc://quit
Here's another one that works for me

for %%a in (*.mov) do "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" -I dummy -vvv %%a --sout=#transcode{vcodec=h264,vb=7000,acodec=mp3,ab=128,channels=4,deinterlace}:standard{access=file,mux=ts,dst=%%a.mp4} vlc://quit

Convert it using ffmpeg on Ubuntu 14.4 and Bourne Shell Scripting

First you need to install ffmpeg onto your ubuntu desktop.
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
and
sudo apt-get update
sudo apt-get install ffmpeg
then use this cool bash script to automagically convert everything using the find command and some cool sed commands.  Sed is used to replace spaces in the directories and filenames.


#! /bin/bash

##
## ALLMOVFILES=`find ./ -name "clip*.mov" -exec /bin/sed -e 's/\ /%20/g' '{}' ';'`
## ALLMOVFILES=`find ./ -name "clip*.mov" -exec echo '{}' | /bin/sed -e 's/\ /%20/g' ';'`
OUTDIR="./H264-Video"
ALLMOVFILES=`find ./ -name "MVI*.MOV" -exec echo '{}' ';' | /bin/sed -e 's/\ /%20/g'`

for INFILE in ${ALLMOVFILES}
do
   echo $INFILE

   FILENAME=`echo ${INFILE} | nawk -F "/" 'BEGIN { FS="/"; } {  print $NF; }'`
   DIRS=`echo ${INFILE} | nawk -F "/" 'BEGIN { FS="/"; } { for (i=1;i<NF;i++) { print $i;} }'`
   echo "Split with awk: " $DIRS
   for dir in $DIRS
   do
      echo "dir:" $dir
   done
   echo "file:" $FILENAME
   ofile=`echo $FILENAME | /bin/sed -e 's/%20/\ /g'`
   ifile=`echo $INFILE | /bin/sed -e 's/%20/\ /g'`
   ofile=`echo $ofile | /bin/sed -e 's/MOV/mp4/g'`

   echo $ifile
   echo $ofile

   ffmpeg -i "${ifile}" -vcodec h264 -acodec aac -strict experimental -ab 128k -b:v 1024k -bufsize 1024k -r 20 "${OUTDIR}/${ofile}"

done

Finally, this script will read the original date and time from the source QT file, and then apply it to the new H264 video file.

#! /bin/bash

##
## ALLMOVFILES=`find ./ -name "clip*.mov" -exec /bin/sed -e 's/\ /%20/g' '{}' ';'`
## ALLMOVFILES=`find ./ -name "clip*.mov" -exec echo '{}' | /bin/sed -e 's/\ /%20/g' ';'`
OUTDIR="./H264-Video"
ALLMOVFILES=`find ./ -name "MVI*.MOV" -exec echo '{}' ';' | /bin/sed -e 's/\ /%20/g'`

for INFILE in ${ALLMOVFILES}
do
   echo $INFILE

   FILENAME=`echo ${INFILE} | nawk -F "/" 'BEGIN { FS="/"; } {  print $NF; }'`
   DIRS=`echo ${INFILE} | nawk -F "/" 'BEGIN { FS="/"; } { for (i=1;i<NF;i++) { print $i;} }'`
   echo "Split with awk: " $DIRS
   for dir in $DIRS
   do
      echo "dir:" $dir
   done
   echo "file:" $FILENAME
   ofile=`echo $FILENAME | /bin/sed -e 's/%20/\ /g'`
   ifile=`echo $INFILE | /bin/sed -e 's/%20/\ /g'`
   ofile=`echo $ofile | /bin/sed -e 's/MOV/mp4/g'`

   echo $ifile
   echo $ofile

   ## ffmpeg -i "${ifile}" -vcodec h264 -acodec aac -strict experimental -ab 128k -b:v 1024k -bufsize 1024k -r 24 "${OUTDIR}/${ofile}"

   let ix=1;
   timestamp=""
   timevals=`stat --format "%y" "${ifile}" | sed 's/[-:.]/ /g'`
   for tt in $timevals
   do
      if [ $ix -le 5 ]; then
         timestamp=${timestamp}${tt}
      fi
      if [ $ix -eq 6 ]; then
         timestamp=${timestamp}.${tt}
      fi
      let ix="ix+1"
   done
   echo $timestamp

  echo "${OUTDIR}/${ofile}"
  touch -a -m -t ${timestamp} "${OUTDIR}/${ofile}"


done

Once you apply these timestamps, you can upload them to Apple iCloud.

read more.


No comments:

Post a Comment