
UPDATE: I’ve posted a newer version of the script with better documentation
I’ve written a bash script that uses nuvexport in conjunction with my custom nuvexportrc file to automatically transcode my HUGE mythtv files after they are recorded. The only thing that this script doesn’t do is delete the source file after creation. I’m working on getting a patch submitted to nuvexport to allow source file and the associate database entries to be deleted upon successful transcode. The easiest way to invoke this script is to create a user job in mythtv’s job queue. Anyway, included below is a copy of my script:
-
#!/bin/sh
-
#
-
# Transcodes and removes commercials from MythTV files.
-
# Requires nuvexport and a properly configured nuvexportrc file.
-
# See attached nuvexportrc for an example.
-
#
-
# Invoke from mythtv user job with the following line:
-
# /path/to/mythexport "%FILE%" "%TITLE%"
-
#
-
# USAGE: mythexport [infile] [title]
-
#
-
-
# User to run nuvexport as, should own both sharedir and outdir
-
user=mythtv
-
-
# Location of nuvexport
-
nuvexport=/usr/local/bin/nuvexport
-
-
# Directory where MythTV stores its .mpg files
-
indir=/shared/.mythtv/
-
-
# The temp location for use during transcoding
-
outdir=/shared/.mythtv/out/
-
-
# For my setup, the location to copy the finished .avi after transcoding
-
sharedir=/shared/video/TV/
-
-
# User must provide at least two arguments
-
if [ $# -lt 2 ]
-
then
-
echo "ERROR: Invalid arguments"
-
echo "USAGE: mythexport [infile] [title]"
-
exit 1
-
fi
-
-
# The provided absolute path to the mythtv file.
-
infile=$1
-
-
# Get rid of the first parameter, the rest are the title of the show
-
shift
-
-
# Title of the show
-
title=$@
-
-
# If the mythtv file exists
-
if [ -r "$indir$infile" ]
-
then
-
# The "command"
-
sudo -u $user $nuvexport –infile "$indir$infile" –noconfirm > /dev/null
-
-
# Create a directory for the show, if one doesn‘t exist
-
if [ ! -d "$sharedir$title/" ]
-
then
-
mkdir "$sharedir$title/"
-
fi
-
-
# Move the transcoded file to the sharedir
-
mv -f "$outdir$title – "*.avi "$sharedir$title/"
-
-
else
-
echo "ERROR: Unable to open source file " "$indir$infile"
-
exit 2
-
fi
-
-
exit 0
-
Here’s a link to my script: mythexport.zip. This file also contains a copy of my nuvexportrc file.
You must be sure to pass the filename to be transcoded, as well as the title of the show, from mythtv itself. This is easily accomplished by using appending %FILE% and %TITLE% to the user job description of the file.
Also, since these are impossible to find online, here are the custom arguments you can pass jobs from myth’s job queue:
-
* %DIR% – the directory component of the recording’s filename
-
* %FILE% – the filename component of the recording’s filename
-
* %TITLE% – the title of the recording (e.g., name of the series)
-
* %SUBTITLE% – the subtitle of the recording (e.g., name of the episode)
-
* %DESCRIPTION% – description text for the recording (from guide data)
-
* %HOSTNAME% – the backend making the recording
-
* %CATEGORY% – the category of the recording (from guide data)
-
* %RECGROUP% – the recording group
-
* %CHANID% – the MythTV channel ID making the recording
-
* %STARTTIME% – the recording start time (YYYYMMDDhhmmss)
-
* %ENDTIME% – the recording end time (YYYYMMDDhhmmss)
-
* %STARTTIMEISO% – the recording start time in ISO 8601 format (YYYY-MM-DDTHH:MM:SS)
-
* %ENDTIMEISO% – the recording end time in ISO 8601 format
-
* %PROGSTART% – the recording’s start time (from guide data; YYYYMMDDhhmmss)
-
* %PROGEND% – the recording’s end time (from guide data)
-
* %PROGSTARTISO%, %PROGENDISO% – the recording’s start and end time in ISO 8601 format.
Very cool script. Thanks so much! I’ve been search the net for and example of how to script nuvexport. =)
Two questions. How are you envoking the script, cron job or from within MythTV? Also Is there a reason that you are envoking sudo rather than setting the script to run say as a cron job as the myth user?
Thanks!
Eric
Thanks a ton. This really helped me out.
I’ve got the same questions as eric… and a few more.
There doesn’t seem to be much documentation about nuvexport. Some of the functions in nuvexportrc don’t seem to work. For example, does anybody know how to change the framerate? There is an option in the nuvexportrc but it doesn’t seem to do anything. Also, the quantisation doesn’t do anything… despite what the comments say you have to specify bitrate manually in nuvexportrc
As for the script itself, It works great. I’m trying to figure out some way to replace unsupported characters in titles though. For example, some systems don’t support a : in a directory name, so “Extreme Makeover: Home Edition/Title.avi” needs to be re-named to “Extreme Makeover- Home Edition/Title.avi”
This script makes nuvexport seemless with mythtv
Sorry about the late reply. I run the script as a user job from MythTV. I use sudo to have it run as the MythTV because nuvexport complains if you run it as root, and I’m not sure what username MythTV invokes user jobs with.
One could run it using cron. In fact, that’s what I did before I figured out how to get the user jobs working properly. I’m sure you could get rid of sudo using cron, but I just wanted to make certain that no matter how I called the script, nuvexport would run with the credentials of MythTV.
Sorry Matt, I don’t know how to fix your naming problem. I’m sure you could do something with regular expressions in the script. But, I’m not the best shell scripter, so I don’t really know. As for your other problems: Yeah, I know nuvexport has crappy documentation. I know there’s currently an outstanding bug addressing your quantization issue. I have no idea how to modify the frame rate either. I’m sorry I can’t be of much help.
I’ll post an updated version of the script shortly.
This is a pretty cool script, however I am not sure what the Shared Directory is for.
thanks,
-jason
As I mention in the comments, I use the sharedir as the location, to which. I copy the output files.
This information would be better put in the official mythtv wiki rather than leaving it to languish on some distant blog page somewhere
I’ll do that. Thanks for the suggestion.
very cool, If they do not accept your patch for delete will you share it with the rest of us so we can fix mythtv to do the delete for us?
I guess one could write a perl app to remove the entry from the DB and then delete the files manually but I would prefer a unified approach.
Thanks!
That looks like an nuvexport bug. It’s typically pretty buggy. If you’re not using the latest nuvexport from SVN, try using a few slightly older version.
Hi Kyle,
actually I sorted this out through trial and error… In the past I have had problems getting mythbackend to start with the /etc/init.d/mythbackend startup script. So I started it from crontab. Seems like that way there is no terminal for which termcap info would be available.
At least now when I updated the startup script, killed, and then started the mythbackend with that, the encoding works. As I have not yet restarted the system, I am not sure if the fix is permanent.
You can also simply edit /etc/init.d/mythtv-backend by adding the following line:
TERM=xterm
This will fix the problem as well.
Having serious issues getting the script to run on my Ubuntu machine. I hacked the script to finally get it going but getting the following error, any ideas?
OSPEED was not set, defaulting to 9600 at /usr/local/share/nuvexport/nuv_export/shared_utils.pm line 61
I’m sorry about that, but that looks like a bug in nuvexport. Check for a new version, or make sure that your nuvexport config file is setup properly.
Could you provide a job line example of how you call your script. I just can’t seem to construct a working job line.
/usr/bin/nuvexport-xvid –ffmpeg –quantisation 4 –a_bitrate 128 –v_bitrate 4000 –nice 10 –input=”%FILE%”
When I would use a job line like this to call nuvexport, it’d go to my export directory following my ~.nuvexportrc, but would not give me any kind of file name, only %t_%s.avi.
Today I got a human readable format using the above line, but the file exports to “/” and not my export directory. So, I’m lost and embarrassed to admit my ignorance in public like this.
2008-04-26 13:37:20.754 JobQueue: Started “Nuvexport Mythexport Script” for “Law & Order: Criminal Intent” recorded from channel 1060 at Wed Apr 16 18:00:00 2008
2008-04-26 13:37:20.767 jobqueue: Job “Nuvexport Mythexport Script” Started: Started “Nuvexport Mythexport Script” for “Law & Order: Criminal Intent” recorded from channel 1060 at Wed Apr 16 18:00:00 2008
/home/mythtv/mythexport2: 36: [[: not found
/home/mythtv/mythexport2: 57: [[: not found
ERROR: Unable to open file /home/mythtv/.mythtv1060_20080416180000.mpg
2008-04-26 13:37:20.815 JobQueue: Finished “Nuvexport Mythexport Script” for “Law & Order: Criminal Intent” recorded from channel 1060 at Wed Apr 16 18:00:00 2008.
2008-04-26 13:37:20.834 jobqueue: Job “Nuvexport Mythexport Script” Finished: Finished “Nuvexport Mythexport Script” for “Law & Order: Criminal Intent” recorded from channel 1060 at Wed Apr 16 18:00:00 2008.
I’ll give you some help in a bit. I’m pretty busy right now.
Thanks so much! I figured you were busy. I really appreciate it.
I just write mythexport %FILE% %TITLE% to the end on my joblist for MythTv configuration.
Have you modified the script at all? I see two errors in your output relating to the use of [[.
Finally, are you using the script from the .zip file?
No, I have not modified the script in anyway. I only renamed the script as Ubuntu has their own script called “mythexport” which is in the PATH. And yes, I am running the script from your .zip. I was able to get Nuvexport to write files with reading file names only by commenting out the filename line in ~.nuvexportrc. But when I try to run the script from the job line, I get a bogus filename again. The mythexport that comes with Ubuntu sucks, as it does not pay attention to the cutlist like Nuvexport. Thats why this is so frustrating that I can’t get proper filenames.
That’s just bizarre. However, what is this error from?
/home/mythtv/mythexport2: 36: [[: not found
/home/mythtv/mythexport2: 57: [[: not found
If you look in my script, I don’t even use the chars ‘[[’.
Anyway, you shouldn’t have to remove the filename line from nuvexportrc. There may be a bug with Ubuntu’s MythTv,
However, I’d suspect nuvexport. It’s generally pretty buggy. Try getting the latest SVN or go back in revisions a few weeks.
I don’t actively maintain a MythTv setup anymore, so I can’t be of that much help. Sorry
I just hope that this little crappy script may be of help to some people.
Ooops… it looks like I have an out-of-date copy of my script sitting on my server, try downloading it now.
I like the script once i got it to work took a little fiddling =) main problem was the same as Petri.
Only got one question or suggestion. Is there a way to get the current status of the transcoding outputed somewhere like mythtrans does on the status page?
actuall i have come into a problem.
the files output are outputed like this:
%t.2.avi
%t.avi
%t – 06.avi
%t.3.avi
it seems that the %t variable doesnt work any suggestions??