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
If you just want to skip commercials from the front end, see Commercial Flagging.
Removing commercials using mythfrontend
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.
The transcoder re-encodes files from one MythTV format to another. There are two reasons to transcode
- Allow users to create MPEG-4 streams to save space.
- Physically cut the commercials or video segments from the recordings.
Use the Recordings Profiles to change how the system transcodes your recordings
mythfrontend -> utilities/setup -> TV Settings --> 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)
The transcoder can be used in two ways:
- Automatically re-encode every file once it has completed recording.
- 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).
Once the transcode is complete, mythbackend will replace the old file with the new as soon as it is no longer in use.
Removing commercials from the command-line
You must have already flagged commercials for this option to work.
Use mythcommflag to create a cut list by using
Then use mythtranscode to transcode the recording using the cut list with
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.
chmod 755 /usr/local/bin/removecommercials
Set up a user job that runs the following:
removecommercials %DIR% %FILE%
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:
mysql -u root mythconverg;
or if you have a password on the root mysql account
mysql -u root -p mythconverg;
UPDATE record SET autotranscode = 0, autocommflag = 0, autouserjob1 = 1, autouserjob2 = 0, autouserjob3 = 0, autouserjob4 =0 WHERE autocommflag = 1;
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.
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:
- TV Settings
- Recording Profiles
- 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".
MythTransCode runs OK, but doesn't cut commercials
What I noticed is that (even from the command line) mythtranscode fails to 'honor the cut list' when used with the "-i <filename>" syntax, but when that is switched to "-c <channel> -s <datetimestamp>" everything suddenly works fine. Don't know why, but it helped me to make things work.
I edited the above script to include the channel and datetimestamp in the mythtranscode command. To make the changes, replace lines 4-9 with
CHANID=$3 STARTTIME=$4 # Sanity checking, to make sure everything is in order. if [ -z "$VIDEODIR" -o -z "$FILENAME" -o -z "$CHANID" -o -z "$STARTTIME" ]; then echo "Usage: $0 <VideoDirectory> <FileName> <CHANID> <STARTTIME>"
and line 30 with
mythtranscode --honorcutlist --showprogress -c $CHANID -s $STARTTIME -o $VIDEODIR/$FILENAME.tmp
Lastly, you need to change the command in your user job entry. It should read
removecommercials %DIR% %FILE% %CHANID% %STARTTIME%
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.
- add the file '.my.cnf' to the mythtv home directory
- add the database options to the file, like so:
[client] user=mythtv password=<replace_with_mythtv_dbpassword> database=mythconverg
- Only the mythtv system user needs read permissions. Note: MySQL will not use this password if the file is world-writable.
-rw-rw---- 1 mythtv mythtv /home/mythtv/.my.cnf
- For debugging, you can add the command 'my_print_defaults' to the shell script to print the configuration options read and used by MySQL.
my_print_defaults client mysql