[mythtv-users] Encoding to h264 to save space

Taco Mel taco_mel at yahoo.com
Wed Feb 20 06:50:35 UTC 2008

> Seems to work well except with seeking.  I wonder if
> this is a keyframe issue.  When I forward or rewind,
> there is distortion for a few seconds and then the
> video fixes itself...

Yes this is probably a keyframe issue.  If you hit the
video between the keyframes you will see distortion
until you hit the next keyframe, and then it will
clear up.

I have been transcoding to H.264 for a couple weeks
now after going through all sorts of pain, mostly
along the lines of "it works in mplayer but not in
MythTV."  Here is what I found:

1) In my experience, it works better if you completely
whack (do not rebuild) the seek table.  So instead of
mythcommflag --rebuild, I am issuing SQL deleting from
the recordedseek table where channel ID and start time
match the recording I just transcoded.  From my
reading of the code, absent the seek table, it will
fall back and figure it out on its own.  Works for me,

2) On some recordings, generally greater than 1 hour
30 minutes, I am unable to seek to the beginning. 
Usually when you hit "UP" with under 10 minutes
played, it will start at the beginning.  But in
certain recordings this does nothing.  I have not
tried to troubleshoot further.

I tried this first with rebuilding the seek table
using mythcommflag, and there were always one of three
results. Either mythcommflag segfaulted before
updating the table, or even after rebuilding the table
I would get the "keyframe distortion" issue, or MythTV
would refuse to play the file (sometimes segfaulting,
sometimes hanging for several seconds and then
returning to the preview).  I tried lots of things,
including using mencoder to ensure that the first
frame of the file was a keyframe, and even making
every frame a keyframe, to no avail.  So for now I am
clearing out the seek table and it works flawlessly on
95% of my recordings and acceptably on the other 5%.

Also, I have set the keyframe interval to 15.  I have
seen suggestions or defaults in the 300 range, which
is 1 keyframe every 10 seconds at 30 fps.  Setting it
to 15 allows you to seek to the nearest 1/2 second
which should be fine.

Finally, I am using mencoder and not ffmpeg.  This is
mainly because I found more examples with mencoder
back when I had no idea what I was doing.  It does
have a very nice option to put the settings into a
file and then call it with "mencoder
--profile=WHATEVER ..." and not have to
remember/retype the settings every time.  I now have
profiles optimized for different types of shows (e.g.,
anime, sports, etc.) with different bitrates and

I am compressing down to about 400 MB per half hour. 
I have a 65 inch TV and anything lower than that
displays obvious distortion.

If you decide to go with the mencoder route, I suggest
that you check out 'h264enc'
(http://h264enc.sourceforge.net/).  It interactively
guides you through a bunch of options.  When you get
done it asks you, do you want to see the options, and
do you want to save the options to a file.  That's a
great starting point for you to go through and figure
out what everything means.

I plan, after further refinement, to offer up my Myth
optimized h264 transcoding script as a contribution,
or sourceforge project, or whatever.  I've still got
to update it to use the MythTV perl bindings and get
some feedback about the "whack the seek table"
approach before I offer it up.  If you want to try it
out shoot me an e-mail and I'll send it along.

Never miss a thing.  Make Yahoo your home page. 

More information about the mythtv-users mailing list