Encoding MythTV Recordings with Subtitle and Surround Sound

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Earlier I had discussed how you can automate the conversion of MythTV recording to avi or mkv on a MythBuntu system using mythnuv2mkv. While the process is almost fully automated (except for the cut-list creation), it has a few shortcomings:

  1. It can only convert with stereo audio, no 5.1 surround sound.
  2. You cannot extract or embed the closed caption text as subtitle.

If you can live with these, then you should stick to the mythnuv2mkv approach. If not, then read on. And yes, it should not be too difficult to adapt this approach to other *nix distros like Fedora, OpenSUSE etc.

For this tutorial I make use of the standard mythtranscode utility to do the conversion to mkv, and then use handbrake (awesome GUI based free video encoder) to convert the mpg file to mkv with 5.1 audio and embedded subtitles. Lets start:

Step 1

On you backend machine copy and paste the content of the script given below to an empty file and save it as “mythtransjob.sh”. You can use gedit if you wish.

# Custom user job designed to save recordings to the videos directory for myth video

# This script needs the following variables in this exact order to run:
# %DIR%
# %FILE%
# TODO: error check args!

# So the prog will be called like: /path/to/script “%DIR%” “%FILE%” “%TITLE%” “%SUBTITLE%” “%CHANID%” “%STARTTIME%”

echo “Starting save_to_videos job…”

# Locate the file specified (not really used – from old script)
SRC_DIR=”$1/” # %DIR% plus a trailing slash

echo “Source file is $SRC_FILE”

# find channel and start time

echo “Channel ID and start time are $CHANID , $STARTTIME”

# Specify output path for the transcoded video

# Form unique filename

echo “Destination file is $DEST_FILE”

mythtranscode –mpeg2 –chanid “$CHANID” –starttime “$STARTTIME” –honorcutlist –outfile “$DEST_FILE” –profile autodetect

echo “Finished $DEST_FILE”

# Exit nicely
exit 0

I found this script on Ubuntuforums website, and I must acknowledge and thank the user who created it, unfortunately I forgot his name. I have changed a couple of things from the original script to fit my preferences.

Let me tell you what this script does: it takes a Mythtv recording and converts it to mpg (mpeg2) while retaining the original audio and CC if present and outputs it to the folder “/home/username/Videos/” (highlighted in red above). You would need to change it to whatever you want when copy the contents to create your conversion script “mythtransjob.sh”. Save the script and then run the following command to make it executable

chmod a+x mythtransjob.sh

Step 2

Now setup a user job to invoke this script.  Launch the MythTV backend setup from System > Administration menu. From the home screen choose 1.General

Keep hitting next button till you get the screen titled “Job Queue (Backend Specific)”.  Make tick against the boxes which says Job # 1 etc. depending on the number of jobs you want to create. I already have couple of jobs setup, the names of which are visible in the screenshot below, instead of these you would see Allow User Job #1 jobs#2 etc.

Keep hitting next again for a couple of times till you reach the screen that says Job Queue (Job Commands), here we enter the command that we want to associate with a particular job, as well as you can change the name of Commands to make them more obvious. Enter the following for a blank as shown below

User Job #3 Description: Transcode to MPG (use whatever you wish)

User Job #3 Description: /path/to/mythtransjob.sh “%DIR%” “%FILE%” “%TITLE%” “%SUBTITLE%” “%CHANID%” “%STARTTIME%”

Don’t forget to replace the /path/to with the correct absolute path of the script that we created in Step 1.

That was all the set up to be done on the backend side. All we need to do is now to create a cut list and then run the job on it.

Step 3

The script that we created has been setup to honor any cutlist that is created. The cutlist just marks the segments of the file you want deleted from the recording (typically, commercials and any buffer you may have at the start and end of the recording). Running commercial flagging itself is not good enough, it doesn’t create a cutlist. First of all the commercial flagging is not perfect, so you would have to check the flagged video and confirm or edit the cutlist. It is quite a straight-forward process and you can find a very detailed tutorial with screenshots and all here. After you have gone through this process once, it becomes very easy. Feel free to leave any queries as comments and I would love to clarify it for you.

Step 4

Now on the mythtv frontend, select Media Library. After highlighting the recording which you want to transcode to mpg and hit “M” button on keyboard or hit info button on your remote to come up with the Menu which has options like these

Add to Playlist
Mark as Watched
Storage Options
Recording Options
Job Options

Select Job Options and then choose the Recording job which you had created in Step 3. Sit back and relax, it may take a while before the encoding gets over.

Alternatively, if you want you can use Mythweb and go to recorded programs and then just click on the recorder program to get the options for the possible jobs that can be run on it and then add the job in queue via web interface.

You can keep track of the transcoding process via the web interface or by going to

Information Centre > System Status > Job Queue

via the main Menu on the Frontend. The transcoded video would be written out to the directory which we specified in the script in the Step 1.

Step 5

That’s all. Now open the video using Handbrake (for Handbrake installation tutorial for Ubuntu 10.04 look here) and set it up to convert it into a mkv or avi. I would recommend mkv, if you want to have embedded subtitles. Using Handbrake is super easy. If you need help with that, then drop me a line and I would write a how to for it as well. MythTV ROCKS!

You might also like

Upgrade MythTV 0.22 to 0.23 on Ubuntu 9.10 Ubuntu 10.04...
Enable Closed Caption (CC) / Subtitle on Live TV / Video Playback Unlike Windows...
Automatic Encoding of MythTV Recordings To avi or mkv on Ubuntu 10.04 Lucid (Mythbuntu) This tutorial...
MythTV Frontend for Windows with Live TV! Update: read...

About the Author

has written 346 posts on this blog.

Meditating towards his "nerdvana", lifehacker is a teacher by the day and a nerdy blogger by the night. He lives to learn and yearns to learn living.

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!


Copyright © 2019 Hack Your Life!. All rights reserved.
Proudly powered by WordPress. Developed by Deluxe Themes