Convert Video for Flash Streaming

This is a simple script I’m using to convert the videos I take on my Canon S90 for posting online using a flash player.

#!/bin/bash
# Convert videos from Canon S90 to flash-playable streaming format
for file in "$@"
do
filename=$(basename $file)
        filename=${filename%.*}
        # Convert the audio stream to AAC
        ffmpeg -i $file -vcodec copy -acodec libfaac temp_vid.mp4
        # Move the H.264 MOOV atom to the beginning of the file for progressive streaming
        qt-faststart temp_vid.mp4 $filename.mp4
        rm temp_vid.mp4
        # Create a screenshot
        ffmpeg -i $filename.mp4 -f image2 -vframes 1 $filename.jpg
done

Posted in Code | Tagged , , | Leave a comment

XBMC Boxee UI Switcher

I bind this script to a button on my LIRC remote to easily switch between XBMC and Boxee on my HTPC. XBMC’s interface using the Rapier skin and fanart is much more attractive, but Boxee offers great social network integration (read: Youtube).

#/bin/bash
# Switch between XBMC and Boxee
if ps ax | grep -v grep | grep xbmc.bin > /dev/null
then
echo "XBMC running, killing process"
kill `pidof xbmc.bin`
sleep 7
echo "running Boxee"
/usr/bin/runBoxee &
elif ps ax | grep -v grep | grep Boxee > /dev/null
then
echo "Boxee running, killing process"
kill `pidof Boxee`
sleep 7
echo "running XBMC"
/usr/bin/runXBMC &
else
echo "No UI running, starting XBMC"
/usr/bin/runXBMC &
fi
view raw switchUI.sh This Gist brought to you by GitHub.

Posted in Code | Tagged , , , , | Leave a comment

Start irexec daemon

#!/bin/bash
# Checks to see if irexec is running and runs it if not already running.

youruser=richard

# Test to see if IRexec is running first, if so kill it, then restart
if ps -ef|grep -v grep|grep -vi start|grep -i irexec
then
ps aux|grep -i $youruser|grep -i irexec |grep -vi start|awk '{print $2}'|xargs kill
else
# Do nothing
echo "irexec already dead!"
fi

#test to see if an instance of irexec is already running
if ps -ef|grep -v grep|grep irexec
then
# do nothing
echo "irexec already running"
else
# start irxevent
irexec -d /home/$youruser/.lircrc &
fi

exit
Posted in Code | Tagged , , , | Leave a comment

Count files and folders

# Prints the folder name number of files and folders in each subdirectory.
for i in *; do show="$i"; num=`ls "$i" | wc -l`; echo "$show: $num"; done;
view raw gistfile1.bat This Gist brought to you by GitHub.
Posted in Code | Tagged , | Leave a comment

Find text in files

# Search for a text string in all files and subdirectories.
find -type f -print0 | xargs -0 grep -il "$1"
view raw gistfile1.bat This Gist brought to you by GitHub.
Posted in Code | Tagged , | 2 Comments

Strip ID3 Tags from FLAC

ID3 tags are not part of the FLAC specification so I decided to strip them from my FLAC files.

# Strip ID3 Tags from FLAC
find . -name "*.flac" -exec id3v2 --delete-all {} \;
view raw gistfile1.bat This Gist brought to you by GitHub.

Posted in Code | Tagged , , | Leave a comment

Compile Mplayer

Use this script to compile the latest version of mplayer in Ubuntu and save yourself some headaches. Resolving compile dependencies in Ubuntu is daunting at best, especially when you’re dealing with multimedia apps. You might end up with some unneeded dependencies, but it’s better than resolving them individually when the configure commands complain.

#!/bin/bash
#Compile the latest smplayer and compile latest mplayer, ffmpeg, and x264 from git
#This version of mplayer supports vdpau and ordered chapters
echo "Add these repositories to your /etc/apt/sources.list"
echo
echo "deb http://ppa.launchpad.net/nvidia-vdpau/ppa/ubuntu karmic main"
echo "deb-src http://ppa.launchpad.net/nvidia-vdpau/ppa/ubuntu karmic main"
echo
read -p "Press any key to continue..."
echo
echo "Install this libx264-67 package:"
echo "http://launchpadlibrarian.net/28175518/libx264-67_0.svn20090621%2Bgit364d7d-0ubuntu2_amd64.deb"
echo
read -p "Press any key to continue..."
echo
echo "Installing smplayer"
sudo aptitude update
sudo aptitude install smplayer
echo "Installing dependencies for ffmpeg, x264, and mplayer"
sudo aptitude install build-essential subversion git-core checkinstall yasm texi2html \
libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev \
libtheora-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev libxv-dev zlib1g-dev \
libfontconfig1-dev autoconf automake freetype6-dev libpng-dev libtool liblzo2-2 ncurses-dev \
zlib1-dev libvdpau-dev ladspa-sdk libaa1-dev libasound2-dev libatk1.0-dev \
libaudio-dev libaudio2 libaudiofile-dev libavahi-client-dev libavahi-common-dev \
libcaca-dev libcairo2-dev libcdparanoia-dev libcelt-dev libdbus-1-dev libdc1394-22 \
libdca-dev libdca0 libdirectfb-dev libdirectfb-extra libdts-dev libesd0-dev \
libexpat1-dev libffado-dev libfontconfig1-dev libfreebob0 libfreetype6-dev \
libfribidi-dev libgif-dev libgl1-mesa-dev libglib2.0-dev libglu1-mesa-dev \
libgsm1 libgtk2.0-dev libice-dev libjack-dev libjack0 libjpeg62-dev liblzo2-2 \
liblzo2-dev libmail-sendmail-perl libncurses5-dev libogg-dev liboil0.3-dev \
libopenal-dev libopenal1 libpango1.0-dev libpixman-1-dev libpng12-dev \
libpthread-stubs0 libpthread-stubs0-dev libpulse-dev libruby1.8 \
libschroedinger-dev libsdl1.2-dev libslang2-dev libsm-dev libsmbclient-dev \
libspeex-dev libsvga1 libsvga1-dev libsys-hostname-long-perl libsysfs-dev \
libtheora-dev libvorbis-dev libvorbisidec-dev libvorbisidec1 libx11-dev libxau-dev \
libxcb-render-util0-dev libxcb-render0-dev libxcb1-dev libxcomposite-dev \
libxcursor-dev libxdamage-dev libxdmcp-dev libxext-dev libxfixes-dev libxft-dev \
libxi-dev libxinerama-dev libxml++2.6-2 libxrandr-dev libxrender-dev libxt-dev \
libxv-dev libxvidcore4 libxvidcore-dev libxvmc-dev libxxf86dga-dev libxxf86vm-dev \
mesa-common-dev vstream-client-dev x11proto-composite-dev x11proto-core-dev \
x11proto-damage-dev x11proto-fixes-dev x11proto-input-dev x11proto-kb-dev \
x11proto-randr-dev x11proto-render-dev x11proto-video-dev x11proto-xext-dev \
x11proto-xf86dga-dev x11proto-xf86vidmode-dev x11proto-xinerama-dev xtrans-dev \
zlib1g-dev libopencore-amrwb-dev libopencore-amrnb-dev libopenjpeg-dev
cd
git clone git://repo.or.cz/mplayer-build.git
cd mplayer-build
./init
./update
./clean
make
echo "Done building mplayer!"
echo "Copy the binary from ~/mplayer-build/mplayer/mplayer to /usr/local/bin/mplayer"

Posted in Code | Tagged , , | Leave a comment

Resize Album Art

I use this to scale and crop my higher quality album art for embedding in my audio tags.

#!/bin/bash
# aa.sh
# Scale and crop album art for embedding in music tags

if [ -z $1 ]
then
echo "Usage: `basename $0` image_file"
else
convert $1 -resize 300x300^ -gravity center -extent 300x300 folder.jpg
fi
view raw aa.sh This Gist brought to you by GitHub.

Posted in Code | Tagged , , | 1 Comment
QR Code Business Card