Converting Videos for the iPhone 5s
Overview
This page describes how to use the free software HandBrake to convert video files into a format suitable for playing on the iPhone 5s and iPod Touch.
HandBrake comes in two versions:
- Graphical user interface version (HandBrake), suitable for converting a small number of video files manually
- Command line version (HandBrakeCLI) that is best suited for converting multiple files automatically via a Bash shell script.
Two Bash shell scrips are provided:
(a) General script for converting any videos into .mp4
(b) Specific script that only converts .mp4 files.
Introduction
Long before I purchased an Apple iPhone 5s, I knew that my favourite video container (MKV) was not directly supported on Apple hardware. While it is possible to install Apps that will play MKV video files I wanted to be able to use the iPhone's native media software. It was obvious that I would need to find a reliable and easy method to convert multiple video files into the correct video format for an iPhone.
A quick look at the Apple 5s technical specifications shows that the following video formats are supported by the iPhone 5s:
(i) H.264 video up to 1080p, 60 frames per second, High Profile level 4.2 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4 and .mov file formats;
(ii) MPEG-4 video up to 2.5 Mbps, 640x480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps per channel, 48kHz, stereo audio in .m4v, .mp4 and .mov file formats;
(iii) Motion JPEG (M-JPEG) up to 35 Mbps, 1280x720 pixels, 30 frames per second, audio in ulaw, PCM stereo audio in .avi file format
For space and quality reasons I chose the H.264 video codec, AAC audio codec and mp4 container specification. The key is that not all .mp4 files will play on an iPhone and so must be converted into the iPhone compatible mp4 format via HandBrake / HandBrakeCLI .
HandBrake / HandBrakeCLI provides a preset(--preset="iPhone & iPod touch") that converts videos into a suitable specification that will play on iPhone and iPod Touch devices. So it was simply question of using HandBrake's iPhone and iPod Touch preset.
(a) Bash Script for Converting any videos into iPhone .mp4 format
#!/bin/bash
clear
clear
echo "Start of $0"
echo
## This is to stop Bash breaking on Spaces and force it to break at the End of each Line.
IFS=$'\n'
count=0
# Change this input directory to suit you if you are not already in the source media directory.
# cd "/WinF/Inputs"
for i in *.*
do
echo "Starting $i"
echo
#j=$(basename $i .*)
j=${i%.*}
echo -e "$i WITHOUT original EXTENSION is \n$j"
echo
# See http://stackoverflow.com/questions/8467424/echo-new-line-in-bash-prints-literal-n for advice on adding newlines with echo -e
echo -e "New filename without old Extension is : \n$j"
echo
# Here we output the files into the directory /WinF/HandBrake-Output obviously change this to to suit you.
# Choose a HandBrakeCLI preset from
# HandBrakeCLI --preset-list
#HandBrakeCLI -i "$i" --preset="iPad" -o /WinF/HandBrake-Outputs/$j.mp4
HandBrakeCLI -i "$i" --preset="iPhone & iPod touch" -o /WinF/HandBrake-Outputs/$j.mp4
# Following example from
# ffmpeg -i "$i" -ab 256k "${i%m4a}mp3"
let count=$count+1
echo
echo "====================================================================================="
echo
echo "$i done"
echo "Files processed=$count"
sleep 10
echo
echo "====================================================================================="
echo
done
======================================================
(b) Bash Script for Converting .mp4 files into iPhone .mp4 format
#!/bin/bash
clear
clear
echo "Start of $0"
echo
## This is to stop Bash breaking on Spaces and force it to break at the End of each Line.
IFS=$'\n'
count=0
# Change this input directory to suit you.
cd "/WinF/Inputs"
for i in *.mp4
do
echo "Starting $i"
echo
j=$(basename $i .mp4)
echo -e "$i WITHOUT MP4 EXTENSION is \n$j"
echo
# See http://stackoverflow.com/questions/8467424/echo-new-line-in-bash-prints-literal-n for advice on adding newlines with echo -e
echo -e "New filename with MP4 extension removed is : \n$j"
echo
# Here we output the files into the directory /WinF/HandBrake-Output obviously change this to to suit you.
#HandBrakeCLI -i "$i" --preset="iPad" -o /WinF/HandBrake-Outputs/$j.mp4
HandBrakeCLI -i "$i" --preset="iPhone & iPod touch" -o /WinF/HandBrake-Outputs/$j.mp4
# Following example from
# ffmpeg -i "$i" -ab 256k "${i%m4a}mp3"
echo
echo "====================================================================================="
echo
echo "$i done"
echo "Files processed=$count"
let count=$count+1
sleep 10
echo
echo "====================================================================================="
echo
done
======================================================
HandBrake Downloads
HandBrakeCLI
HandBrake Guide
======================================================
======================================================
Further Reading
HandBrake Downloads
HandBrakeCLI
HandBrake Guide
======================================================
No comments:
Post a Comment