Tip #4: Transcode profiles for HDTV

The Problem I was having transcoding HDTV

One of the biggest issues with recording HDTV is that the files are huge. Also, mythtranscode's ability to transcode HDTV was spotty prior to 0.19. My old solution was to use ProjectX to demux the Transport Stream and transcode (with ffmpeg) to resize, convert to MPEG-4 (XviD) and remux. If I wanted to maintain the best quality, I would use two passes, and this solution was *sloooooow* and very manual.

Mythtranscode works now! ...What's next?

With 0.19, mythtranscode has been rock solid transcoding my HD Transport Streams. It's also blazingly fast! Once I started using it, though, I realized that the default profiles didn't work for me. I had three different sources of DTV:

  • 1080i
  • 720p
  • 480i

I also have several different desired output formats:

  • No Resize - High Quality (De-Interlaced)
  • Resize to 960x540 High Quality (De-Interlaced)
  • Resize to 634x352 Med Quality (De-Interlaced)

Because of all the combinations, I wanted the following Transcode profiles:

  • 1080i - NoResize
  • 1080i - Resize High
  • 1080i - Resize Med
  • 720p - NoResize
  • 720p - Resize High
  • 720p - Resize Med
  • 480i - NoResize

Great... Now how can I do that?

With MythTV, you are given some profiles for transcoding (Default, Live TV, High Quality, Low Quality), which you can modify, rename, etc; however, it does not allow you to create new transcoding profiles through the UI, so I went to the database (mythconverg). Once I figured out all of the tables that are involved in the transcoding process, I went to work.

The three tables I'm interested in are: profilegroups -> recordingprofiles -> codecparams

Modify Transcoder Profile Group

First, we want to modify the Transcoder Profile Group. From mythfrontend, select: Setup -> TV Settings -> Profile Groups -> Transcoders. This will drop you into the recordings profile screen where you will see the four default profiles: Default, Live TV, High Quality, Low Quality. These are generally not good enough for the needs of HDTV folks. The next step will show you how to customize those recordings profiles, and even create a few more.

Modify existing recordings profiles

  • From mythfrontend, select the first profile 'Default'.
  • Replace the name 'Default' with 1080i NoResize.
  • Make sure Lossless transcoding, and Resize video while transcoding are not checked, and select Next.
  • Now set up your code params. I use the following settings:

    Click to enlarge

  • Click 'Next'. On the 'Audio Quality' screen, choose Uncompressed, and 48000 as the sampling rate.
  • Click 'Finish'.

Repeat this for each of the remaining profiles (Live TV, High Quality, Low Quality) renaming them as you go.
For example:
For 1080i Resize High Quality
Rename Live TV -> 1080i Resize High
Check 'Resize Video while transcoding'
Width: 960 Height 540
Codec: MPEG-4
Maximum quality:2
Minimum quality:15
Max diff between frames:3
Check all boxes except Scale bitrate for frame size
Audio Settings:
Sampling rate:48000

Now... When you use the last profile and you need to create another one, you need to add an entry to the recordingprofiles table. Do this by executing:

mysql> insert into recordingprofiles (name,videocodec,audiocodec,profilegroup) values ('480i Resize','MPEG-4','Uncompressed','6');
Query OK, 1 row affected (0.01 sec)

Now when you go back into your transcoders screen, you will see the new profile and you can modify the settings appropriately.

Additional Notes

When creating the profiles for 720p source content be sure to uncheck to two boxes Enable Interlaced DCT encoding and Enable Interlaced Motion Estimation.

My bitrate and widthxheight settings are as follows:

  • 1080i - NoResize - 4526 na
  • 1080i - Resize High - 2400 960x540
  • 1080i - Resize Med - 1300 624x352
  • 720p - NoResize - 4559 na
  • 720p - Resize High - 2400 960x540
  • 720p - Resize Med - 1300 624x352
  • 480i - NoResize - 900 na

I leave my bitrates higher than they probably need to be, but I have not had time for a tremendous amount of experimentation, and the settings yield enough of a decrease in filesize that it works for me.

Good Luck, and if you have any comments, please feel free to leave them here.

Tip #3: Importing downloaded TV shows into MythTV


Last week, I upgraded my kernel. Unfortunately, after a re-boot, my DVB drivers failed to load. The net result is I went three days without recording a single show. Now my only option is downloading the TV shows, and watching them manually, somehow (usually mplayer). WAF definitely goes down.

How to Get the Shows Into MythTV

It turns out, that importing the shows into MythTV is easy. The issue is it's not terribly simple. I'll describe below how to import a show into MythTV. Some of the metadata is 'optional'.

Let's get to it!

Not entering the optional data will get your show into MythTV, but the Meta-Data about the show will not be imported (Meta data like Show description, the correct date/time of the show, subtitle, etc...)

  • the show must be in mpeg-4, or mpeg-2 format. If it is not, you can use mencoder, or transcode to convert it.
  • You need to know the name of the show
  • You need to know the channel ID of the show's recordings (see script below)
  • Optional:The original date/time of the episode
  • Optional:The Subtitle of the episode (see tv.com for this stuff)
  • Optional:The description of the show (tv.com is your friend)

I wrote a little shell script to list the channels in my channels table:
mysql --host -umythtv -p -e 'use mythconverg; select chanid, name, callsign from channel where visible=1'

Let's say I missed an episode of E-Ring

  1. Download the show from your favorite source (fine by me if you use torrents).
  2. Move the file to your recordings directory (in my case /video/recordings)
  3. run myth.rebuilddatabase.pl --ext avi (if your file has the extension avi)

    These are the files stored in (/video/recordings) and will be checked against
    your database to see if the exist. If they do not, you will be prompted
    for a title and subtitle of the entry, and a record will be created.

    Non-nuv file /video/recordings/E-Ring.11-16.Delta.Does.Detroit.avi found.
    Do you want to import? (y/n):y

  4. Enter 'y'
  5. You will be prompted for several pieces of information, and when you are done, myth.rebuilddatabase.pl should ask you to rebuild the seek table (critical!). If it does not, then when the script exists execute the following command:

$ mythcommflag --rebuild --file .nuv
This will rebuild the seek table, but will not commercial flag the recording. Commercial flagging is probably not necessary as your downloaded file probably does not contain commercials.

Final Note

Sometimes when viewing imported AVI files with MythTV's internal player I will notice problems with the screen refreshing when I skip around. This is usually due to the fact the many shows are encoded with key frames far and few between. Wait a couple seconds (usually a scene change) and the screen will clear up.

Good Luck!