Tag Archive: playstation 3


  1. Run the converter on your media server: ps3_mp3_converter.pl -d {directory}
  2. Copy your mp3 collection wherever you told ps3_mp3_converter.pl to run in.
#!/usr/bin/perl

use strict;
use warnings;

use File::Basename;
use File::Find ();
use Getopt::Std;
use Linux::Inotify2;
use POE;

$|++;

#######################################
#######################################

our @found_dirs;

sub watch_add_dir {
 my ($heap_ref, $session, $dir_name) = @_;

 $heap_ref->{inotify}->watch($dir_name, IN_CREATE|IN_CLOSE_WRITE, $session->postback("watch_hdlr"));
 print " Watching directory $dir_name\n";
}

sub watch_hdlr {
 my ($heap_ref, $session, $event) = ( $_[HEAP], $_[SESSION], $_[ARG1][0] );

 my $name = $event->fullname;
 my $short_name = $event->name;

 unless ($_[HEAP]{inotify}{files}{$name}) {
  if ($event->IN_CREATE && -d $name) {
   print "New directory: $name\n";
   watch_add_dir($heap_ref, $session, $name);
  } elsif ($event->IN_CLOSE_WRITE) {
   my $ext = ( fileparse($name, ‘\..*’) )[2];

   if (lc($ext) eq ‘.mp3′) {
    print "-"x20 . "\n";
    print "$name:\n";

    my $cmd_output = `eyeD3 –to-v1.1 "$name"`;
    $cmd_output = `eyeD3 –remove-v2 "$name"`;
   }

   $_[HEAP]{inotify}{files}{$name} = 1;
  }
 }

 print "events for $name have been lost\n" if $event->IN_Q_OVERFLOW;
}

sub find_wanted {
 my $object = $File::Find::name;

 if (-d $object) {
  push @found_dirs, $object;
 }
}

#######################################
#######################################
#######################################

my %arg_options;
my $watch_dir;

getopts(‘d:’, \%arg_options);

if ($arg_options{d} && -d $arg_options{d}) {
 $watch_dir = $arg_options{d};
 File::Find::find({wanted => \&find_wanted}, $watch_dir);

 POE::Session->create
  ( inline_states =>
   { _start => sub {
     my $inotify_FH;

     $_[KERNEL]->alias_set(‘notify’);
     $_[HEAP]{inotify} = new Linux::Inotify2
      or die "Unable to create new inotify object: $!";

     foreach my $dir (@found_dirs) {
      watch_add_dir($_[HEAP], $_[SESSION], $dir);
     }

     $_[HEAP]{inotify}{files} = {};

     open $inotify_FH, "< &=" . $_[HEAP]{inotify}->fileno
     or die "Can’t fdopen: $!\n";

     $_[KERNEL]->select_read( $inotify_FH, "inotify_poll" );
   },
   inotify_poll => sub {
    $_[HEAP]{inotify}->poll;
   },
    watch_hdlr => \&watch_hdlr,
   },
 );

 POE::Kernel->run();
}

exit 0;

After much trial and error, I chose HandbrakeCLI for ripping a dvd to a h.264 mpeg4 file that I can play on my Sony Playstation 3 console. Please note that HandBrake does quite well on live action video but not so good on animation.

% sudo aptitude install build-essential
% sudo aptitude install zlib1g-dev jam yasm
% wget http://handbrake.fr/rotation.php?file=HandBrake-0.9.2.tar.gz
% tar zxvf HandBrake-0.9.2.tar.gz
% cd HandBrake
% ./configure
% jam
% cp HandBrakeCLI ../bin  # to copy the binary into the user’s bin dir

We need yasm installed to pick up any cpu extensions that our cpu supports. For example: MMX MMXEXT SSE SSE2 3DNow!

Now that we have a working HandBrakeCLI binary built for our system (works for 32bit or 64bit depending on which system we built it on).

I wrote a very simple script that will rip the dvd (legal dvd rip btw) into a mp4 file, copy it to the media-server which will be picked up automatically by mediatomb.

make_ps3_hb.sh:

#!/bin/bash

# make_ps3_hb.sh <video_name .mp4> [genre]

nice -n 15 ~/bin/HandBrakeCLI -i /dev/dvd -e x264 -b 1200 -B 160 -R 48 -E faac -f mp4 -P=16 -x level=41:subme=5:me=umh -T -2 -d -7 -8 -O –crop -m -N eng -o "$1"

if [ -f "$1" ]
then
  if [ $2 ]
  then
    echo copying $1 to media-server /home/jason/Videos/$2
    scp "$1" "jason@media-server:/home/jason/Videos/$2/$1" && rm -f "$1"
  else
    echo copying $1 to media-server /home/jason/Videos
    scp "$1" "jason@media-server:/home/jason/Videos/$1" && rm -f "$1"
  fi
fi</video_name>

Handbrake documentation is available on the Handbrake wiki website.

UPDATE: If you’re looking for a GUI front end for HandBrakeCLI on Linux, check out RippedWire by th3rmite.

Screenshot: HandBrakeGTK 1.0.1 - Queue Tab