Wednesday, December 31, 2008

Converting videos to play on the Sony Ericsson P1i

All the playing around with transcoders for the Creative Zen got me thinking about watching videos on my Sony Ericsson P1i. It has roughly the same size and resolution screen as the Zen, although probably less colours, and a even more limited video player.

First I tried using transcode, but quickly learned that the P1i video player likes 3GP files, which use MPEG4/H.263/H.264 for video, and AMR/AAC for audio. Both of these codecs have license/patent issues, which means they aren't built into your usual rpm files.

I then found this blog post and was inspired to try using ffmpeg. The vanilla rpm on my aspire one didn't include aac/amr, so I gave source building a try.

Install SVN, and checkout the source for ffmpeg
sudo yum install svn
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

Install amr and faac codecs
sudo yum install amrnb amrnb-devel
sudo yum install faac-devel

Configure and make ffmpeg
./configure --enable-libfaac --enable-libamr-nb --enable-nonfree
make

Convert avi file to 3gp
./ffmpeg -i /mnt/nas/somebody.avi -s qcif -vcodec h263 -acodec libfaac -ab 128000 -y somebody.3gp

Copy to phone, and play
cp somebody.3gp /media/PHONE\ CARD/video/

it works!
I found that the player couldn't handle resolutions other than qcif (176x144). More experimentation is required to see what else it can handle.

I've read that H.264 would be worth trying, and perhaps the audio rate I'm using is an overkill. This post also is interesting.

Still, I'm not that sure I actually want to watch video on the phone... so perhaps I'll just end here :)

Happy New Year!

Sunday, December 28, 2008

libmtp #2

To give libmtp a fair chance I downloaded the lastest released version, compiled and installed it, and retried. I must say the process went smoothly -

./configure
make
sudo make install
./hotplug.sh

(it seems the fedora 8 rpm for libmtp is very old... still I'm avoiding moving from linpus on the aspire one... I was however impressed yesterday by a fedore 10 vmware image... hmm.. q-emu on linpus perhaps?)

The updated mtp-sendtr now prompts for meta-data which is nice. I found giving an empty album name resulted in a seg fault... however, after being more forth-coming with meta-data, it worked!

Starting program: /usr/local/bin/mtp-sendtr u2.avi u2.avi
libmtp version: 0.3.3

PTP: Opening session
u2.avi,u2.avi,(null),(null),(null),(null),(null),(null),00,0,0
Sending track u2.avi to u2.avi
type:avi,8
Title> U2
Album> U2
Album artist> U2
Artist> U2
Writer or Composer> U2
Genre> rock
Track number> 1
Year> 2004
Length> 228
Sending track:
Codec: Audio Video Interleave
Title: U2
Album: U2
Album artist: U2
Artist: U2
Writer or Composer: U2
Genre: rock
Year: 2004
Track no: 1
Length: 228
Storage ID: 0
Sending track...
Progress: 25604828 of 25604828 (100%)
New track ID: 94879
Album doesn't exist: creating...
success!
PTP: Closing session

Program exited normally.

The length I found using
[user@localhost ~]$ tcprobe -i u2.avi
[tcprobe] RIFF data, AVI video
[avilib] V: 29.970 fps, codec=XVID, frames=6856, width=320, height=240
[avilib] A: 44100 Hz, format=0x55, bits=16, channels=2, bitrate=128 kbps,
[avilib] 6856 chunks, 3659103 bytes, CBR
[tcprobe] summary for u2.avi, (*) = not default, 0 = not detected
import frame size: -g 320x240 [720x576] (*)
frame rate: -f 29.970 [25.000] frc=4 (*)
audio track: -a 0 [0] -e 44100,16,2 [48000,16,2] -n 0x55 [0x2000] (*)
bitrate=128 kbps
length: 6856 frames, frame_time=33 msec, duration=0:03:48.761

and simply converted it to seconds.

Perhaps I should give gnomad2 another try, with a later release of libmtp.

Creative Zen, libmtp, gnomad2

Today I've encountered a number of bugs (and unexpected features)... mostly whilst trying to get fast forward, rewind and duration to work on video files transferred to the Creative Zen. After spending a number of hours trying to re-encode the video files with different tools, switches and the like - some heavy googling revealed that the problem might lie with the method I was using to transfer the files onto the device!

A quick test, using Windows to transfer the files instead of Linux + libmtp showed that the transfer method was the problem. MTP is Microsoft's Media Transfer Protocol, and unfortunately (for me) it allows meta-data to be sent 'out of band', ie. not relying on the data embedded in the media files being transferred. The duration of a video clip is one such piece of metadata, and the Zen apparently relies on this metadata when seeking in a video file.

libmtp comes with an (example) tool 'mtp-sendfile' which I'd been using, as well as a 'mtp-sendtr' which perhaps is more appropriate, as it allows meta-data to be specified. Unfortunately it doesn't handle .avi files in the release I have at least.

In the process, of investigating the above, I managed to 'corrupt' data in the Zen, such that it thought all the videos on it were gone. A reboot of the device resolved this.

I then found a blog post http://tiagoboldt.net/blog/creative-zen-linux/ indicating that gnomad2 handles the meta-data correctly. It uses libnjb to communicate with the device (I'm not sure if this is a layer above mtp or beside). Unfortunately it behaved badly on my machine, crashing with a seg-fault, and leaving the Zen hanging.

libnjb is beautifully documented via doxygen, so perhaps I'll read up more on it, and even do some coding to get a working solution :)

Friday, December 26, 2008

Dependencies and video transcoding

Well it seems that I'd made one of the great Fedora no-nos and enable yum repositories for both livna and freshrpms.

This led to the problems below, whilst trying to install transcode -
ffmpeg-libs-0.4.9-0.42.20071121.lvn8.i386 from installed has depsolving problems
--> Missing Dependency: libx264.so.56 is needed by package ffmpeg-libs-0.4.9-0.42.20071121.lvn8.i386 (installed)
Error: Missing Dependency: libx264.so.56 is needed by package ffmpeg-libs-0.4.9-0.42.20071121.lvn8.i386 (installed)

I found an explanation here -
http://linux.derkeiler.com/Mailing-Lists/Fedora/2008-01/msg04547.html

And resolved it by disabling the livna repo, then -
[user@localhost ~]$ sudo yum erase ffmpeg-libs
This was installed from livna, and then re-install my video utilities from freshrpms -

[user@localhost ~]$ sudo yum install transcode
[user@localhost ~]$ sudo yum install dvdrip

[user@localhost ~]$ sudo yum erase libdvbpsi
[user@localhost ~]$ sudo yum install vlc

I was then able to reencode and resize videos for the Creative Zen as follows -

[user@localhost ~]$ transcode -i /mnt/nas/Music\ Videos/input.mpg -y xvid4 -o test.avi -Z 320x240 -w 768,100
(Transcode takes a plethora of options which probably need tweaking... that I'll try to get back to some time)

Connecting to the Creative Zen requires MTP (Media Transfer Protocol), so -

[user@localhost ~]$ sudo yum install libmtp libmtp-devel libmtp-examples

[user@localhost ~]$ mtp-sendfile test.avi test.avi

And surprisingly enough... it works!

Tuesday, December 23, 2008

Merry Christmas


I've been working hard, learning JDBC and enjoying coding for the last few days... but now it's time to relax, eat and enjoy the Christmas break.

Merry Christmas

and let's hope it's bug-free :)

Monday, December 15, 2008

Annoying touchpad?

Whilst workable, the touchpad on my Aspire one always seemed way too sensitive, and it would keep scrolling the screen when I didn't want it too.

Eventually I tired of it... went into the settings, reduced the sensitivity further, and disabled the scrolling function. Problems solved :)

Embarrassingly simple!

Tuesday, December 2, 2008

autofs #3

Ok, I weakened... again this isn't a pretty solution, and it seems NetworkManager is becoming my friend...

[user@localhost ~]$ cat /etc/NetworkManager/dispatcher.d/03-autofs
#!/bin/sh
if [ "$2" = "up" ]; then
AUTOFS=/etc/init.d/autofs

if [ ! -x $AUTOFS ]; then
exit 0
fi

$AUTOFS start > /dev/null
fi