I recently decided to copy some of my FLV (Flash Video) collection to my LGU990 Viewty mobile phone [1]. I was inspired by the ffmpeg cheat sheet [2].
deb http://www.coker.com.au lenny selinux-mm
Firstly I installed the version of ffmpeg that comes from the Debian-Multimedia repository [3]. Then I spent about an hour getting it to build with some patches to not require text relocations. The change involves putting --disable-mmx in the CONFIG_OPT setting for i386 and patching rgb2rgb.c to not compile MMX code. I’ve put the packages in the above APT repository.
My first attempt was to produce AVI files similar to the ones that my Viewty makes when it saves a video. ffmpeg -i file.avi displays the file details, which includes mpeg4 video and mp3 audio. By default ffmpeg creates AVI files that use mp2 audio and my phone doesn’t like them. I tried using “-acodec libmp3lame” which gave a file that (according to ffmpeg) had the same encoding as files produced by my phone, but my phone didn’t accept them. I eventually gave up and used mpeg4 which worked without any problem. I never had a reason to desire AVI files, it just seemed likely that the easiest format would be the one that the phone uses to encode the videos it creates – obviously a bad assumption.
Just use MPEG4 for a Viewty phone!
One of the videos I tried causes various parts of the phone to crash. It would crash the preview screen (which shows icons of the videos), and crash the player after playing for a couple of seconds. Crashing the player caused a soft-boot of the phone (it restarted and asked for my PIN code). I expect that anyone who was suitably motivated could create a hostile mpeg4 file that can exploit a Viewty.
The next problem I had was that most videos had a blank icon for the preview. It seems that the Viewty uses the first frame as the icon which doesn’t work well for videos that fade in, as such videos comprise a large portion of my collection that is a problem. The solution to this problem is to take 100ms of video from later on in the flv file and prepend it to the start. The ffmpeg FAQ has some information on how to do this [4], it involves converting the data to a format that can be concatenated and then converting it back. It’s rather ugly, it would be good if someone added a feature to ffmpeg to support multiple -i options.
I used the below Makefile to convert all the flvs in my collection to mp4 format in a subdirectory named “mp4“. I used a Makefile for this so that I can just run “make” whenever I add more flvs to my collection, and “make -j2” to use both cores of my Opteron CPU. It takes 0.1 seconds of data from 20 seconds in the video and appends the entire video to that. It creates two pipes for the temporary data which tends to be about 30* larger than the source flv file.
MP4S:=$(shell for n in *.flv ; do echo $$n | sed -e s/^/mp4\\// -e s/flv$$/mp4/ ; done)
all: $(MP4S)
mp4/%.mp4: %.flv
mkfifo $@.aud $@.vid
sh -c "(ffmpeg -ss 20 -t 0.1 -i $< -vn -f u16le -acodec pcm_s16le -ac 2 -ar 22050 – ; ffmpeg -i $< -vn -f u16le -acodec pcm_s16le -ac 2 -ar 22050 – ) > $@.aud &"
sh -c "(ffmpeg -ss 20 -t 0.1 -i $< -an -f yuv4mpegpipe – ; ffmpeg -i $< -an -f yuv4mpegpipe – ) > $@.vid &"
ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 22050 -i $@.aud -f yuv4mpegpipe -i $@.vid -y $@
rm $@.aud $@.vid
Using ffmpeg without MMX optimisations is fracking slow!
Please do not use the ffmpeg packages from debian-multimedia.org. Since you are already patching the sources, you should consider taking the master.unstripped branch from the ffmpeg git repository in alioth[1]. This way it is less likely that your ffmpeg libraries (libavcodec and friends) have binary incompatibilities with the debian packages (in case you end up for some reason with the debian ffmpeg binary but libavcodec/libavformat are from your repo). Marillat does not build packages in the same way as Debian does, which has caused problems of this kind in the past.
[1] http://git.debian.org/?p=pkg-multimedia/ffmpeg-debian.git;a=summary
http://etbe.coker.com.au/2008/09/12/fixing-execmod-textrel-problems-in-lenny/
nine: Performance doesn’t appear to be THAT bad, the results of tests on my EeePC 701 seemed good enough, see the above URL.
http://etbe.coker.com.au/2008/09/11/execmod-and-se-linux-i386-must-die/
Using untrusted data from the network with libraries that reduce the protections against buffer overflow attacks is a bad idea. See the above URL for more detail.
Felipe: I find that the Debian-Multimedia project releases good packages. The only problem I have had was due to a mirror that linked “lenny” to “unstable”… If you want to do video things involving mobile phones then you end up being forced to deal with “3gp” files, and that forces you to use the Debian Multimedia packages.
The master.unstripped branch creates packages that are identical to the official Debian ones, but with all the encoders enabled. Marillat’s packages have in the past contained libraries with the same SONAME but a broken ABI. Which causes problems if you have other applications coming from Debian that link with said libraries (mplayer, for example).