Ok, I haven't fully tested the resulting command, but the following MySQL query should generate the appropriate ffmpeg commands, that will include all the MythTV metadata. You might want to do some manual checks on the commands before running them, but it should give you a good headstart.
SELECT
CONCAT (recorded.hostname, ":", recorded.title, " (", recorded.progstart, ")") recording,
CONCAT (
"ffmpeg -i ",
storagegroup.dirname, "/", recorded.basename,
" -vcodec copy -sameq -acodec copy -f matroska",
" -metadata title=\"", recorded.title, "\"",
" -metadata DATE_BROADCASTED=\"", recorded.progstart, "\"",
" -metadata ORIGINAL_MEDIA_TYPE=\"TV\"",
CASE
WHEN recorded.category IS NOT NULL
THEN CONCAT(" -metadata CONTENT_TYPE=\"", recorded.category, "\"")
END,
" -metadata TVCHANNEL=\"", channel.name, "\"",
CASE
WHEN recorded.subtitle <> "" AND recorded.description <> ""
THEN CONCAT(" -metadata SUMMARY=\"", recorded.subtitle, ". ", recorded.description, "\"")
WHEN recorded.subtitle <> ""
THEN CONCAT(" -metadata SUMMARY=\"", recorded.subtitle, "\"")
WHEN recorded.description <> ""
THEN CONCAT(" -metadata SUMMARY=\"", recorded.description, "\"")
ELSE ""
END,
" \"", storagegroup.dirname, "/",
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(recorded.title, " ", "_"), "\\", "_"), "/", "_"), "*", "_"), "<", "_"), ">", "_"), "|", "_"), "\"", "_"),
"(", REPLACE(recorded.progstart, " ", "_"), ")", ".mkv\"") converttomkv
FROM recorded, channel, storagegroup
WHERE recorded.chanid = channel.chanid
AND recorded.hostname = storagegroup.hostname
AND recorded.storagegroup = storagegroup.groupname