MythTV does not automatically remove commercials. The system will flag commercials and optionally skip them during playback. It can also transcode recordings between MPEG-2 and MPEG-4 or lossless transcode MPEG-2 and remove a cut list from the program. Since a list of commercial flags is not a cut list, it is not removed automatically. This document describes how to remove commercials permanently from the source material

Note: You do not need to do anything on this page if all you are doing is watching recorded shows using Myth TV, then deleting them or letting them auto-expire. You will not save very much space. What the instructions on this page are useful for is if you're storing or archiving your recordings, or are watching your recordings outside of MythTV, or want to watch "HDTV" programming on a slower machine in standard definition.

Removing commercials using mythfrontend

Editing Recordings

The recording editor allows you to mark areas of the recording to skip over during playback. Once you edit a recording, you can transcode the recording to permanently remove the cut areas from the recording file.

If you would like the transcoder to permanently remove any portions of the recording--including commercials or the lead in prior to a show or the overrun at the end of a show--you must first edit the recording.

Transcoding Recordings

The transcoder re-encodes files from one MythTV format to another. There are two reasons to transcode

Note: This is not used for creating MPEGs for burning to DVD as you will get audio video sync issues, especially with DVB recordings. You need to use MythArchive for this or manually with Project X and DVD Author.

Use the Recordings Profiles to change how the system transcodes your recordings

mythtv-setup --> Recording Profiles -> Transcoders.

now select either RTjpeg or MPEG-4 (selecting any of the hardware encoders will result in the transcoder not working). set the other parameters as you'd like. For best performance, you should match the audio to the 'Default' profile. If you plan to only use the manual transcoder, you can choose to set the video to be the same as the default profile too (as long as it is MPEG-4 or RTjpeg)

Note: Even though MythTV 0.21 allows you to change the names of the recording profiles, don't do it. You can only edit the existing profiles. This is a feature that was partially implemented but hasn't been finished.

After marking commercials, the transcoder can be run manually to delete the commercials from the file (thus further saving space).

The two methods are independent. The first is an automatic process that can be enabled/disabled through the setup program; the second is a manual method which must be invoked on each recording individually.

You can transcode a recording that has already been transcoded, for example to cut a further section with no loss in quality provided you are going from and to the same format.

To enable automatic transcoding, do the following: start the setup program under the host-specific settings: set the Transcoder Auto-run checkbox, or in newer versions of the program, you may select automatic transcoding from any of the recording profiles you have set up.

Everything should now be setup properly. If you elected to use the Auto-Run feature, the transcoder will automatically launch after each recording is complete. The transcoder thread runs at a low priority, so it should not impact any critical tasks or other recordings.

If you want to manually transcode a program, simply press while watching a recording and select Transcode (you should have already finished marking all commercials and creating your Cut List with the Recording editor).

If you change your mind press and select Stop Transcoding.

Once the transcode is complete, mythbackend will replace the old file with the new as soon as it is no longer in use.

Then use mythtranscode to transcode the recording using the cut list with

mythtranscode --honorcutlist

You will need the additional standard options to both programs to choose the proper program based on filename or channel and time. Look at the --help output from each program for details on using these options

Automatically removing commercials

In the 0.20 release of MythTV, you can specify a custom command-line option for both the commercial flagging job and the transcoding job. Using this function, you could create a wrapper script for transcoding after commercial flagging that would use the command-line options outlined above.

One such way to implement this is to setup a User Job that uses this script. Save that script as /usr/local/bin/removecommercials and ensure that the script is executable by running:

chmod 755 /usr/local/bin/removecommercials

Set up a user job that runs the following:

removecommercials %DIR% %FILE% %CHANID% %STARTTIMEUTC%

You can do this by following the directions found on the User Jobs page.

Name the user job "Commercial Removal". You can now remove commercials by highlighting the recording in the recording list, hitting the right arrow, selecting "Job Options", and then selecting "Begin Commercial Removal". You may also set up your recordings to automatically run this script after a recording finishes. For more information on doing this, see the User Manual.

Update All Recordings

If you want to update all your recordings to automatically remove commercials, you could use the following SQL statement:

This SQL statement assumes you've set up the job as User Job 1, and will only update those recordings already set to flag commercials.

Troubleshooting

Transcode error - Transcode failed with status: 247

If it throws an error at the transcoding step check your transcoding prefs. I had to change mine from RTjpeg to MPEG in the transcoding option in the Recording Prefs.
From the Myth Frontend:

Utilities/Setup

Setup

TV Settings

Recording Profiles

Transcoders

Edit all "Autodetect" profiles (two in my case), on the second screen of each profile is a "codec" option, change this to "MPEG-4" from "RTjpeg".

Lastly, you need to change the command in your user job entry. It should read

removecommercials %DIR% %FILE% %CHANID% %STARTTIMEUTC%

The script has been updated to support MythTV 0.27, 0.28. If you need an earlier version of the script, please visit the discussion page of the script or check wiki history.

Database update fails after transcoding completes

Also if it gets past the transcoding and then crashes by saying user @ localhost does not have privileges. The mythbackend.log says something like "Access denied for user 'mythtv'@'localhost'".
I had to run backend as root (I don't know how to make my user account have the privileges).

Note from manicmike: An easy way to give the user permissions is to 1) Edit* the sudoers file as root with "visudo" and add the entry <the mythtv user> ALL=NOPASSWD:/usr/local/bin/removecommercials (obviously, change the angle brackets bit to the user running mythtv) then save and quit. 2) change "removecommercials" in your user job to "sudo removecommercials". This will run the job as root while you're still the user.

in vi, press "i" to go into insert mode. Make the changes and exit using the sequence Esc : x (hit Esc, type a colon, type an x, hit enter).

Running the removecommercials script as system root probably only works when the MySQL root user has a blank password; leaving the MySQL root user without a password is a fairly basic security no-no. Another option would be to create a user-level configuration file for the mythtv user. The configuration file contains the database, user name and password to be used automatically by MySQL when scripts running as 'mythtv' make database calls.