I noticed that a lot of the HD video content I find on the internet is usually a .mkv file. Unfortunately, the PS3 won't natively play these files, and reencoding HD video takes forever, but luckily we can convert to .mp4 with no quality loss and no video reencoding.
This script assumes you already have all the necessary tools for converting mkv files and dealing with aac audio. (gpac, unstripped libs, mkvtoolsnix)
Anyway, here's the script. It will convert all mkv's in the current folder and all subfolders to mp4's, deleting the mkv's and cleaning up all the temp stuff. It currently deletes the original mkv file, but if you don't want it to do that or you think I suck at writing scripts, just comment out the if statement and the rm -f line.
Let me know if you encounter any problems while using it.
Code:#!/bin/bash find . -type f | grep .mkv$ | while read file do directory=`dirname "$file"` title=`basename "$file" .mkv` AC3=`mkvinfo "$file" | grep AC3` #check if it's AC3 audio or DTS AAC=`mkvinfo "$file" | grep AAC` order=`mkvinfo "$file" | grep "Track type" | sed 's/.*://' | head -n 1 | tr -d " "` #check if the video track is first or the audio track if [ "$order" = "video" ]; then fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | head -n 1` #store the fps of the video track if [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".ac3 ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac # mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3 # faac -o "${title}".aac "${title}".wav elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac else mkvextract tracks "$file" 1:"${title}".264 2:"${title}".dts ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac fi else fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | tail -n 1` if [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".ac3 2:"${title}".264 ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac # mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3 # faac -o "${title}".aac "${title}".wav elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac else mkvextract tracks "$file" 1:"${title}".dts 2:"${title}".264 ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac fi fi MP4Box -new "${directory}/${title}".mp4 -add "${title}".264 -add "${title}".aac -fps $fps rm -f "$title".aac "$title".dts "$title".ac3 "$title".264 "${title}".wav if [ -f "${directory}/${title}".mp4 ]; then rm -f "$file" fi done



Adv Reply




Bookmarks