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.


Anonymous said...
1:17 PM

Great info !

Hope to try it with HDTV from firewire. Could be a problem as the firewire source doesn't show any recording profiles but maybe this is a bug on my system.

Anonymous said...
4:58 PM

any command line solutions to transcoding?

John said...
5:00 PM

You can use mythtranscode from the command line, or, depending on how portable you want the final file to be, you can also use nuvexport (which also works with HDTV programs now).

Anonymous said...
8:09 PM

I set up using tip 4: however my files in video/recordings are not being transcoded, they are still in the original MPEG2 from recording. Are transcoded files put elsewhere by mythtv? I tried default transcode using autodetect and specific transode profile.
There are no transcode mentions in the mythbackend log at all.
When I try mythtranscode it tells me it can't find profile for MPEG-2.
any tips?
(Mythdora 3.2)

Wvrent said...
7:57 AM

I was happy to find this link and the profiles now look good in the setup screen, but how do I use them? All I see for options is Default, Autodetect, High/Medium/Low Quality

Brad said...
1:20 PM

My experience is that enabling interlaced dct encoding and motion estimation gives you an interlaced result, not a deinterlaced result. I presume you have to add a custom filter to get a deinterlaced result (and then you would not turn on these flags as they are for use on interlaced video)

Is this incorrect?

John said...
1:56 PM

@Brad, I believe you are correct, but I'm not trying to de-interlace when transcoding, instead, I'm still relying on MythTV's autodetect on playback to deinterlace when playing back the video. It makes the transcode that much faster when *not* de-interlacing.

Mark said...
10:18 AM

Re: command line transcoding: I use ffmpeg. The high quality options I use are from experimentation and a lot of scrounging on the web. Adjust threads to your processor.

The input file is 720p HDTV. I usually cut the commercials by hand first and then do a lossless transcode from Mythfrontend, prior to the MPEG-4 transcoding. Also if you have a 1080i input, then add the deinterlacing option.

Pass 1:
-i input.mpg -b 896k -vcodec libxvid -vtag xvid -pass 1 -r 29.97 -s 624x352 -aspect 16:9 -an -threads 4 /dev/null

Pass 2:

-i input.mpg -b 896k -vcodec libxvid -vtag xvid -pass 2 -mbd rd -trellis 2 -bf 2 -r 29.97 -s 624x352 -aspect 16:9 -ar 48000 -ab 192k -ac 2 -vcodec libmp3lame -f avi -threads 4 output.avi

Produces a very nice result around 350MB for an hour of television with the commercials cut out. I'm working on getting this more automated.

Note that I tried a similar setup using libx264 and the playback has serious audio issues in MythTV. Works fine in VLC, though...