Archive for the ‘*nix’ Category.

ffmpeg cheat sheet

ffmpeg is a multiplatform, open-source library for video and audio files. I have compiled 19 useful and amazing commands covering almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more.

Getting infos from a video file
ffmpeg -i video.avi
Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg

This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

Turn a video to X images
ffmpeg -i video.mpg image%d.jpg

This command will generate the files named image1.jpg, image2.jpg, …

The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

Encode a video sequence for the iPpod/iPhone
ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4

Explanations :

  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 128kb/s
  • Video codec : mpeg4
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Explanations :

  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 32kb/s
  • Video codec : xvid
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3

Explanations :

  • Source video : source_video.avi
  • Audio bitrate : 192kb/s
  • output format : mp3
  • Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv

Or:

ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg

Explanations :

  • target pal-dvd : Output format
  • ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
  • aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg
Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

This was shamelessly stolen from http://www.catswhocode.com/blog/os/19-ffmpeg-commands-for-all-needs-824

Screen and the delete key - .screenrc

After a bit of poking around the interwebs i came across this little gem for getting screen to behave a bit better with the delete key.
Put this in your ~/.screenrc

termcapinfo xterm-color kD=\E[3~

the best thing is that you don’t even have to restart the screen to get it, just reattach.

Automate a Remote Login Using SSH-Agent

When it comes to remote logins, SSH is a wonderful tool. Not only is it
secure, it supports public/private key logins. Depending on public and
private keys mean even if someone gets your password, without your
private key it won’t do them any good (and vice versa).

see full article here

*nix bash while read line do - to proccess all files in a direcotry tree. because i keep forgetting….

I keep forgetting the syntx for while read.

essentially, you pipe a bunch of lines into it, and then it’ll process each line e.g.:

$find ~/video -iname ‘*avi’ -or -iname ‘*mpeg’ | while read movie ; do
mencoder [encoding options...] “$movie” -o ~/converted/`basename
“$movie”` ; done

Yay.

Installing subversion (svn) and trac on a Centos 4.6, virtuoso VM running cPannel & WHM

Or, “how to cause yourself much pain and mental anguish by inflicting silly challenges on yourself when you should really be getting some sleep”

cPannel supports apache2 now. svn needs apache2, so all is good. Or so you would think.

When installing SVN on VPS’ such as Virtuozzo, you may find that the process of creating the repository hangs, due to a lack on entropy with /dev/random. It is therefore a better bet to actually develop and use SVN outside of the VPS realm, using a dedicated box.[1]

Nice. Entropy. (I’m getting visions of Oliver Ridge, my old physics teacher, who used to fix computers with his bare hands, and a big box of resistors. Seriously, someone once gave him a broken hard disk, and he gave it back a week later. It had about ten extra components soldered to the pcb and worked better than it had originally. The man was a genius.)

Continue reading ‘Installing subversion (svn) and trac on a Centos 4.6, virtuoso VM running cPannel & WHM’ »

Strip Comments from config files on *nix ; linux

Quite easy really, you can use a number of approaches. As always regex is your friend:

Sed

sed -e 's/#.*//;/^\s*$/d' [file_name]

Grep

egrep -v '(^[ ]*#|^#|^$)' [file_name]

Perl

/usr/bin/perl while(<>) { print unless /^(#.+|\s+)$/ );

Rename hardware devices (like eth0) using udev for linux

shamelesly stolen

udev is a daemon which dynamically creates and removes
device nodes from /dev/, handles hotplug events and loads drivers at
boot time. It replaces the hotplug package and requires a kernel not
older than 2.6.12.udev - /dev/ and hotplug management daemon

Continue reading ‘Rename hardware devices (like eth0) using udev for linux’ »

htop - a nicer top

http://htop.sourceforge.net/

This is htop, an interactive process viewer for Linux. It is a text-mode application (for console or X terminals) and requires ncurses. Tested with Linux 2.4 and 2.6.

Virtualbox linux kernel upgrade solution

Problem:

VirtualBox kernel driver not installed. The vboxdrv kernel module was either not loaded or /dev/vboxdrv was not created for some reason. Re-setup the kernel module by executing ‘/etc/init.d/vboxdrv setup’ as root.
VBox status code: -1908 (VERR_VM_DRIVER_NOT_INSTALLED).

Solution:

sudo apt-get install linux-headers-$(uname -r)
sudo /etc/init.d/vboxdrv setup

Howto replace duplicate files with hard links.

Like most people I have multiple backups of the same files, stored in an ad-hoc structure. I went hunting fir a good utility to remove duplicates, and replace them with hard links.

It surprised me that there is a tool for doing this on NTFS volumes under windows. Update: and another free one!

I found a perl script called trimtrees.pl You can find it in CPAN, it’s describes itself such:

Traverse all directories named on the command line, compute MD5
checksums and find files with identical MD5. IF they are equal, do a
real comparison if they are really equal, replace the second of two
files with a hard link to the first one.

Special care is taken to cope with C error conditions.
The inode that is overbooked in such a way, is taken out of the pool
and replaced with the another one such that the minimum of files
needed is kept on disk.

The C< --maxlinks> option can be used to reduce the linkcount on all
files within a tree, thus preparing the tree for a subsequent call to
C. This operation can be thought of the reverse of the normal
trimtrees operation (–maxlinks=1 produces a tree without hard links).