Archive for the ‘posix’ Category

How to add runmodes to a CGI::Application

Tuesday, March 25th, 2008

There really are a ton of messy ways to tinker with adding runmodes to CGI::Application.

I tried a lot of different things, succesfully, strangely, even ‘cleverly’.

If you have a plugin that is being ‘use’d, you should have an import function.

(more…)

copy part of movie

Wednesday, February 6th, 2008

I wanted to cut a chunk of footage from a video file.
Mencoder does this wonderfully, but, the command is not intuitive.

First, the example. This command goes to 10 minutes after the movie starts and takes 30 seconds after and spits out to ‘out.avi’..

mencoder ./filein.avi -ss 00:10:00 -endpos 00:00:30 -o ./out.avi

More practical example:

Fire up a terminal emulator.. open your source movie with mplayer.
You’ll need to see where in the movie you are, press ‘o’, get a pen and paper. This tells you the time elapsed.
You want to start your video selection at 00:14:24, that is, 14 minutes, 24 seconds.
And you want to stop at 00:15:24.
What you need to figure out is how much time there is betwen the start time and the stop time, in this case, one minute.

So our -ss seek/start time, will be 00:14:24
Once the movie is being copied, the end position (inside the copy movie) will be 00:01:00 (one minute).

Let’s put the command together..

mencoder ./in.avi -ss 00:14:24 -endpos 00:01:00 -o ./out.avi

Wait! Where is the stop time of 00:15:24?? RTFM, remember? endpos is telling mencoder where to stop, this is the target duration of the output movie we are making.

how to join movie files

Wednesday, February 6th, 2008

Examples

mencoder ./a.avi ./b.avi -oac copy -ovc copy -o joined.avi

Basically, there are three sets of parameters, in whatever order..

1) a list of files to join (paths)
2) -o the name of the output file (path)
3) settings for how to deal with audio (-oac) and video (-ovc)

There are a lot more settings then this, for that please see man mencoder.

how to make an avi smaller

Wednesday, January 30th, 2008

Sometimes I have a divx file that is way too big to fit into a cd.
How the heck do you make an avi smaller?

I ripped a copy from dvd to an avi, and got it to under 700 megs, great. That fits in a cd. But then I had a 10 meg subtitle file! So, it didn’t fit! I needed to get the avi a little smaller.

If you look up info on mplayer, mencoder.. there’s a LOT to read.
So here’s how, in no way complete.
Just one way to solve the problem.

   mencoder in.avi -o out.avi -ovc lavc -oac copy  -lavcopts vbitrate=400:vpass=1

Now, what’s very cool about mencoder, is it gives you stats on progress..

   Pos: 101.5s   2435f ( 0%) 213.30fps Trem:  27min 628mb  A-V:0.036 [320:32]

‘Trem’ is rime remaining, and the mb count is the guess for how big it will be.
As the progress gets further along (beyond 10%), the stats will be more precise.

Downloading Images from a Camera with Linux

Tuesday, January 29th, 2008

Ingredients:

  • Linux distro (Fedora Core 4)
  • Camera USB (Kodak Easyshare LS743)
  • gphoto2

So I get a camera, and take pictures.. now what? I got linux. I thought this may be complicated.. But guess what..

Step 1

Make sure gphoto2 is installed. If not.. open shell cli prompt (whatever) and become su, then # yum -y install gphoto2, wait for it to complete..

Step 2

Make your dir to receive photos, change to it.. then # gphoto2 -P

Step 3

All your photos are downloaded to your current working dir. Now, delete the photos.. # gphoto2 -DR .. All the photos are deleted from your camera.

Done. That's it. No mouse clicking. No stupid dialogues. Wow.

posting to wordpress via the command line

Sunday, January 20th, 2008

I tackled this problem via XMLRPC and perl.
I ended up packaging this under WordPress::Post on cpan.

Usage examples:

wppost -t 'title of the post' -c stuff,fruit,cake -i 'This is what I think of bla.'

You can also write a text file, the name of the text file is the title.

wppost -i ./path/to/title_of_the_post.txt

