Hi Folks,
I've been trying out a few scripts (one I hacked myself) to convert hidef MKV files to MP4 containers. Specifically, the main issue I'm trying to solve is converting DTS -> AAC audio. I noticed the scripts I used before used ffmpeg. I tried NeroAacEnc and found the audio quality is much better. Unfortunately, I'm having issues with MP4Box accepting the audio NeroAacEnc creates. I also hit one other issue and that is making sure HxW size of video is in multiples of 16. I was trying to use ffmpeg pad filter for that but couldn't figure it out.
Does anyone have a working solution they can share?
Thanks so much!
+ Reply to Thread
Results 1 to 7 of 7
-
-
Thanks. I'm looking for 5.1 sound in the MP4, so don't think that will work. Also, the DTS MKVs need to be re-encoded to AAC. PS3 doesn't play DTS from MP4s, only AAC.
-
Thanks. I forgot to mention I'm on Mac OSX and/or Linux. I don't think either of the above will work. So far, I have a working script and the converted DTS audio sounds great. The only issue I think is making sure the height / width are multiples of 16. From what I understand, PS3 will only play video that has multiple of 16 for those parameters. I'd like to figure out how to use ffmpeg to reencode with the correct sizing.
-
I don't know what version they changed it but instead of -padtop and -cropleft, etc they have gone to "-vf pad=width:height:x:y:color" (substitute "crop" for "pad" if you want to crop). Default color is black, so you can leave that out. x and y tell ffmpeg where you want the pad or crop applied. If you set up a pad of 100 pixels on the width and you want the padding even on both sides, you would put in 50 for the x value (and set y to 0). If you wanted the padding off center, you could put more or less in the x field and it will put the remaining padding on the right. y works the same but represents the top of the image. Also, in the past crop was performed on the input video and pad on the output video, but now both operations take arguments regarding the output and not the input video. This makes for a bit of a headache when resizing and fixing the aspect ratio at the same time. If doing a pad operation you first have to resize the video to the new size but original aspect ratio (resize it to the width and height the corrected video would be if you cropped off the padding), and then put the final width and height you want into the -vf pad filter and ffmpeg will fill in the missing space with padding. This post has a pretty good explanation of how the new syntax works.
Edit: I may be wrong about the order of operations always being resize first and then the crop or pad. I'm reading that you can set up a filter chain to control this. I haven't tried this, but when I used -s to resize I found it did the resize first and then applied the crop or pad. Can anyone confirm this?
I hope this helps.Last edited by Mountain Man; 10th Feb 2011 at 12:25.
-
Thanks. I believe ffmpeg -crop / -pad re-encodes the video. Not good if you want to maintain original quality. I have a script that I will post below that works ok. It doesn't covert all videos, I think it's because of the H.264 encoding used in some of the newer MKVs isn't compatible with PS3. I wish I knew a way to detect the incompatibility and re-encode... Oh well, time to sell the PS3 for a media client that plays MKV.
Here is a script that converts MKVs to either MP4/AAC or M2TS/AC3 for playback on PS3. I used it and found the results pretty good, but some video doesn't play. Not sure why. I think PS3 is very limited on what video it can play.
One thing the script does is by default, when used $ mkvtomp4_new.sh blah.mkv, first check if pixel size is mod 16. If it is, the mkv is converted to mp4. If it isn't, mkv is converted to m2ts (which doesn't have the mod 16 limitation). The script prefers encoding to MP4/AAC because I find that AAC sounds much better then AC3 (at max bitrate 640k). NeroAacEnc does a excellent job I would say of creating AAC stream about 90% quality to the original WAV6/DTS stream.
This script depends on:
- tsMuxeR (download the mac version, open the package, the non gui exe works, place it in your path)
- NeroAacEnc (download from nero the "windows" version)
- gpac (MP4Box, you will need to check out the latest svn rev and compile it, there was a bug in gpac
source from a few weeks ago surrounding this script)
- wine (to runs windows nero aac enc, install "mac ports", then "sudo port install wine")
- mkvtools (for mkvextract etc... you can install this "sudo port install mkvtoolnix")
- dcadec (you will have to download the source and compile this yourself, it compiles though)
- faad ("sudo port install faad2")
- aften (this is the ac3 encoder it does a good job, you need to download and compile it yourself)
- python (you may need to install this "sudo port install python27")
- mplayer ("sudo port install mplayer")
You can run this $ mkvtomp4_new.sh -2 blah.mkv , will force creation of .m2ts
$ mkvtomp4_new.sh -4 blah.mkv, will force creation of .mp4
-a X : specifies audio delay in msec
-v X : specifies video delay in msec
Code:#!/bin/bash last() { if [[ $# -ne 0 ]] ; then shift $(expr $# - 1) echo "$1" fi } mkvtom2ts() { 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 "$DTS" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".dts dcadec -o wavall "${title}".dts | aften -b 640 - "${title}".ac3 rm "${title}".dts elif [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".ac3 # Great done for us! elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac faad -o - "${title}".aac | aften -b 640 - "${title}".ac3 rm "${title}".aac fi else fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | tail -n 1` if [ -n "$DTS" ]; then mkvextract tracks "$file" 1:"${title}".dts 2:"${title}".264 dcadec -o wavall "${title}".dts | aften -b 640 - "${title}".ac3 rm "${title}".dts elif [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".ac3 2:"${title}".264 # Great done for us! elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".aac 2:"${title}".264 faad -o - "${title}".aac | aften -b 640 - "${title}".ac3 rm "${title}".aac fi fi # Change Profile Level to 4.1 python -c "f=open('"${title}".264','r+b'); f.seek(7); f.write('\x29'); f.close()" echo "V_MPEG4/ISO/AVC, "${title}".264, level=4.1, insertSEI, contSPS, lang=eng" > "${title}".meta echo "A_AC3, "${title}".ac3, lang=eng" >> "${title}".meta $TSMUXER "${title}".meta "${title}".m2ts rm -f "$title".aac "$title".dts "$title".ac3 "$title".264 "${title}".wav "${title}".meta } mkvtomp4 () { 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 "$DTS" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".dts #ffmpeg -ab 640k -aq 1000 -ac 6 -i "${title}".dts -acodec libfaac "${title}".aac dcadec -o wavall "${title}".dts > "${title}".wav $NEROAACENC -if "${title}".wav -of "${title}".aac rm "${title}".wav elif [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".ac3 mplayer "${title}".ac3 -ac ffac3 -channels 6 -af format=s16le,channels=6:6:0:0:1:2:2:1:3:4:4:5:5:3 -vo null -vc null -ao pcm:fast:waveheader:file="${title}".wav -novideo -quiet -nolirc $NEROAACENC -if "${title}".wav -of "${title}".aac rm "${title}".wav elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac fi else fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | tail -n 1` if [ -n "$DTS" ]; then mkvextract tracks "$file" 1:"${title}".dts 2:"${title}".264 #ffmpeg -i "${title}".dts -acodec libfaac -ab 640k "${title}".aac dcadec -o wavall "${title}".dts > "${title}".wav $NEROAACENC -if "${title}".wav -of "${title}".aac rm "${title}".wav elif [ -n "$AC3" ]; then mkvextract tracks "$file" 1:"${title}".ac3 2:"${title}".264 mplayer "${title}".ac3 -ac ffac3 -channels 6 -af format=s16le,channels=6:6:0:0:1:2:2:1:3:4:4:5:5:3 -vo null -vc null -ao pcm:fast:waveheader:file="${title}".wav -novideo -quiet -nolirc $NEROAACENC -if "${title}".wav -of "${title}".aac rm "${title}".wav elif [ -n "$AAC" ]; then mkvextract tracks "$file" 1:"${title}".aac 2:"${title}".264 fi fi # Change Profile Level to 4.1 python -c "f=open('"${title}".264','r+b'); f.seek(7); f.write('\x29'); f.close()" MP4Box -new "${title}".mp4 -add "${title}".264$delayvstr -add "${title}".aac$delayastr -fps $fps rm -f "$title".aac "$title".dts "$title".ac3 "$title".264 "${title}".wav } export LD_LIBRARY_PATH=/usr/local/lib delayv=0 delaya=0 m2ts_flag=0 mp4_flag=0 while getopts "24v:a:" OPTION do case $OPTION in v) delayv=$OPTARG ;; a) delaya=$OPTARG ;; 2) m2ts_flag=yes ;; 4) mp4_flag=yes ;; esac done lastvar=$(last "$@") file=$lastvar delayvstr="" delayastr="" if [ $delayv -gt 0 ] ; then delayvstr=":delay=$delay" fi if [ $delaya -gt 0 ] ; then delayastr=":delay=$delay" fi ENCBR=384000 NEROAACENC="wine /opt/local/bin/neroAacEnc.exe -2pass -ignorelength -q 1.00 -br $ENCBR" #TSMUXER="wine /opt/local/bin/tsMuxeR_1.10.6/tsMuxeR.exe" TSMUXER=/opt/local/bin/tsMuxeR title=`basename "$file" .mkv` AC3=`mkvinfo "$file" | grep AC3` #check if it's AC3 audio or DTS AAC=`mkvinfo "$file" | grep AAC` DTS=`mkvinfo "$file" | grep DTS` WIDTH=`mkvinfo "$file" | grep "Pixel width:" | sed 's/.*: //g'` HEIGHT=`mkvinfo "$file" | grep "Pixel height:" | sed 's/.*: //g'` if [ $(( $WIDTH % 16 )) -ne 0 ] ; then echo "Width $WIDTH: Is not divisible by 16!" M2TS=true fi if [ $(( $HEIGHT % 16 )) -ne 0 ] ; then echo "Height $HEIGHT: Is not divisible by 16!" M2TS=true fi if [ "$mp4_flag" == "yes" ] ; then M2TS=false fi if [ "$m2ts_flag" == "yes" ] ; then M2TS=true fi if [ "$M2TS" == "true" ] ; then echo "Creating M2TS file..." mkvtom2ts else echo "Creating MP4 file..." mkvtomp4 fi # if [ -f "${directory}/${title}".mp4 ]; then # rm -f "$file" # fi
Similar Threads
-
mkv to mp4(ps3) subtitle issues
By HeroSmero in forum Video ConversionReplies: 2Last Post: 3rd Jan 2010, 19:43 -
MKV HD to MP4 HD (PS3)
By m93 in forum Video ConversionReplies: 10Last Post: 2nd Aug 2009, 10:24 -
The Best Xbox 360 and PS3 mkv video converting to mp4 App.
By spyder7777 in forum Newbie / General discussionsReplies: 0Last Post: 11th Apr 2009, 04:55 -
Large MKV (h264) File to PS3 MP4 without re-encoding
By icue in forum MacReplies: 0Last Post: 29th Sep 2008, 18:14 -
MKV to MP4 for PS3 Error
By Ravlin in forum Video ConversionReplies: 1Last Post: 5th Jul 2008, 17:38