Monday, July 25, 2011

sed with variables

Here is an example of how to get sed to replace values within files with variables:

for a in {1..12} ; do sed -e s/0/"$a"/g myConfig > myConfig$a ; done;


This is useful if you need to have an iterated set of config files, for instance.

In place editing of files quickly

Use the sed -i option for in place editing of files:

sed -i 's/foo/bar/g' FILENAME

It will replace all occurances of foo with bar within FILENAME

Monday, July 11, 2011

Convert videos to iPad 2 format

Recorded programs on my MythTV are in a lossless HD mpg format, which doesn't play well on my iPad2 using AirVideo Server over wlan (via wine). So, instead of having AirVideo Server converting it through the wine abstraction layer (which requires more CPU/memory, and uses ffmpeg.exe anyway), I just run this user job from my MythTV server to convert the files that I care to watch on my iPad.

Step 1:
Create this file which I call /usr/bin/mythconverttoipad. If you have an issue with "too may threads," remove -threads 16. I am using this script on a 3 core machine, the -threads option speeds things up a bit.

#!/bin/bash
DIR=$1
FILE=$2

echo $DIR
echo $FILE

ffmpeg -y -i $DIR/$FILE -ab 320kb -vcodec libx264 -b 3200kb -s 1280x720 -threads 16 $DIR/$FILE.m4v


Step 2:
Make the script executable.

chmod +x /usr/bin/mythconverttoipad

Step 3:
Add script as user job within MythTV.

Within mythtv-setup add the following user job:

/usr/bin/mythconverttoipad %DIR% %FILE%

Step 4:

Enable it within rules.

Within a program recording rule (within mythfrontent), enable this user job to be run post-recording.

Step 5:
Access the files from Air Video client or other player.

If you have questions, please comment.