This program is in its infancy. But dammit, it works. It’s how I posted this content via the command like. Also, you can include images in your posts. Multiple images. Via the command line.
Anything not in the argument is considered posting content..
So what if your post if about a party you went to, and you have 5 pictures..

First write your halloween_party.txt file, then have your photos lined up somewhere.. then..

wppost -i halloween_party.txt ./images/halloween_photos_post/*jpg

Done. Linux rocks.

how to join avi movies

Sunday, January 20th, 2008

mencoder -aoc copy -ovc copy ./file1.avi ./file1.avi -o ./out.avi

mencoder is part of mplayer, you can install via yum on fedora core packages..

yum -y install mencoder

I had a lot of these to join.. so..
I made a perl script that I can use use without so much fuss.. one that I don’t have to tell it what the output file is going to be.
I put it in ~/bin/avijoin

#!/usr/bin/perl
use strict;

my $outfile = outfile();

my @arg = (qw(mencoder -oac copy -ovc copy), @ARGV, '-o',$outfile);

system(@arg) == 0 or die($?);

print "Wrote:\n$outfile";

exit;

sub outfile {
@ARGV or die('missing args');
my $outfile = $ARGV[0];
$outfile=~s/([^\/]+)\.(\w{1,5})$// or die;
my ($filename,$ext) = (uc $1,$2);
my $x=0;
$filename=~s/\W//g;
my $_outfile;

for(1){
$_outfile="$outfile/$filename$x.$ext";
last unless -e $_outfile;
$x++;
}
return $_outfile;

}

Make sure to chmod 0755 ~/bin/avijoin

rename

Wednesday, January 16th, 2008

I want to go over linux rename command very quickly. It’s a simple command but I used to find it tricky and unintuitive.

The man rename output examples of foo and bar are freaking cryptic.
So I want to show some real world examples of rename

Let’s do a directory listing…

[leo@localhost rename_example_dir]$ ls -l
total 1872
-rw-rw-r-- 1 leo leo 845805 2008-01-16 20:36 P1010591.JPG
-rw-rw-r-- 1 leo leo 914240 2008-01-16 20:36 P1010624.JPG
-rw-rw-r-- 1 leo leo  38167 2008-01-16 20:35 Picture 11.jpg
-rw-rw-r-- 1 leo leo  29726 2008-01-16 20:35 Picture 16.jpg
-rw-rw-r-- 1 leo leo  25545 2008-01-16 20:35 Picture 21.jpg
-rw-rw-r-- 1 leo leo  23886 2008-01-16 20:35 Picture 22.jpg
-rw-rw-r-- 1 leo leo  14736 2008-01-16 20:35 Picture 3.jpg

Great. Now, let’s change those filenames..

[leo@localhost rename_example_dir]$ rename 'Picture ' 'PICTURE_' ./Pictu*
[leo@localhost rename_example_dir]$ ls -l
total 1872
-rw-rw-r-- 1 leo leo 845805 2008-01-16 20:36 P1010591.JPG
-rw-rw-r-- 1 leo leo 914240 2008-01-16 20:36 P1010624.JPG
-rw-rw-r-- 1 leo leo  38167 2008-01-16 20:35 PICTURE_11.jpg
-rw-rw-r-- 1 leo leo  29726 2008-01-16 20:35 PICTURE_16.jpg
-rw-rw-r-- 1 leo leo  25545 2008-01-16 20:35 PICTURE_21.jpg
-rw-rw-r-- 1 leo leo  23886 2008-01-16 20:35 PICTURE_22.jpg
-rw-rw-r-- 1 leo leo  14736 2008-01-16 20:35 PICTURE_3.jpg

Ok, how about we match up the file extensions too..

[leo@localhost rename_example_dir]$ rename JPG jpg ./*
[leo@localhost rename_example_dir]$ ls -l
total 1872
-rw-rw-r-- 1 leo leo 845805 2008-01-16 20:36 P1010591.jpg
-rw-rw-r-- 1 leo leo 914240 2008-01-16 20:36 P1010624.jpg
-rw-rw-r-- 1 leo leo  38167 2008-01-16 20:35 PICTURE_11.jpg
-rw-rw-r-- 1 leo leo  29726 2008-01-16 20:35 PICTURE_16.jpg
-rw-rw-r-- 1 leo leo  25545 2008-01-16 20:35 PICTURE_21.jpg
-rw-rw-r-- 1 leo leo  23886 2008-01-16 20:35 PICTURE_22.jpg
-rw-rw-r-- 1 leo leo  14736 2008-01-16 20:35 PICTURE_3.jpg

Now let’s talk about what the heck happened.
The command is..

rename $takeout $putin $towhatfiles

First argument is what you do not want there, second argument is what you want to replace it with, third argument is a list of files, you can use wildcards and all the other freaky unix filematch operators.

rename images by exif date

Tuesday, January 15th, 2008

I have a digital cam. I take pictures.
I don’t like a million DSCIM or DSCF or whatever files.
It’s inconvenient with so damn many.

It would be nice to rename all the images according to the date, as recorded inside the image exif data, that is, the sate stamp put in by your camera.

I hacked together this script to do that..
Use at your own peril. This is a hack.
Eventually I will release a refined version on cpan.

This scrip requires modules Image::ExifTool, LEOCHARRE::CLI ..

#!/usr/bin/perl -w
use strict;
use File::Copy;
use Cwd;
use LEOCHARRE::CLI;

# requires Image::ExifTool
#
my $o = gopts('m');

#yn('rename all jpg files by date in '.cwd().'?') or exit;

my $files = argv_aspaths();

(defined $files and scalar @$files )or die("no file arguments provided");

if ($o->{m}){
   -d './noout' or mkdir './noout';
}

for (@$files){
   $_=~/(.+)\/([^\/]+)$/ or next;
   my $abs = $1;
   my $filename = $2;
   $filename=~/\.jpg$/i or next;
   print STDERR "$abs   - $filename \n" if DEBUG;

   if ($filename=~/\d{4}[_\: ]+\d{2}[_\: ]+\d{2}/){
      print STDERR "file $filename already named?\n" if DEBUG;
      next;
   }

   my $out =  `exiftool -DateTimeOriginal '$abs/$filename'`;
   chomp $out;

   unless( $out ){
      print STDERR " no out? $filename\n" if DEBUG;
      if ($o->{m}){
         File::Copy::move("$abs/$filename", "$abs/noout/$filename");

      }
      next;

   }
   $out=~s/^Date\/Time Original[\:\s]*//i;
   $out=~s/:| /_/g;

   unless( $out=~/^[\d_]+$/ ){
      print STDERR "dont like [$out]\n" if DEBUG;
      next;
   }   

   print STDERR "$filename : [$out]\n" if DEBUG;;

   rename("$abs/$filename", "$abs/$out\_$filename");
   print STDERR "moved to $abs/$out\_$filename\n" if DEBUG;  

}

=head1 OPTION FLAGS

   -m move to noout dir if cant get date

problems installing DBD::mysql

Saturday, January 12th, 2008

So I was doing a fresh install of my customized database api package for perl. LEOCHARRE::Database.
Goodly enough, my perl Makefile.PL let me know that I was missing DBD::mysql. Great.

I fire up cpan install DBD::mysql, and alas.. No go! How come??

Turns out you need to install mysql-client and mysql-devel.
I’m on a fedora core gui, so I use yum..

yum -y install mysql-client mysql-devel

Great.
Now let’s try cpan again..
cpan install DBD::mysql

It works better.. but oops.. still ..
2 tests skipped.
Failed 31/34 test scripts, 8.82% okay. 473/478 subtests failed, 1.05% okay.
make: *** [test_dynamic] Error 255
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force

What’s up?
I think the mysql server’s not running on this machine, thus, we need to install to make a full successful check via cpan.

yum -y install mysql-server

And then..
[root@localhost LEOCHARRE-Database]# /etc/init.d/mysqld status
mysqld is stopped
[root@localhost LEOCHARRE-Database]# /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
Ok

Great. Let’s try that cpan again..

cpan install DBD::mysql

Haha! It works! :-)