Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Script to Convert mkv to mp4 for your PS3

  1. #1
    Join Date
    Jan 2008
    Beans
    204
    Distro
    Hardy Heron (Ubuntu Development)

    Script to Convert mkv to mp4 for your PS3

    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
    Last edited by ASULutzy; November 15th, 2010 at 04:38 PM.

  2. #2
    Join Date
    Jun 2010
    Beans
    43
    Distro
    Xubuntu 11.04 Natty Narwhal

    Re: Script to Convert mkv to mp4 for your PS3

    Whenever I try this, the script tries to import a .aac file with an identical filename of the .mkv that I'm trying to convert, but it can't find it, so it stops right there. What do I do now?

  3. #3
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,134
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Script to Convert mkv to mp4 for your PS3

    Can you run mkvinfo against your mkv file and paste the results in here? I'm guessing that you have either a weird audio codec, or the mkv file has the tracks in a different order than video, audio. Looking at this script it should work in most situations.

  4. #4
    Join Date
    Feb 2008
    Beans
    8

    Re: Script to Convert mkv to mp4 for your PS3

    I was running into the same problem that frustratednerd mentioned above. I had to change the libfaac to aac and I had to add a -strict experimental flag on the ffmpeg lines.

    ASULutzy or rubylaser, did you compile ffmpeg from source? If so, maybe thats why it doesn't work for us. I know I just installed it from the repos. Just a thought.

  5. #5
    Join Date
    Jun 2010
    Beans
    10

    Re: Script to Convert mkv to mp4 for your PS3

    thank you, that was really helpful. I didn't need to convert the audio since it was all aac. One suggestion. mkvextract automatically overwrites files with the same name. So instead of extracting to
    Code:
    $Title.264 and $Title.aac
    you can just extract to video.264 and audio.aac. then in mp4box mux -add video.264 -add audio.aac When it comes to demuxing the next mkv in the folder video.264 and audio.aac will be overwritten and the file names reused.
    Last edited by ki3456; February 22nd, 2011 at 01:43 AM.

  6. #6
    Join Date
    Nov 2008
    Location
    United States
    Beans
    2,090
    Distro
    Kubuntu 11.10 Oneiric Ocelot

    Re: Script to Convert mkv to mp4 for your PS3

    why not just use DeVeDe and maintain the high resolution .mkv offers?

    just choose the divx option.

    the ps3 will play this file, so would divx home players if the file is burned as a data dvd.

  7. #7
    Join Date
    Jun 2010
    Beans
    10

    Re: Script to Convert mkv to mp4 for your PS3

    Here is a cut down version of the script I used. There is no conversion, no checking that video is first stream, and no deletion.

    Code:
    #!/bin/bash
    
    find . -type f | grep .mkv$ | while read file
    do
     directory=`dirname "$file"`
     title=`basename "$file" .mkv`
     AAC=`mkvinfo "$file" | grep AAC`
     fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | head -n 1` 
     mkvextract tracks "$file" 0:video.264 1:audio.aac
     MP4Box -new "${directory}/${title}".mp4 -add video.264 -add audio.aac -fps $fps
    done
    Last edited by ki3456; May 20th, 2012 at 12:04 AM.

  8. #8
    Join Date
    Jun 2010
    Beans
    10

    Re: Script to Convert mkv to mp4 for your PS3

    It just occured to me the other problem with PS3 is it won't attempt to play video higher than level 4.1. Some encoders accidentally set the level to 5.1 Since the tracks are already demuxed might as well set the level to 4.1, so at least the PS3 will try to play the file.

    To do that you need to hexedit raw video file. Hexalter will do the job from the command line.

    Code:
    #!/bin/bash
    
    find . -type f | grep .mkv$ | while read file
    do
     directory=`dirname "$file"`
     title=`basename "$file" .mkv`
     AAC=`mkvinfo "$file" | grep AAC`
     fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | head -n 1` 
     mkvextract tracks "$file" 0:video.264 1:audio.aac
     hexalter video.264 0x7=41
     MP4Box -new "${directory}/${title}".mp4 -add video.264 -add audio.aac -fps $fps
    done
    link for hexalter
    Code:
    http://www.kuwanger.net/hexalter.zip
    Last edited by ki3456; May 20th, 2012 at 12:05 AM.

  9. #9
    Join Date
    Feb 2009
    Location
    47.3505, 8.71842
    Beans
    168
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Script to Convert mkv to mp4 for your PS3

    I was fiddling around for a long time with this .mkv to .mp4 problem, and now I've finally written a little program to take care of it. Here is the URL of the projects page on github:https://github.com/Basphil/MKVToMP4Converter.
    Turning an .mkv file in an .mp4 file works well, it does check for the order of audio/video streams and chooses the right fps. Depending of the orignal audio format it also changes the volume a bit, becuase in my experience aac tends to be louder in an .mkv than in an .mp4 file.
    You can additionally have it watch a directory for new .mkv files, and then it automatically converts them. I'm still working on this part, but for single .mkv files it works reasonably well.

    There are still improvements to do (like delete the temp files etc.) but I hope that it can be of use for you.
    “The ships hung in the sky in much the same way that bricks don't.”
    Douglas Adams

  10. #10
    Join Date
    Jun 2011
    Location
    Johannesburg, S. Africa
    Beans
    1
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Script to Convert mkv to mp4 for your PS3

    ASULutzy's first script in this worked really well for me, though it needed some tweaking. For example, if track 1 is AAC and track 2 is video, the extraction will output to the wrong files.

    The AAC encoding bitrate seems really high at 576k. Why not use 320k? Or am I missing something?

    A further improvement might be to use the Nero AAC encoder, since the libfaac one seems to have a bit of a bad reputation.

    @Zilioum, I was never able to get your converter to work.

    I'm a noob on these forums. Where would be the best place to create a HOW-TO on this topic. It seems to come up a lot with all the PS3's out there.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •