Archive for the ‘posix’ Category

how to join avi movies

Sunday, January 20th, 2008
mencoder -oac copy -ovc copy ./file1.avi ./file1.avi -o ./out.avi

That example may not place keyframes in- (you know how you use the arrow keys in mplayer to forward or rewind?)
For an example that would put in keyframes:

mencoder file1.avi file2.avi -oac copy -ovc lavc -o out.avi

For closer together keyframes:

mencoder file1.avi file2.avi -oac copy -ovc lavc -o out.avi -lavcopts keyint=5

This would change your output quality.

If you get an audio encoding error, you may have to choose an audio codec..

mencoder file1.avi file2.avi -oac pcm -ovc copy -o out.avi

If you don’t want to deal with keyframes, simply use the -forceidx option when you play the movie

mplayer -forceidx ./out.avi

What is mencoder?

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

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! :-)

Linux On A Dell Inspiron 600m

Sunday, January 6th, 2008
dell inspiron 600m

This is a review. Not a hints and tips sheet.

OVERALL VERDICT : HOT
(more…)

how to deskew an image

Monday, January 29th, 2007

OVERVIEW

First thing you need is a way to figure out what the skew angle is.

unpaper 0.2

I tried using ‘unpaper’ v 0.2

But for some reason no matter how much I fumbled with the settings.. I could not get it to detect a skew.

pagetools 0.1

The next thing I tried was something called ‘pagetools’
http://sourceforge.net/projects/pagetools/
The current version for that is 0.1 (as of this writing).
You can see them on http://sourceforge.net/projects/pagetools/

This version has no real installer per se, you unzip, untar, and then
where you extracted you run ‘make’.
The following is an example of how you would go about doing this.
This may fail on your machine- use your head and don’t dispair.
(as root..)

	cd ~/
	mkdir tmp
	cd tmp
	wget http://downloads.sourceforge.net/pagetools/pagetools-0.1.tar.gz?use_mirror=internap
	gunzip pagetools-0.1.tar.gz
	tar -xvf pagetools-0.1.tar
	make

And likely get an error about missing pbm.h
WHY! Because this is provided by another package.
I did a yum search

	yum provides pbm.h

And got some results. Then chose what to install..

	yum install netpbm-devel

Great. Then I did a ‘make clean’ to wipe my previous make try..

	make clean

Now run the make again..

	make

And.. and?? What happenned??
What happened is if you look in pbm_findskew/pbm_findskew , this binary is what
was compiled for you.

Try the sucker out.

Imagine you have a skewed.png image..
(assuming you habe imagemagick installed on your system)

	convert skewed.png skewed.pbm
	./pbm_findskew/pbm_findskew skewed.pbm

Output is something like ‘0.839234′
Great. Now.. Use that value to fix your original

	mogrify -rotate "-0.839234" skewed.png

Why minus - ? Because pbm_findskew tells you how many degrees counter clockqise you must
rotate to get it straight.

Check it out.

	eog skewed.png

Conclusion

You could script this together pretty easy with perl/bash.
I was doing this originally to prep stuff for gocr. But.. I think the quality of the rotated
image is not as good for ocr reaing as the original!! Weird- but makes sense.

installing par2 par2cmdline on fedora core 4

Wednesday, December 20th, 2006

This is a great linux command line application that lets you repair creat etc par2 file.

Background: If you make massive downloads online a lot of your data can be missing. PAR2 is a
way of creating .. let’s call them.. ’semi backup files’ for those of us with lesser intelligence. (me).

You maye have seen downloads for things like movies on usenet, and some of the files are all screwy. But
still you see people saying things like ‘just par2 the suckers..’ and you scratch your head and .. anyway.

If you got here you probably know what par2 is and you are having PROBLEMS COMPILING on a 64bit machine!
this is that it may look like:

reedsolomon.cpp:54: error: explicit specialization of ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::SetInput(const std::vector<bool, std::allocator<bool> >&)’ must be introduced by ‘template <>’
reedsolomon.cpp:54: error: template-id ‘SetInput<>’ for ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::SetInput(const std::vector<bool, std::allocator<bool> >&)’ does not match any template declaration
reedsolomon.cpp:54: error: invalid function declaration
reedsolomon.cpp:83: error: explicit specialization of ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::SetInput(u32)’ must be introduced by ‘template <>’
reedsolomon.cpp:83: error: template-id ‘SetInput<>’ for ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::SetInput(u32)’ does not match any template declaration
reedsolomon.cpp:83: error: invalid function declaration
reedsolomon.cpp:104: error: explicit specialization of ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::Process(size_t, u32, const void*, u32, void*)’ must be introduced by ‘template <>’
reedsolomon.cpp:104: error: template-id ‘Process<>’ for ‘bool ReedSolomon<Galois<8u, 285u, unsigned char> >::Process(size_t, u32, const void*, u32, void*)’ does not match any template declaration
reedsolomon.cpp:104: error: invalid function declaration
reedsolomon.cpp:192: error: explicit specialization of ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::SetInput(const std::vector<bool, std::allocator<bool> >&)’ must be introduced by ‘template <>’
reedsolomon.cpp:192: error: template-id ‘SetInput<>’ for ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::SetInput(const std::vector<bool, std::allocator<bool> >&)’ does not match any template declaration
reedsolomon.cpp:192: error: invalid function declaration
reedsolomon.cpp:236: error: explicit specialization of ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::SetInput(u32)’ must be introduced by ‘template <>’
reedsolomon.cpp:236: error: template-id ‘SetInput<>’ for ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::SetInput(u32)’ does not match any template declaration
reedsolomon.cpp:236: error: invalid function declaration
reedsolomon.cpp:270: error: explicit specialization of ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::Process(size_t, u32, const void*, u32, void*)’ must be introduced by ‘template <>’
reedsolomon.cpp:270: error: template-id ‘Process<>’ for ‘bool ReedSolomon<Galois<16u, 69643u, short unsigned int> >::Process(size_t, u32, const void*, u32, void*)’ does not match any template declaration
reedsolomon.cpp:270: error: invalid function declaration
make[1]: *** [reedsolomon.o] Error 1
make[1]: Leaving directory `/tmp/par2cmdline-0.4'
make: *** [all] Error 2

The problem is the file reedsolomon.cpp , it’s got a problem when you try to compile with gcc 4.0

Open up the magic tool and cure for all the problems in the univers: vim , and edit reedsolomon.cpp
Run this command (after pressing ‘Esc’ and ‘:’ (which puts you in command mode ))

:%s/^bool ReedSolomon/template <> bool ReedSolomon/g

save the file, run make again and it should compile

linux ext3 inode questions

Tuesday, August 15th, 2006

inodes , ext3

I wanted to index files partly based on inodes. I wanted to store metadata on files. Why work with inodes?

  • While users play with filenames, the system doesnt care about names. The inode is the most important thing.
  • if you rename a file, the inode stays the same.
  • No matter where you 'move' the file, the inode stays the same.
  • The inode table is recorded on that filesystem, on that volume. Inode stays the same on mount, umount.. on any machine that reads ext3.

Possible problems.

Copying a file loses all sense to the system. That is , a copy of a file is to the system - a completely different data collection- however to the user it is the same.

Jane copies 'family fotos' from disk a to disk b- In Jane's mind, these are the same. In the computer's mind, these might as well be jane's photos and the blue prints to the whitehouse. How do we keep metadata associated?

Netgear MA401RA works with fc4

Sunday, June 18th, 2006

linux kernel 2.16
Fedora Core 4 distro
IBM Thinkpad 600E
PII 366Mhz
198m memmory
5.6g hd.

The date is June 06- no, this is not a prehistory document. This is really one of my work computers. It is sturdy, beautiful, has great review all over the net from geeks and hackers. The CD drive is bust, the battery is dead, I love it.

I spent a long time looking for a card that would work with my laptop. I found one, last night it worked. It still works.
It’s a Netgear MA401RA, which is different then a netgear ma401.

It works. I had to fc#x with it, but.. It’s really something. A linux laptop with a wireless connection.