Sunday, October 6, 2019

How to Convert Apple QuickTime .MOV files to H264 on Ubuntu command line like a boss

Convert Your Bloated Apple QuickTime .MOV videos to H264 .MP4 with ffmpeg

Everybody knows that Apple QuickTime is an outdated and bloated video format that requires extra codecs to play on Windows 7 and 10, plus you need Apple Itunes or Apple QuickTime to play it back.  On Windows 7 and 10, you also need VLC media player or the codec pack to play it back with Windows Media player.  It's so bloated that a 3 minute video can easily fill up 1 GB of disk space.  Plus native QuickTime can easily fill up your icloud account.  Furthermore, it's an outdated format that will soon be obsolete. So, convert the videos to H264 video to compress down to 1/10 the file size and be playable on Windows Media Player and be ready for upload to YouTube.  Compress it and reduce the frame rate with ffmpeg to reduce the file size by 95% or more.

First thing you need is Ubuntu 14 to 16+ LTS running on a decent core i7 machine with at least 4 cores. Then once you get that, you need to use apt to install ffmpeg. 

Install the reposisitory and then install ffmpeg using these 3 commands.

sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get update
sudo apt-get install ffmpeg
Some basic things that you do:

Reduce .mov File Size:
ffmpeg -i in.mov -c:v libx264 -c:a copy -crf 20 out.mov
Convert .mov To .mp4
ffmpeg -i in.mov -vcodec h264 -acodec aac -strict experimental -ab 128k out.mp4

Convert a Lot of Files using this bash shell script
#! /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 "clip*.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 "${OUTDIR}/${ofile}"

done
Here's the same things with pretty code

#! /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 "clip*.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 "${OUTDIR}/${ofile}"

done

You can read more at:
https://tecadmin.net/install-ffmpeg-on-linux/

There are other command line apps to do the same thing. For example: avconv, vlc, and mencoder.  However, none of them can stand up to ffmpeg when it comes to QuickTime Video.

No comments:

Post a Comment