Last active
May 8, 2019 16:38
-
-
Save ammmze/59fab84a816af1f88c4e4b3ca6710837 to your computer and use it in GitHub Desktop.
Video File to DVD ISO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# AVI to DVD Script | |
# Ben Dowling - www.coderholic.com | |
# Change to "ntsc" if you'd like to create NTSC disks | |
format=${VIDEO_FORMAT:-ntsc} | |
output_file=./dvd.iso | |
burn=false | |
burn_dev=/dev/cdrom | |
titles=() | |
while [[ "$#" > 0 ]]; do | |
key="$1" | |
shift | |
case ${key} in | |
--format|-f) | |
format="$1" | |
shift | |
;; | |
--verbose|-v) | |
verbose=true | |
;; | |
--burn|-b) | |
burn=true | |
if [[ -e "$1" && `wodim dev=$1 -checkdrive` ]]; then | |
burn_dev="$1" | |
shift | |
fi | |
;; | |
--help|-h) | |
exit 0 | |
;; | |
--output|-f) | |
output_file="$1" | |
shift | |
;; | |
*) | |
titles+=("$key") | |
if [ ! -e "$key" ]; then | |
echo "File '$key' not found" | |
exit 1 | |
fi | |
;; | |
esac | |
done | |
# Check we have enough command line arguments | |
if [ "${#titles[@]}" -lt 1 ]; then | |
echo "Usage: $0 input_file... [output_file]" | |
exit | |
fi | |
# Check for dependencies | |
missing=0 | |
dependencies=( "mencoder" "ffmpeg" "dvdauthor" "mkisofs" ) | |
for command in ${dependencies[@]}; do | |
if ! command -v $command &>/dev/null; then | |
echo "$command not found" | |
missing=1 | |
fi | |
done | |
if [ $missing = 1 ]; then | |
echo "Please install the missing applications and try again" | |
exit | |
fi | |
function emphasise() { | |
echo "" | |
echo "********** $1 **********" | |
echo "" | |
} | |
counter=0 | |
first=0 | |
for input_file in "${titles[@]}"; do | |
let counter=counter+1 | |
# Check the file exists | |
if [ ! -e "$input_file" ]; then | |
echo "Input file '${input_file}' not found" | |
exit | |
fi | |
emphasise "Converting '${input_file}' to MPG" | |
ffmpeg -i "${input_file}" -y -target ${format}-dvd -qscale 0 -aspect 16:9 finalmovie.mpg | |
if [ $? != 0 ] || [ ! -e finalmovie.mpg ]; then | |
emphasise "Conversion failed" | |
exit | |
fi | |
emphasise "Creating DVD contents" | |
dvdauthor --title -o dvd -f finalmovie.mpg | |
let first=first+$? | |
done | |
VIDEO_FORMAT="${format}" dvdauthor -o dvd -T | |
second=$? | |
if [ $first != 0 ] || [ $second != 0 ]; then | |
emphasise "DVD Creation failed" | |
exit | |
fi | |
emphasise "Creating ISO image" | |
mkisofs -dvd-video -o "${output_file}" dvd/ | |
if [ $? != 0 ]; then | |
emphasise "ISO Creation failed" | |
exit | |
fi | |
# Everything passed. Cleanup | |
rm -f finalmovie.mpg | |
rm -rf dvd/ | |
emphasise "Success: ${output_file} image created" | |
if [ "$burn" = true ]; then | |
response=y | |
else | |
read -r -p "Would you like to burn the iso to ${burn_dev}? [y/N] " response | |
response=${response,,} # tolower | |
fi | |
if [[ $response =~ ^(yes|y)$ ]]; then | |
growisofs -dvd-compat -Z "${burn_dev}=${output_file}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment