[mythtv-users] Lossless remux ISO to MKV for .22 video storage groups
Joel Means
means.joel at gmail.com
Wed Oct 21 22:00:08 UTC 2009
Also, I made a script to convert one of these mkv's back to an iso in
case I want to burn it to DVD later. Just in case anyone else wants
it. If you copy and paste this, you may need to go wherever you see a
"^M" and delete that and replace it by typing ^V^M (with ^ meaning
CTRL, not SHIFT+6) to get the proper character in there (I am not sure
if those will copy and paste correctly). For some reason, mediainfo
insists on making DOS output on Linux.
Joel
---------------------------------------------------------------------------------------
#!/bin/bash
if [ "${1}" = "" ]; then
echo "You must provide a mkv file as an input file"
exit 1
fi
if [ ! "`echo ${1} | grep -o ".mkv"`" = ".mkv" ]; then
echo "You must provide a mkv file as an input file"
exit 1
fi
## Set some parameters
MOVIEFILE=$1
TITLE=`basename ${MOVIEFILE} .mkv`
MKVEXTRACT="/usr/bin/mkvextract"
MPLEX="/usr/bin/mplex"
DIR=${PWD}
## We want the full path to the movie file
MOVIEFILE=${DIR}/${MOVIEFILE}
## Get us a working directory
TEMPDIR=`mktemp -d`
pushd ${TEMPDIR}
## Get info on tracks within the mkv
## Main video track (only one is handled)
VIDEO_TRACK=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 1
"Video" | grep "^ID" | cut -d':' -f2 | sed 's/ //'`
## Audio Tracks
NUM_AUDIO_TRACKS=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 1
"Audio" | grep "^ID" | wc -l`
for i in `seq 1 ${NUM_AUDIO_TRACKS}`; do
AUDIO_TRACKS[${i}]=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A
1 "Audio" | grep "^ID " | cut -d':' -f2 | sed 's/^ //' | tr '\n' ' ' |
awk '{ print $'"${i}"' }'`
AUDIO_TYPE[${i}]=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 2
"Audio" | grep "^Format " | cut -d':' -f2 | sed 's/^ //' | tr '\n' ' '
| awk '{ print $'"${i}"' }'`
done
## Subtitle Tracks
NUM_SUB_TRACKS=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 1
"Text" | grep "^ID" | wc -l`
for i in `seq 1 ${NUM_SUB_TRACKS}`; do
SUB_TRACKS[${i}]=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 1
"Text" | grep "^ID " | cut -d':' -f2 | sed 's/^ //' | tr '\n' ' ' |
awk '{ print $'"${i}"' }'`
SUB_TYPE[${i}]=`mediainfo ${MOVIEFILE} | sed 's/^M//g' | grep -A 2
"Text" | grep "^Format " | cut -d':' -f2 | sed 's/^ //' | tr '\n' ' '
| awk '{ print $'"${i}"' }'`
done
## Setup the options passed to mkvextract and mplex
EXTRACT_OPTS="1:${TITLE}.m2v"
MPLEX_OPTS="${TITLE}.m2v"
for i in `seq 1 ${NUM_AUDIO_TRACKS}`; do
EXTRACT_OPTS="${EXTRACT_OPTS} ${AUDIO_TRACKS[${i}]}:"
if [ "${AUDIO_TYPE[${i}]}" = "AC-3" ]; then
EXTRACT_OPTS="${EXTRACT_OPTS}${TITLE}.${i}.ac3"
MPLEX_OPTS="${MPLEX_OPTS} ${TITLE}.${i}.ac3"
else if [ "${AUDIO_TYPE[${i}]}" = "DTS" ]; then
EXTRACT_OPTS="${EXTRACT_OPTS}${TITLE}.${i}.dts"
MPLEX_OPTS="${MPLEX_OPTS} ${TITLE}.${i}.dts"
fi fi
done
## Extract chapters and format them for dvdauthor
${MKVEXTRACT} chapters ${MOVIEFILE} -s > ${TITLE}.txt
xchap2author.sh ${TITLE}.txt
## Extract the video and audio tracks
${MKVEXTRACT} tracks ${MOVIEFILE} ${EXTRACT_OPTS}
## Put them together in a format acceptable to dvdauthor
${MPLEX} -f8 -o ${TITLE}.mpg ${MPLEX_OPTS}
## Grab the subtitles (only VobSub handeled currently)
for i in `seq 1 ${NUM_SUB_TRACKS}`; do
OPTS_SUBS="${SUB_TRACKS[${i}]}:"
if [ "${SUB_TYPE[${i}]}" = "VobSub" ]; then
OPTS_SUBS="${OPTS_SUBS}${TITLE}.sub"
fi
## Extract the subtitles
${MKVEXTRACT} tracks ${MOVIEFILE} ${OPTS_SUBS}
## Add them to the video
if [ -e ${TITLE}.sub ]; then
mkdir subs
pushd subs
spuunmux -s0 -o ${TITLE} ../${TITLE}.sub
spumux ${TITLE}.xml < ../${TITLE}.mpg > ../${TITLE}_subs.mpg
popd
mv ${TITLE}_subs.mpg ${TITLE}.mpg
fi
done
## Create the xml file for dvdauthor
if [ -e ${TITLE}.xml ]; then rm ${TITLE}.xml; fi
cat << EOF >> ${TITLE}.xml
<dvdauthor>
<vmgm />
<titleset>
<titles>
<pgc>
<vob file="${TITLE}.mpg" chapters="`cat ${TITLE}.txt`" />
</pgc>
</titles>
</titleset>
</dvdauthor>
EOF
## Now author the dvd and create the iso
dvdauthor -o ${TITLE} -x ${TITLE}.xml
mkisofs -dvd-video -o ${DIR}/${TITLE}.iso ${TITLE}
## Get out of and remove the temp directory
popd
rm -rf ${TEMPDIR}
More information about the mythtv-users
mailing list