Script to convert MKV to MP4 for PS3 then pass to Sickbeard?

Come up with a useful post-processing script? Share it here!
Post Reply
boredemt
Newbie
Newbie
Posts: 1
Joined: January 15th, 2013, 3:54 pm

Script to convert MKV to MP4 for PS3 then pass to Sickbeard?

Post by boredemt »

Hello all,

I'm running Sab on Ubunu 12.04.

I am looking for a script that will remux an MKV file into MP4 for use with a PS3. I'd then like it passed to Sickbeard. I know how to do it manually and I have to assume that someone else has wanted to do the same thing automagically. I've been trying to find a solution for about a week now. I know absolutely nothing about scripting. I looked around these forums and saw a few things that'd work, but they were all for Windows. Does anyone know of something that'll work on Linux? I really don't want to learn bash scripting right now.

Thanks in advance.
darkager
Newbie
Newbie
Posts: 3
Joined: February 4th, 2013, 2:52 am

Re: Script to convert MKV to MP4 for PS3 then pass to Sickbe

Post by darkager »

Hey boss,

I'm actually working on one right now that is working, but I'm ironing out some kinks.

It uses the "mkv2mp4.py" (found here: https://aur.archlinux.org/packages/mkv2mp4-svn/)

I made a very minor addition to that script to add a -r argument to tell it to remove the source file when remuxing is complete. It's not necessary if you run the script solely by SABnzbd's/Sickbeard's post-processing since it will auto-remove the directories when you're done downloading/processing the episode, but I put it in there for myself so I can run conversions on old files on my NAS. I excluded the -r switch from my script that I posted below so you don't have any issues if you just copy/paste it.
The dependencies are:

ffmpeg
gpac
mkvtoolnix
python2

The catch is, for ffmpeg, they removed the libfaac codec for legal reasons. You have to custom compile it with some specific arguments/flags to get it to compile with libfaac (I don't remember the specifics! Sorry! I'm relatively new to linux and this was a freaking brain killer for me). I believe the main ones are "--enable_libfaac" and "--nonfree" or something like that (arguments are listed in the ffmpeg configure file, so that should help).



MY code is a bash script that I placed in /c/.sickbeard/autoProcessTV/ named "processhd.sh"
Here is the current, working contents of the code. I just ironed out some issues 5 minutes ago about files/directories with spaces and file names with a comma in it.
The way the code works is, it processes and converts everything, then has Sickbeard do it's post-processing. It's seamless.

Code: Select all

#!/bin/bash
filedir=$1

echo "test"
echo ""
if [ -d "$filedir" ]; then
  cd "$filedir"

  for file in ./* ;
  do
    if [[ $file = *.mkv ]] ; then
      if [[ $file == *","* ]] ; then
        newfile=${file//,/}
        mv "$file" "$newfile"
        file="$newfile"
      fi
      file=${file##*/}
      donefile=${file:0:${#file}-4}".mp4"
      mkv_in="$file"
      mkvinfo_cues=$(mkvinfo ${mkv_in} | grep 'Algorithm')
      if [ -n "$mkvinfo_cues" ]; then
        nocues_file="nocues_"$file
        mkvmerge -o "$nocues_file" --no-cues "$file" -q
        rm $file
        mv "$nocues_file" "$file"
      fi

      mkv2mp4.py -i "$file" -o "$donefile"
    fi
  done
  /c/.sickbeard/autoProcessTV/sabToSickBeard.py "$1" "$2" "$3" "$4" "$5" "$6" "$7"
fi


Sorry about some of the commented code and lack of informational comments... I didn't intend to distribute this because when I was researching this, I didn't see any interest, so I thought I was the only one...

Make sure you give execute permissions on the script file..

Also, obviously change the paths where appropriate for your sickbeard processing script. Mine's an odd folder structure because I have this all set up with Newznab on my ReadyNAS. This whole deal has been an adventure since mid December...
Last edited by darkager on February 4th, 2013, 6:14 am, edited 2 times in total.
darkager
Newbie
Newbie
Posts: 3
Joined: February 4th, 2013, 2:52 am

Re: Script to convert MKV to MP4 for PS3 then pass to Sickbe

Post by darkager »

Another note...

I put in a bit of code there to check if there are audio/video chapters in the MKV file. I noticed some Game of Thrones episodes came with chapters in them, which the remuxing crashed when it encountered them. If it encounters them, it uses mkvmerge to strip the chapters out so you can proceed with the remuxing. It's pretty damn sweet.


I'm not 100% sure if mkvmerge and mkvinfo are in mkvtoolnix, which is listed as a dependency. I would verify that you have those after installing mkvtoolnix.
alexjj
Newbie
Newbie
Posts: 1
Joined: February 4th, 2013, 11:01 am

Re: Script to convert MKV to MP4 for PS3 then pass to Sickbe

Post by alexjj »

cytec
Newbie
Newbie
Posts: 17
Joined: April 9th, 2013, 9:55 am

Re: Script to convert MKV to MP4 for PS3 then pass to Sickbe

Post by cytec »

the easyest way may be Handbrake CLI http://handbrake.fr just define a preset as you like it and run it on your files
Keelan
Newbie
Newbie
Posts: 3
Joined: September 23rd, 2013, 12:33 pm

Re: Script to convert MKV to MP4 for PS3 then pass to Sickbe

Post by Keelan »

darkager wrote:Hey boss,

I'm actually working on one right now that is working, but I'm ironing out some kinks.

It uses the "mkv2mp4.py" (found here: https://aur.archlinux.org/packages/mkv2mp4-svn/)

I made a very minor addition to that script to add a -r argument to tell it to remove the source file when remuxing is complete. It's not necessary if you run the script solely by SABnzbd's/Sickbeard's post-processing since it will auto-remove the directories when you're done downloading/processing the episode, but I put it in there for myself so I can run conversions on old files on my NAS. I excluded the -r switch from my script that I posted below so you don't have any issues if you just copy/paste it.
The dependencies are:

ffmpeg
gpac
mkvtoolnix
python2

The catch is, for ffmpeg, they removed the libfaac codec for legal reasons. You have to custom compile it with some specific arguments/flags to get it to compile with libfaac (I don't remember the specifics! Sorry! I'm relatively new to linux and this was a freaking brain killer for me). I believe the main ones are "--enable_libfaac" and "--nonfree" or something like that (arguments are listed in the ffmpeg configure file, so that should help).



MY code is a bash script that I placed in /c/.sickbeard/autoProcessTV/ named "processhd.sh"
Here is the current, working contents of the code. I just ironed out some issues 5 minutes ago about files/directories with spaces and file names with a comma in it.
The way the code works is, it processes and converts everything, then has Sickbeard do it's post-processing. It's seamless.

Code: Select all

#!/bin/bash
filedir=$1

echo "test"
echo ""
if [ -d "$filedir" ]; then
  cd "$filedir"

  for file in ./* ;
  do
    if [[ $file = *.mkv ]] ; then
      if [[ $file == *","* ]] ; then
        newfile=${file//,/}
        mv "$file" "$newfile"
        file="$newfile"
      fi
      file=${file##*/}
      donefile=${file:0:${#file}-4}".mp4"
      mkv_in="$file"
      mkvinfo_cues=$(mkvinfo ${mkv_in} | grep 'Algorithm')
      if [ -n "$mkvinfo_cues" ]; then
        nocues_file="nocues_"$file
        mkvmerge -o "$nocues_file" --no-cues "$file" -q
        rm $file
        mv "$nocues_file" "$file"
      fi

      mkv2mp4.py -i "$file" -o "$donefile"
    fi
  done
  /c/.sickbeard/autoProcessTV/sabToSickBeard.py "$1" "$2" "$3" "$4" "$5" "$6" "$7"
fi


Sorry about some of the commented code and lack of informational comments... I didn't intend to distribute this because when I was researching this, I didn't see any interest, so I thought I was the only one...

Make sure you give execute permissions on the script file..

Also, obviously change the paths where appropriate for your sickbeard processing script. Mine's an odd folder structure because I have this all set up with Newznab on my ReadyNAS. This whole deal has been an adventure since mid December...
Any chance you could give me a hand with this? All i seem to get is:
Exit(-1) Cannot run script /path/to/script.sh
Post Reply