Skip to content

Instantly share code, notes, and snippets.

@aa989190f363e46d
Forked from csiknor/convert_dlna_ready_mkv
Last active August 29, 2015 14:11
Show Gist options
  • Save aa989190f363e46d/26c83250bd7a69e3c6cf to your computer and use it in GitHub Desktop.
Save aa989190f363e46d/26c83250bd7a69e3c6cf to your computer and use it in GitHub Desktop.
# Usage: find Harry.Potter.* -name *.mkv -exec convert_dlna_ready_mkv {} ";"
echo "Processing file: $1"
FFMPEG_INFO_FILE='ffmpeg-info'
OUTPUT_FILE=`echo "$1" | sed 's/\(.*\)\.mkv$/\1-lo.mkv/'`
ffmpeg -i "$1" 2>$FFMPEG_INFO_FILE
AUDIO_STREAM=`egrep "Stream #(\d:\d).*hun.*Audio: dts" $FFMPEG_INFO_FILE | sed 's/.*Stream #\([0-9]:[0-9]\).*/\1/'`
if [ -z $AUDIO_STREAM ]
then
AUDIO_STREAM=`egrep "Stream #(\d:\d).*hun.*Audio: ac3" $FFMPEG_INFO_FILE | sed 's/.*Stream #\([0-9]:[0-9]\).*/\1/'`
if [ -z $AUDIO_STREAM ]
then
echo 'Neither DTS nor AC3 hungarian audio stream found.'
else
echo "AC3 hungarian audio stream found: $AUDIO_STREAM"
fi
else
echo "DTS hungarian audio stream found: $AUDIO_STREAM"
fi
VIDEO_STREAM=`egrep "Stream.*Video" $FFMPEG_INFO_FILE | sed 's/.*Stream #\([0-9]:[0-9]\).*/\1/'`
if [ -z $VIDEO_STREAM ]
then
echo 'No video stream found.'
else
echo "Video stream found: $VIDEO_STREAM"
fi
if [ $AUDIO_STREAM -a $VIDEO_STREAM ]
then
FFMPEG_COPY_CMD="ffmpeg -i \"$1\" -map $VIDEO_STREAM -map $AUDIO_STREAM -acodec copy -vcodec copy \"$OUTPUT_FILE\""
echo "Executing command '$FFMPEG_COPY_CMD'"
$FFMPEG_COPY_CMD
else
echo "Nothing to execute."
fi
rm $FFMPEG_INFO_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment