get_iplayer startup script

19 02 2012

For funsies I am looking to create a web pvr, using get_iplayer, sickbeard and sabnzbd+ (though I am planning to stay on the legal side and only download what I can watch for free anyway).

Since there is no startup script for the get_iplayer web pvr program, I created one. You can find it here:

XBMC Ubuntu Minimal Maverick Install Script

1 01 2011

As a little New Year’s present, I have updated a script that has been knocking around to allow you to install XBMC on a minimal version of Ubuntu Maverick.

If you simply install Ubuntu from the mini.iso containing the basic Ubuntu Maverick install, then on reboot, download my script using:


make it executable, using:

chmod a+x

then finally run it using:

sudo ./

I find it is best to run it again, once the script reboots the machine, as this fixes a few issues.

It is still a work in progress, as you can’t yet shutdown / restart etc via XBMC since it seems the method to add permissions in Ubuntu 10.10 have changed and they conflict with the setup here, so I am still looking into that. To shutdown / reboot at the moment, I log in via SSH and issue:

sudo shutdown -hP now

Also, it is designed to work just with the Acer Aspire Revo 3610, but there is no reason why it wont work with any other device (apart from maybe the audio configurations).


Download It Here

FINALLY: A Bash Progress Indicator for ffmpeg that WORKS

11 05 2010

I decided to write a progress indicator for ffmpeg video conversions. This was much much much harder than I ever anticipated. I was in for a tough time. Annoyingly, for what ever reason, ffmpeg doesn’t use Carriage Returns and Line Feeds in the expected way when it outputs its output during a conversion, resulting in two days of stress for a noobie bashophile like me.

Eventually, after hours of googling, I came across the solution. This script should be a very accurate indicator of the progress of a ffmpeg video conversion. It currently only tells you how far the conversion has progressed as a percentage, but I will soon add an ETA and time to it as well (now added, see update below). It does this, by looking at the number of frames your input video file has, and then reading what frame ffmpeg is currently on every ten seconds, and printing out the percentage.

You have to put in your own ffmpeg command if you want, mine is just for converting .mpg DVB-T recordings from MythTV to mkv files.
To use the script, call the script with the full path of the file to be converted afterwards, e.g.: “./ /home/prupert/FIVE.mpg” and it gives you something like this:


I have now added an ETA function, which, as far as I can tell, should be pretty accurate, I’ll be testing it tomorrow to see how well it works. It is based on the remaining number of frames to process and the current fps that ffmpeg is working at. I also plan to convert the script to python, if possible, to make it cross platform and give it a GUI. It will also be called YAFF (Yet Another Ffmpeg Frontend).

Essentially, the script turns ffmpeg output from this:

frame=42992 fps= 21 q=29.0 size= 217692kB time=1717.72 bitrate=1038.2kbits/s dup=12 drop=0
frame=43002 fps= 21 q=29.0 size= 217692kB time=1718.12 bitrate=1038.0kbits/s dup=12 drop=0
frame=43018 fps= 21 q=29.0 size= 217756kB time=1718.76 bitrate=1037.9kbits/s dup=12 drop=0
frame=43036 fps= 21 q=29.0 size= 217788kB time=1719.48 bitrate=1037.6kbits/s dup=12 drop=0
frame=43050 fps= 21 q=29.0 size= 217820kB time=1720.04 bitrate=1037.4kbits/s dup=12 drop=0
frame=43062 fps= 21 q=29.0 size= 217852kB time=1720.52 bitrate=1037.3kbits/s dup=12 drop=0
frame=43078 fps= 21 q=29.0 size= 217884kB time=1721.16 bitrate=1037.0kbits/s dup=12 drop=0
frame=43090 fps= 21 q=29.0 size= 217916kB time=1721.64 bitrate=1036.9kbits/s dup=12 drop=0
frame=43106 fps= 21 q=29.0 size= 217948kB time=1722.28 bitrate=1036.7kbits/s dup=12 drop=0
Last message repeated 2 times
[mpeg2video @ 0x8f7ebf0]ac-tex damaged at 15 0
[mpeg2video @ 0x8f7ebf0]concealing 90 DC, 90 AC, 90 MV errors
frame=43122 fps= 21 q=29.0 size= 217981kB time=1722.92 bitrate=1036.4kbits/s dup=12 drop=0
frame=43140 fps= 21 q=29.0 size= 218045kB time=1723.64 bitrate=1036.3kbits/s dup=12 drop=0
frame=43155 fps= 21 q=29.0 size= 218077kB time=1724.24 bitrate=1036.1kbits/s dup=12 drop=0
frame=43168 fps= 21 q=29.0 size= 218141kB time=1724.76 bitrate=1036.1kbits/s dup=12 drop=0
frame=43182 fps= 21 q=29.0 size= 218205kB time=1725.32 bitrate=1036.1kbits/s dup=12 drop=0
frame=43194 fps= 21 q=29.0 size= 218237kB time=1725.80 bitrate=1035.9kbits/s dup=12 drop=0
frame=43207 fps= 21 q=29.0 size= 218269kB time=1726.32 bitrate=1035.8kbits/s dup=12 drop=0

In to this:

/home/rupert/Downloads/Village of the Damned.mpg..mpg has 172447 frames, now converting
ffmpeg PID = 24868
ffmpeg: 43062 of 172447 frames, progress: 24% and ETA: 1h 42m 41s

Which must be a good thing in anyone’s book ;)

The script is hosted at github, enjoy:

Creative Commons License
YAFF by Rupert Plumridge is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales License

Simple Bash Progress Script

21 04 2010

So, I wanted a way to monitor the progress of a Bash script I was running, since it could take a long time to run on occassion and I wasn’t sure if it had failed or not.

After some Ubuntu Forum googling, I came up with this:

time=( $(tac /var/log/rsback/work-daily | grep -m 1 "total runtime" | awk '{ print $6 }') )
echo "last running time was" $time
/bin/rsback -v work-daily >> /var/log/rsback/work-daily &
trap "
#[ -e /proc/$pid ] && kill $pid

while [ -e /proc/$pid ]; do
sleep 10
runtime=( $(ps ax | grep -m 1 zenity | awk '{print $4}') )
echo "#" $runtime
done | zenity --width 500 --progress --pulsate --title="work-daily running time: $time" --text="running time:" --auto-close

# If the progress bar was canceled, give a warning.
if [ $retval -ne 0 ]; then
zenity --title="work-daily rsback" --error --text="the work-daily rsback was cancelled" || exit 1
kill $pid
time=( $(tac /var/log/rsback/work-daily | grep -m 1 "total runtime" | awk '{ print $6 }') )
zenity --info --title "Work rsback" --text "work rsback done in $time"

It seems to work pretty well, though obviously this is customised for my particular needs (so it uses the command’s own log location etc). I thought I would share it with the world, since it took me a while to figure out. When I get the chance, I’ll update it to it can work with any command or script ;)

Automatically Update FFMPEG and x264 From Source / SVN In Ubuntu

16 04 2010

Whenever I wish to install and use the rather excellent video and audio transcode programs ffmpeg and x264 I have used FakeOutdoorsman’s excellent How To from the Ubuntu Forums. However, constantly typing out all the commands, especially when updating, is a pain in the arse.

I thus decided, with FakeOutdoorsman’s permission, to write some scripts to automate the task. They are, I hope, fairly comprehensive and allow a user to build and install the latest version of ffmpeg and x264, from source for Ubuntu Hardy, Intrepid, Jaunty, Karmic and Lucid. They allow this to be done automatically, after a few questions have been answered.

There are four scripts in total, one for the initial install, one for keeping everything up-to-date, one to reverse the changes with minimal impact and one to completely reverse all changes (this one I recommend no-one using, hence it is depreciated, but it is there in case some one wants it).

I am certainly not the best at bash, but I have done lots of Googling and I think the script is fairly robust, though I am sure there are errors.

I will be adding to the script over time, adding new features, combining things, adding better error checking etc, so for now consider them BETA releases. They have been tested on Lucid and Karmic only, but they appeared to work.

Please submit any questions here or at the project hosting page.

So, where are the files?

You can get all the scripts here:

Have fun!

MythTV Recordings: Rename, Move and Delete From The Database

12 11 2009

So, I have been using MythTV for a while now and it is a.w.e.s.o.m.e.. However, I had one problem, since I transcode and store all my videos on my Ubuntu server and not my MythTV box (which is off most of the time via mythwelcome) I had to manually transfer recorded files to my Ubuntu server via mythweb.

I thought this was a bit of a hokey solution, so I asked around if there was a script that allowed you to rename MythTV recordings (to a more human readable version), move them to another location and remove them from the MythTV database. There were some solutions out there, but they all involved the recorded files being kept in the MythTV database.


So, I wrote my own script. This script renames the MythTV files to a nice human understandable version using, it then moves the recordings to a folder of your choice (in my case a mounted samba share on my server), it then uses to delete the moved recordings from the mythTV database (I don’t know if it will still remember that these files were previously recorded so it doesn’t rerecord them or not, I guess time will tell).

So, without further ado, here is the script, in lovely Bash (the script is called mythtvremodel (mythtv REname MOve DELete, geddit?):

#! /bin/sh
# Provides: mythtvremodel
# Required-Start:    $local_fs $syslog $remote_fs dbus
# Required-Stop:     $local_fs $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: rename, move delete recordings
# script to rename files recorded from mythtv and then to move them and delete them
#made by
#creative commons licence, whichever is the most FREE (as in beer)

#lets put in some variables so others can use this
#location of log file, you can choose anything and any name
#this is the full path to
#this is the full path to your recordings folder
#this is the extension your recordings are stored as, usually mpg or nuv
#this is the full path to where you want your files moved to
#this is the full path to
#mythtv database password for

# first, run mythtvrename to get nice names for the recordings
echo starting mythtvremodel on `date "+%m/%d/%y %l:%M:%S %p"` > $log
perl $mrename --underscores --format %T-%S-%d%m%y >> $log
# use find to search for all recorded files in the recording folder and move them to the TV folder
find "$record" -name "*.$ext" >> $log
find "$record" -name "*.$ext" -exec mv {} "$dest" ; >> $log
# use mythorphan to remove the now missing recorded files from the database
perl $morphan --pass=$pass --dodbdelete >> $log
#that should be it
echo stopping mythtvremodel on `date "+%m/%d/%y %l:%M:%S %p"` >> $log
exit 0

And there you have it. Now, since I run mythbuntu, I have put this script in /etc/rc0.d (thats rc zero . d) and have named it K03mythtvremodel, thus it is run when my system shuts down, but before all the samba shares and drives are unmounted. As I said, since I use mythwelcome to shutdown my machine when idle, this seemed like the best solution.

Hope it helps someone!

MediaPortal Comskip and Transcode Bat and Bash Scripts

8 09 2009

As I mentioned earlier, I use MediaPortal to record DVB-T broadcasts. As these end up quite big, I then use two scripts to check the recordings for adverts and to transcode the recordings to a mkv file (smaller and better supported).

This solution isn’t very elegant, since it is for my personal setup which is a little unusual, in that the recordings are done via a Windows XP MediaCentre PC, they are then analysed for adverts using Comskip and are then transferred to my Ubuntu-based server, which then transcodes the files to an MKV file and the adds Chapter markers to those MKV files using the file from Comskip. Thus there script is in two parts, one a Windows Bat script and the other is a Ubuntu Bash script.

The scripts are below. First, the Windows Bat script that runs the recorded file through Comskip and then copies it over to the server. Since I wanted to only run one script for all the recordings made in an evening, the script takes the file name from MediaPortal, which passes it to the script after the file is finished recording, using the Comskip plugin. This explains all the weird “Echo” in front of all the terms, since basically it is putting all the commands into another script, which is then run early each morning.



ECHO Rem Batch commands for %1 START >> "C:scriptscomskiptrans.bat"
ECHO CD "C:scriptscomskip" >> "C:scriptscomskiptrans.bat"
ECHO START "" "C:Program FilesVideoLANVLCvlc.exe" >> "C:scriptscomskiptrans.bat"
ECHO %%SystemRoot%%explorer.exe "Z:" >> "C:scriptscomskiptrans.bat"
ECHO ECHO ************************** ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO Post Processing started on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
REM ECHO ECHO Starting mpeg2repair %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
REM ECHO mpeg2repairHelper.exe %1 %1-fixed.ts >> "C:scriptscomskiptrans.bat"
REM ECHO ECHO mpeg2repair finished on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO Comskip started on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO comskip %1 >>"%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO Comskip finished on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO %%date%% %%time%% ^>^> "Z:new_files.log" >> "C:scriptscomskiptrans.bat"
REM ECHO ECHO ComClean started on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
REM ECHO mencoder "%~dpn1.ts" -edl "%~dpn1.edl" -alang eng,nar -noskip -vf harddup -oac copy -ovc copy -of mpeg -o "%~dpn1_clean.ts" >> "C:scriptscomskiptrans.bat"
REM ECHO ECHO ComClean finished on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO New file %1 being moved to Server ^>^> "Z:new_files.log" >> "C:scriptscomskiptrans.bat"
ECHO ECHO Tidying started on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO %%SystemRoot%%explorer.exe "Z:" >> "C:scriptscomskiptrans.bat"
ECHO CD "%~dp1" >> "C:scriptscomskiptrans.bat"
REM ECHO ren *.edl *.ts.edl >> "C:scriptscomskiptrans.bat"
REM ECHO ren *.txt *.ts.txt >> "C:scriptscomskiptrans.bat"
ECHO ren *.chap *.ts.chap >> "C:scriptscomskiptrans.bat"
ECHO ECHO Moving Clean TS to Server directory on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
REM ECHO IF EXIST "%~dpn1_clean.ts" del %1 >> "C:scriptscomskiptrans.bat"
ECHO xcopy %1 Z: >> "C:scriptscomskiptrans.bat"
ECHO IF EXIST "Z:%~n1.ts" del %1 >> "C:scriptscomskiptrans.bat"
REM ECHO xcopy "%~dpn1.edl" Z: >> "C:scriptscomskiptrans.bat"
ECHO del "%~dpn1.txt" >> "C:scriptscomskiptrans.bat"
ECHO xcopy "%~dpn1.ts.chap" Z: >> "C:scriptscomskiptrans.bat"
ECHO ECHO TS and others moved to Server directory on %%date%% %%time%% ^>^> "%~dpn1.PostLog.txt" >> "C:scriptscomskiptrans.bat"
ECHO ECHO %~n1.ts moved to Server on %%date%% %%time%% ^>^> "Z:new_files.log" >> "C:scriptscomskiptrans.bat"
ECHO TASKKILL /IM vlc.exe >> "C:scriptscomskiptrans.bat"
ECHO Rem Batch commands for %1 FINISH >> "C:scriptscomskiptrans.bat"

Thus this script creates the trans.bat file, which is then run via a scheduled task. All the stuff starting with REM are lines that the script no longer uses, but that contain interesting code that might be useful in the future. This includes using a program called mpeg2repair, that was meant to clean the recording in-case there were any errors during transmission, but the program error-ed out too many times. Another line was also meant to use Mencoder to cut the adverts out directly using an EDL file created by comskip, but this resulted too often in audio/video sync problems, I think as a result of the original .ts file having some errors in it, so I REMed out that line as well.

The second script is my Ubuntu bash script, which is run every morning, after the trans.bat script (created by the script above) is run.

# Written by FakeOutdoorsman and updated by mysoogal further updated by prupert
# Attribution-Noncommercial 3.0 Unported
# trackback
echo started on `date "+%m/%d/%y %l:%M:%S %p"` > /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.ts" >> /mnt/media/documents/ruperts/TV/trans.log
chmod -R 777 /mnt/media/documents/ruperts/TV
find /mnt/media/documents/ruperts/TV -name "*.ts" -exec /home/server/Desktop/handbrake/HandBrakeCLI -i {} -t 1 -c 1 -o {}.mkv -f mkv -e xvid -b 1200 -2  -a 1 -E faac -B 160 -R 0 -6 dpl2 -D 1 -C 2  -v '{}' ; >> /mnt/media/documents/ruperts/TV/trans.log
echo finished on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
echo attempting to add advert chapter markers on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec /home/server/scripts/ "{}" ; >> /mnt/media/documents/ruperts/TV/trans.log
echo advert chapter markers added on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
echo starting clear up on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
cd "/mnt/media/documents/ruperts/TV/" || { echo >&2 "Source folder not found"; exit 1; } >> /mnt/media/documents/ruperts/TV/trans.log
find . -type f -name "*.ts" -exec sh -c '[ -f "${1%.ts}.ts.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/trans.log
find . -type f -name "*.ts" -exec sh -c '[ -f "${1%.ts}.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/trans.log
find . -type f -name "*.ts.mkv" -exec sh -c '[ -f "${1%.ts.mkv}.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/trans.log
find . -type f -name "*.ts.chap" -exec sh -c '[ -f "${1%.ts.chap}.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec mv {} /media/video/Video ; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.edl" -exec rm {} ; >> /mnt/media/documents/ruperts/TV/trans.log
find /mnt/media/documents/ruperts/TV -name "*.txt" -exec rm {} ; >> /mnt/media/documents/ruperts/TV/trans.log
echo ts files deleted and moved script stopped on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log

This is run by a cron job every morning. It uses Handbrake to transcode the .ts file to a .mkv file. It then runs a third script (below called to use mkvmerge to add chapter markers to the mkv file that Handbrake created. Finally, it moves the mkv file to where all my Videos are stored. At the very end, there are some commands to delete the .ts files and the intermediate .mkv files ONLY if the mkv file has been correctly created.

Here is the script:

echo started on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/trans.log
mkvmerge --chapters "${VIDEO%/*}/${ENC%%.*}.ts.chap" "$VIDEO" -o "/mnt/media/documents/ruperts/TV/${ENC%%.*}.mkv"

This script is called by the main Ubuntu script above.

I also have a separate script that I use to transcode the .m2ts files produced by the Sony PS3’s PlayTV program:

echo started on `date "+%m/%d/%y %l:%M:%S %p"` > /mnt/media/documents/ruperts/TV/transm2ts.log
find /mnt/media/documents/ruperts/TV -name "*.m2ts" >> /mnt/media/documents/ruperts/TV/transm2ts.log
chmod -R 777 /mnt/media/documents/ruperts/TV
find /mnt/media/documents/ruperts/TV -name "*.m2ts" -exec /home/server/Desktop/handbrake/HandBrakeCLI -i {} -t 1 -c 1 -o {}.mkv -f mkv -w 720 -e xvid -b 1200 -2 -a 1 -E faac -B 160 -R 0 -6 dpl2 -D 1 -C 2 -v '{}' ; >> /mnt/media/documents/ruperts/TV/transm2ts.log
echo finished on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/transm2ts.log
echo starting clear up on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/transm2ts.log
cd "/mnt/media/documents/ruperts/TV/" || { echo >&2 "Source folder not found"; exit 1; } >> /mnt/media/documents/ruperts/TV/transm2ts.log
find . -type f -name "*.m2ts" -exec sh -c '[ -f "${1%.m2ts}.m2ts.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/transm2ts.log
find . -type f -name "*.m2ts" -exec sh -c '[ -f "${1%.m2ts}.mkv" ]' _ {} ; -delete >> /mnt/media/documents/ruperts/TV/transm2ts.log
find /mnt/media/documents/ruperts/TV -name "*.mkv" -exec mv {} /media/video/Video/TV ; >> /mnt/media/documents/ruperts/TV/transm2ts.log
echo m2ts files deleted and moved script stopped on `date "+%m/%d/%y %l:%M:%S %p"` >> /mnt/media/documents/ruperts/TV/transm2ts.log

Because Comskip can’t be run on .m2ts files, I don’t call the script, since there is no .chap file to use.

I would freely admit that these scripts aren’t very user friendly, since they are customised just for my setup. However, if readers would prefer a useful version that was more user-friendly, I could create that. It is possible to convert the Ubuntu Bash script into a Bat script for Windows. However, I don’t think there is any alternative to the mkvmerge file for Windows that the Ubuntu script uses.

Also, sadly, the devs of Handbrake are a little blinkered. They created the CLI interface so you can run Handbrake via the commandline, which is great. The CLI also creates Exit codes, which is very useful for scripting. However, the Exit codes only tell you if the CLI worked correclty, not if Handbrake worked correctly. So if the transcode failes, but the CLI worked corretly, it will exit as if nothing went wrong. Sadly the Handbrake devs don’t see this as a problem. Kind stupid imho, but hey, it’s their loss. Thus, there is no way of telling if the transcode worked correctly or not, the only way to check is to see if the file you want to be created is there…doh!


Get every new post delivered to your Inbox.