Skip to content

Instantly share code, notes, and snippets.

@csiknor
Last active October 4, 2015 18:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save csiknor/ad9d9db0f0f2cb9767a6 to your computer and use it in GitHub Desktop.
Save csiknor/ad9d9db0f0f2cb9767a6 to your computer and use it in GitHub Desktop.
Copies the video streams and the Hungarian DTS or AC3 audio streams to a new file using ffmpeg. The DLNA client of my WebOS LG TV doesn't support audio stream switching and picks audio streams randomly which isn't fun.
# 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