Mythtranscode

Mythtranscode is the internal process used by the front end to transcode MythTV recordings. For lossless transcodes, calling the program through the command line has been known to work sometimes when the normal method fails.

Usage

Usage: mythtranscode <--chanid <channelid>>
<--starttime <starttime>> <--profile <profile>>
[options]
--mpeg2 or -m: Perform MPEG2 to MPEG2 transcode.
--chanid or -c: Takes a channel id. REQUIRED
--starttime or -s: Takes a starttime for the
recording. REQUIRED
--infile or -i: Input file (Alternative to -c and -s)
--outfile or -o: Output file
--profile or -p: Takes a profile number or 'autodetect'
recording profile. REQUIRED
--honorcutlist or -l: Specifies whether to use the cutlist.
--allkeys or -k: Specifies that the output file
should be made entirely of keyframes.
--passthrough : Pass the audio through rathert than decoding
and recoding (available in 0.25 or later)
--fifodir or -f: Directory to write fifos to
If --fifodir is specified, 'audout' and 'vidout'
will be created in the specified directory
--fifoinfo : Report the format of the data output to the fifos.
(requires -v general for the information to be displayed).
--fifosync : Enforce fifo sync
--buildindex or -b: Build a new keyframe index
(use only if audio and video fifos are read independantly)
--showprogress : Display status info to the stdout
--verbose level or -v: Use '-v help' for level info
--help or -h: Prints this help statement.

Choosing a Recording

Two methods are available to choose which recording to work on. The first is to specify the channelid and start time,

--chanid 1067 --starttime 20080109223000

The other method is to specify the file,

--infile /MythTV/tv/1856_20060425200000.mpg

Note: Specifying the filepath only works if the recording's filename is formatted the default way.

When using the --infile option, mythtranscode will use the filename to lookup the recordings in the recorded table and find the corresponding chanid and start-time. Non-default filenames, such as those renamed with mythrename.pl, prevent mythtranscode from doing so (and it complains of this), but it still proceeds with the transcode anyway, confusing the user. The resulting mythtranscode run is useless because the utility doesn't know what seektable to update with the data it found by scanning through the recording. The only way around this and have the transcoding succeed is:

First rename the recording back to the default format, or

Instead of using the more-convenient --infile, manually specify the data mythtranscode needs with -c and -s.

--honorcutlist Limitation

--honorcutlist only seems to work (0.19-fixes [9938]) with the "-c -s" switch combo, NOT with a specified input (-i) file, even if that file is in the mythconverg database.

Using the --buildindex Option

Using the --mpeg2 Option for (Virtually) Lossless MPEG2 Transcode

New in 0.19 is a virtually lossless MPEG2 transcode. What this does is let you select cut points and mythtranscode will only re-encode the frames that need to be, copying the rest directly from the stream. If you are using this to cut commercials and you cut at the black frames of a fade to black (or white of a fade to white), what you get is basically a perfect stream copy of the video with no loss to the frames that matter.

This also has some side benefits,

Converts the mpeg2 from a TS stream to a PS stream, possibly saving up to 20% of the file size!

Fixes Audio/Video sync issues in a similar fashion to ProjectX.

Using the --fifodir path Option

The --fifodir option causes mythtranscode to perform only the decoding part of transcoding, sending the raw video and raw audio to two pipes. No alteration is made to the original file. The path passed to the --fifodir option is assumed to refer to a directory. The two pipes will be created in that directory, with names audout and vidout. The intended use is for the raw data output to the pipes to be recompressed by an external program such as ffmpeg (this is how nuvexport works). If -v general is also specified then the format of the data that will be output to the pipes is displayed. For example

To display the format information without actually performing the transcoding, --fifoinfo can be specified, in place of --fifodir path. An example script shows mythtranscode driving ffmpeg with libx264. The script handles progressive and interlaced recordings, either maintaining resolution or downscaling.

Examples

Remove commercials from an MPEG2 recording

This will drop the cut version beside the original, but with an added .tmp extension. I'm not exactly sure what it does to the database. It seems to keep the cutpoints and points at the old .mpg file, but shortens how long it thinks the movie is to the size of the .tmp file.
Alternatively, you can add the -o option. This is useful for exporting to a different directory. For example

Troubleshooting

Every once in a while, something will happen and transcoding will not be able to complete. When this happens, the Job Queue will indicate the failure by turning the job title red in color. It will also say "Job: Transcode Status: Errored", and will follow with the line "Transcode failed with status: ###"

When this happens, you can often find information in the backend logs.. otherwise you can check this list to see if your error status matches any that others have encountered:

Code

Name

Possible Causes

References

139

SIG_SEGV

System generated, segfault. Please submit a ticket with the backtrace from your core dump.

227

TRANSCODE_BUGGY_EXIT_DEADLOCK

"Deadlock detected. One buffer is full when the other is empty!"

Cut list contains a cut zone with a beginning but no ending (often at the very end of the recording)

none

235

TRANSCODE_EXIT_STOPPED

Transcode was stopped manually by the jobqueue.

236

TRANSCODE_EXIT_ERROR_CUTLIST_UPDATE

Transcode failed to clear cutlist.

237

TRANSCODE_EXIT_REMOTE_FILE

File is on a remote filesystem. mythtranscode does not yet handle these files. Check if the Job runs on a slave backend.

Invalid command line. The transcoder is being called directly, improperly.

254

TRANSCODE_EXIT_NO_MYTHCONTEXT

No MythContext. Could not initialize properly.

Fixing "Deadlock detected. One buffer is full when the other is empty!"

If your transcode fails because this error, you can remux the video and try again. Mythtv's keyframe index will be wrong for the remuxed file, so you must also regenerate the index. And then it's sensible to reposition your cut points incase they are off. So the procedure is