Saturday, June 18, 2011

How to convert .m2ts videos to .avi, using a script

The problem:
I have a bunch of vacation videos located in: /mnt/drive2/vacation_videos/ , but they are all .m2ts format, and I want them to be in .avi format

The solution:
- Create a generic script "convert.sh" which converts a .m2ts file to .avi
- Create a script "vacationVideos.sh" with all the custom vacation videos, and call the convert.sh script
- Run this as a background process, which allows you to log out of the session without interrupting the process. i.e. "nohup shellscriptname &"


1. Generic conversion script. Save as: nano /usr/sbin/convert.sh

#!/bin/bash
# AlanLupsha: this script converts .m2ts files to .avi files
# If you do not have mencoder, run sudo apt-get install mencoder
if [ -z $1 ] ; then
        echo "syntax: convert.sh file.m2ts"
        RETURNCODE=1
        exit $RETURNCODE
fi
mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o  "$1.avi"

2. custom script with the names of all my vacation videos. Save as: nano ~/vacationVideos.sh

#!/bin/bash
# This "vacationVideos.sh" script copies my vacation videos into a
# temporary directory and then invokes the convert.sh
# script which converts .m2ts format to the .avi format

MAINPATH=/mnt/drive2/vacation_videos/
TMP=/dev/shm
cd "$TMP"

FILE="2011.grandparents.m2ts"
cp "$MAINPATH/$FILE" "$TMP"
# convert the file from .m2ts to .avi (takes a long time)
convert.sh "$FILE"
# copy the converted .avi file back to the drive
mv "$TMP/$FILE.avi" "$MAINPATH"
# remove the temporary copy of the .m2ts file
rm "$TMP/$FILE"


FILE="2010.SouthFlorida.m2ts"
cp "$MAINPATH/$FILE" "$TMP"
# convert the file from .m2ts to .avi (takes a long time)
convert.sh "$FILE"
# copy the converted .avi file back to the drive
mv "$TMP/$FILE.avi" "$MAINPATH"
# remove the temporary copy of the .m2ts file
rm "$TMP/$FILE"


FILE="2006.DriveAcrossTheUSA.m2ts"
cp "$MAINPATH/$FILE" "$TMP"
# convert the file from .m2ts to .avi (takes a long time)
convert.sh "$FILE"
# copy the converted .avi file back to the drive
mv "$TMP/$FILE.avi" "$MAINPATH"
# remove the temporary copy of the .m2ts file
rm "$TMP/$FILE"

echo "Done converting!"

3. How to run:

ssh myname@linuxserver
nohup ~/vacationVideos.sh &

To see the progress:
tail -f nohup.out

To see the process:
ps aux | grep mencoder

To kill the process:
killall mencoder

Enjoy.

Thursday, June 9, 2011

How to set up Subversion in Ubuntu

sudo adduser subversion

sudo mkdir /home/svn
sudo svnadmin create /home/svn/dev

# change ownership
sudo chown -R subversion:www-data /home/svn/dev

# make the dir group write-able
chmod -R g+w /home/svn/dev/

# add yourself to the www-data group
sudo usermod -a -G www-data alan



sudo apt-get install apache2
sudo apt-get install libapache2-svn

sudo nano /etc/apache2/mods-available/dav_svn.conf

add at the end:


DAV svn
SVNParentPath /home/svn
SVNListParentPath On
AuthType Basic
AuthName "Subversion Repository"
# AuthUserFile /etc/subversion/passwd

Require valid-user




Save.

sudo /etc/init.d/apache2 restart


# Add your users in subversion, create their accounts:
sudo nano /home/svn/dev/conf/passwd

alan=123456
mary=654321


# For subversion over http, also add the same users to the
# subversion passwd file, first time use -c to "create" it.
sudo htpasswd -c /etc/subversion/passwd alan
sudo htpasswd /etc/subversion/passwd mary


# Empty out config file
sudo su -
echo "" > /home/svn/dev/conf/svnserve.conf

# Edit file and add next entries:
sudo -u subversion nano /home/svn/dev/conf/svnserve.conf


[general]
anon-access = none
auth-access = write
password-db = passwd
realm = digitalagora
[sasl]

# Save, exit.

# Install xinetd, and let it take care of running the subversion server
sudo apt-get install xinetd

# edit a new svn file
sudo nano /etc/xinetd.d/svn

# Paste these contents:

service svn
{
port = 3690
protocol = tcp
socket_type = stream
wait = no
disable = no
user = subversion
server = /usr/bin/svnserve
server_args = -i -r /home/svn/dev

#ALAN - increase incoming connections per second
# X connections per second, 1 sec to reset after overload
cps = 3000 1

# if in /var/log/messages you see: FAIL: svn per_source_limit from=IP...
per_source = UNLIMITED
}

# Save the file, exit.

# start the xinetd service
sudo service xinetd restart

# check that subversion is running, you should not get an error from this command (use your

username/pass)
svn --non-interactive --username alan --password abc12345 list svn://localhost/



# ===================================================
# ALTERNATIVELY, IF YOU DO NOT WANT TO USE XINETD:
# Start the server manually...
svnserve -d -r /home/svn/
#
# Check that it's running
ps aux | grep svn
#
You should see something like: svnserve -d -r /home/svn/
# to stop svnserve, run
ps aux | grep svn
killall svnserve
ps aux | grep svn
# ===================================================



Test the installation

# create project
svn --non-interactive --username alan --password abc12345 -m "new" mkdir

svn://localhost/dev/testproject

# check out project
cd ~
svn --non-interactive --username alan --password myPassw0rd checkout

svn://localhost/dev/testproject

# create new files in checked out project
touch ~/testproject/newfile1.txt
touch ~/testproject/newfile2.txt
touch ~/testproject/newfile3.txt

# go into project
cd ~/testproject
svn add *

# commit the files
svn commit -m "new" *

Adding newfile1.txt
Adding newfile2.txt
Adding newfile3.txt
Transmitting file data ...
Committed revision 2.




=================================
a2ensite default-ssl
a2enmod ssl
sudo /etc/init.d/apache2 restart
sudo make-ssl-cert generate-default-snakeoil --force-overwrite
=================================

Check that it's working:
http://localhost/