My Departement Of Nerdcore Enthusiasm

Tutorials and the like. Things which I have committed myself to. Often linux/UNIX-related.

onsdag den 11. juli 2012

To make 3g USB modem work on Android

++++++++++++
The Liberty Tab journey -reports from my process towards making a 10.1 inch tablet computer become my primary computer.
The product i use for this is a Packard Bell Liberty Tab G100. Please note that:
Packard Bell Liberty Tab G100
and
Acer Iconia A500 TAB
are identical products and that i will use the two product names synonymous.
++++++++++++

To make 3g USB modem (mobile broardband) work

Packard Bell Liberty Tab G100 comes with build in WI-FI but not with built in 3g modem (SIM Card) function. I wanted to use my 3g USB dongle modem (mobile broadband) to go on the internet. My 3G modem is a Huawei E1750.
The mobile broadband solution I have used for some years now in Linux as my everyday internet connection. I have several time spent some time to get it to the work under various Linuxes. Huawei E1750 and indeed all the various Huawei 3G modem are made in such a manner that they themselves have the drivers for eg Windows on board. The way it works is that when you first put the modem in the Windows computer the modem reports to the system as a CD-ROM containing the installation program. After installation is complete the installed software sends a signal to the modem that it must now change from being a CD-ROM to be a Modem. It is this shift operation which is causing some problems under Linux, and therefore also under Android (Android is Linux based). A German guy named Draisberghof has developed a Linux tool for this switching operation. This tool is called USB_modeswitch. All Android tablet computer that I know of are driven by a process type called ARM. Draisberghof have compiles a version of usb_modeswitch for the ARM processor.
. And he has compiled it STATIC. That is, he has compiled a version of usb_modeswitch that can run without any further dependencies on most android devices, smart phones, tablets, etc. Will need this version of usb_modeswitch for making the 3g modem work on our Android tablet. It can be downloaded from here.

http://www.draisberghof.de/usb_modeswitch/#download

Look for the text
"Upon a recent request I Provide a static binary for ARM: usb_modeswitch-1.1.9-arm static.bz2."
Under the Download headings on the page and download it.

I'll have to say now that before you can even do the following, you must first have installed a costume ROM on your device. The stuck ROM (also called firmwire) that ships with the Packard Bell Liberty Tab G100 does not support 3G USB modem. It does in fact not support USB devices at all. I will talk about the process of installing costume ROM in another post. For this post we'll assume you have already installed a costume ROM that supports 3G modem and that your tablet is rooted witch it will propel be if you have installed a costume ROM.

You need an android terminal for the next step. I have been very happy about a terminal called ConnectBot It's free (Android marked). But otherwise you can just use Terminal Emulator also from Android marked.

OK let's say you have downloaded usb_modeswitch-1.1.9-arm-static.bz2 to your PC. A easy way to get it on your tablet could be pulling the mini-sd-card out of the tablet. Putting it in a card reader on your PC. Add usb_modeswitch-1.1.9-arm-static.bz2 onto the card and put the card back into the tablet computer. So you need a good file manager. Astro (app) is good. (Total commandor app is even better). With your file manager find usb_modeswitch-1.1.9-arm-static.bz2 on external_sd. If you click and hold usb_modeswitch-1.1.9-arm.static.bz2 in Astro you can unpacks the bz2 archives and so you'll get the pure binary file usb_modeswitch-1.1.9-arm-static. usb_modeswitch-1.1.9-arm-static should now be maneuvered into a specific directory on your tablet PC for

/data/local

You can do this by opening your terminal

and then:

su

to become root

cd /data/local

and

cp /mnt/external_sd/usb_modeswitch-1.1.9-arm-static .

now you just make sure that usb_modeswitch-1.1.9-arm-static is executable

chmod 0755 usb_modeswitch-1.1.9-arm-static

Now you're actually ready to initiate your modem by giving a very long command to usb_modeswitch-1.1.9-arm-static. This command is so vast that it must be in a script if you want to use it many times and you must if you use this method.

You must therefore have made a small shell script which shall also be
/data/local/
The shell it self is nothing but a plain text file with a few lines of text in. The text lines are here.

--------------------------------------
#!/bin/sh
/data/local/usb_modeswitch-1.1.9-arm-static -v 0x12d1 -p 0x1446 -V 0x12d1 -P 0x1001 -s 20 -M "5553
4243000000000000000000000011060000000000000000000000000000"
--------------------------------------

How you'll make this small text file and gets it into
/data/local
I will leave it up to you for now. But when you have done it you must also make sure that it is executable

chmod 0755 mymodeswitch # or whatever name you gave your little script

You can now put your modem into the USB port on your tablet computer and then run your script

by typing
/data/local/mymodeswitch
in your terminal.
You can see what usb_modeswitch-1.1.9-arm-static "answer". If it finds a modem and it succeed with the switch operation it will answer that it succeeded.

If you have another Huawei modem than E1750 it may be you need another mode line. The mode line is the long number line that you can see the script text above.

Try to search google with your Huawei your-model usb_modeswitch

I had to even adjust some of the values to get to the values that i use here. Her the tool:

lsusb

Is a good help. Just tupe "lsusb" in the terminal and see what it says.

If you manage to switch your modem, you must have it set up in your Android system settings
as well.
Go to settings turn of WI-FI. Find the settings for mobile broadband. Enter or choose two pieces of information. Your access point and your network. It is in my case:

network: Telia
accespoint: websp

After that it worked for me.

Every time I turn on the tablet computer and wants to use internet will I open a terminal and execute my modem initiation script

su
/data/local/mymodeswitch

So it takes a few minutes when the modem initialize and connect and after this I'm ready to go on facebook and email and surf the Internet.

tirsdag den 6. december 2011

Zooming in a video clip

This script is a way to zoom into a video clip already recorded. In order for that to work one must be able to move the "focus" around through the progression of the video clip so that one can keep the focus around a certain object. The scripted in reality consist of two scripts "prunpre" a preperatons a script and "prunrun" a "run script" which treats 60 frames at a time.
The script vil run on a Unix environment: Unix, Linux, Mac OS X, Solaris, Free BSD, etc. You can even run it in Windows if you install cygwin. besides having a UNIX/Linux environment, there are also some basic software packages you must have installed on the system before this script can be used. That is:

FFmpeg (commandolinie Video conversion and editing)
Feh (Image viewer)
Netpbm (Toolkit for manipulation of graphic images)

Here is a video demo of the scripts in action.


Here are the scrips. You can right click and download or open and copy paste.

prunpre
prunrun

Once you have the script downloaded, you will probably also have to make them executable.
chmod +x prunpre
chmod +x prunrun

When you have the two scripts, create a directory where you put the two scripts and the video clip you want to zoom in on.
Then the video clip needs to be converted into a series of numbered ppm images (ppm is an image format) one image per frame in the video clip.
You do that with ffmpeg. Open an x-terminal of one kind or another and switch to the directory where you you have the video clip and the scripts. then give the command:

ffmpeg -sameq -i myvideo.avi myvideo%d.ppm

Where naturally myvideo.avi be replaced with the name of the video clips you want to work with.

Note this process can be pretty disk-space intensive.

You're then ready to run the first script. So in your X-terminal you type.
./prunpre basename (Followed by "enter")
where basename is the base name of the pictures you just printed out with ffmpeg. If the images are called.

img1.ppm, img2.ppm, img3.ppm, img4.ppm

then your base name is "img".

The script will guide you through the following steps. After prunpre the second script prunrun have to be executed, but prunpre will give a message about that when it has completed its process. The demo-video here above could also give a sense of how to use the scripts.

A more general note that is dealing not just with these two scripts but also the other scripts on this blog and my whole approach to this work:
The scripts here I make because I need them myself for a specific task, but somtimes I think they are really good and very configurable and so I try to adjust them so that others could use them too. It is also a kind of aesthetic pleasure to make things nice of comprehensible to others. But I think I apeal to a very limitation audience with these scripts and therefore there is no reason to come around every all aspects of adaptation and compatibility. I think of it this way: For instance this scripts would, easily be adapted to run on the terminal on a mac computer. Or the scripts could easily be change to work together with an other image viewer than "feh", but I do not know if anyone will ever need this so there is no reason to make all this ajustments. I’d rather you contact my if you have any special needs. I know the scripts and I could probably easy ajust them to your needs. My contact info is here ore you can do a comment on the blog post here.

Enjoy
Mikkel

mandag den 17. oktober 2011

Create scrolling move text from a pdf file

If you look around on this blog you can see that much of it is about being able to produce video effect without a fancy graphic video editing program. I find it fuzzy to work with these heavy video editing programs when I often sit and just have a small computer at my disposal. My scripts can produce a good result without me having to sit and pull elements in place with the mouse drag-and-drop in a graphics program. I can instead give a precise command from a commando line and then just wait to see the job gets done. This script can be slow to get through the process. The example of “rolling credits” shown here took about half an hour to process on my little ASUS eee pc. But in that time I am free to work on something else. That works fine for me.

This script creates scrolling text video clip like the rolling credits of a movie. It makes it out of a PDF or PS (PostScript) document. That is when you want to produce your rolling credits, you simply typing them into a word processing program like OpenOffice Writer or AbiWord, etc. and then save (save a copy or export) as a pdf (almost any modern word processor will do this). You should set the page size to A4 paper size. Top and bottom margin should be an inch with is equal to 2.54 cm. The spread of your document equals to the screen stretched so the distance you have between the text and the edges of the document corresponds to what you're going to see on the screen.  I have usede a Font Size of 20 points which I think is a good starting point but it is up to you. You can format text just like you would in your word processing system. Use black for the text and white for the background. Although the text is spread out over several pages in the word processing program try to imagine that it's just one long continuous text when you set it up. The resulting video clip is white text on black background. This concept can obviously be expanded so that the text will run over the "living pictures" in your video, but it leads too far now. The script is also currently limited to producing a video output in VGA format 640 x 480 pixels.

For this script to work you must have the following programs on your computer:

1. The scripted is a bash shell script so you must have a bash shell environment that you have on most Unix platforms. OS X, Linux (Ubuntu, Red Hat, puppy etc), Solaris, etc.

2. The basic program package Netpbm command-line based and script-based image processing.

3. Ghostscript (GS), the classic Gnu / open-source tool for PDF and PostScript handeling.

4. Ffmpeg a really nice strong basic commando line based film/video editing and conversion tool.

To run the script you must have opened a terminal window. Xterm Aterm.. whatever. Then, in your working directory you should have your PostScript file and the script. You give PDF or PostScript file as an argument to the script like this:

./rolling yourfile.pdf

and now it will take a while to produces a video clicp script with "rolling credits" out of your document.

The script is here. If you want to download it you can right-click and then choose save target as, or similar. Now make sure the script is executable. You can probably also do the right-click action or from a commando line with

chmod +x rolling

http://www.mimoart.ooz.dk/rolling

If for some reason would want to see the pdf file I've used as the basis for this video eksepel so it is here.

http://www.mimoart.ooz.dk/youare.pdf

tirsdag den 7. december 2010

Add subtitles to video clip with pure text (.srt) file


-----------------------------------
Note on revisit
On March the 14, 2013
When revisiting this poste I realized that people are actually reading this instruction. I also realize that the method I am advising for "burning" the subtitles to the video is no longer the method I would recommend. So in the bottom of this post I have added the method for burning subtitles that I use now.

-----------------------------------

I was pretty excited when I discovered that I could add subtitles to a video clip just by typing them into a plain text file on a very specific way. Save this file with extension .srt and then call it from my media player when playing the video clip. So I will just write about here.

You can see some specifications for the configuration of a subtitle file here:
http://www.matroska.org/technical/specs/subtitles/srt.html

Here is a extract of my .srt file:

1
00:00:04,000 --> 00:00:10,000
This little tech video was made during my
work making a slid show of my picture book:

2
00:00:11,000 --> 00:00:17,000
THE SILVER DOOR
-A Children's Book About Sex

3
00:00:18,000 --> 00:00:24,000
Inspired by some beautiful books from my
childhood. Books derived out of
Rudolf Steiner's impulse in pedagogy.

4
00:00:25,000 --> 00:00:31,000
It is a project I've been working on for many
years now. I started back in 2003 with drawings,
painting and writing

I am a Linux user and very happy with (CLI) mplayer (a very powerful media player).

So if I want to play my videos with sub-texts and I have a video clip called:

littledemo.avi

and a. srt (text file) called:

littledemo.srt

Then I can do this with the command:

mplayer -sub littledemo.srt littledemo.avi

Burn subtitles to video clip

Then I saw that you could also burn the subtitles into the video so it was a part of the video clip itself. It was a feature I wanted to use so I spent some time on how I could do this. In this solution I use mplayer to do it. Mplayer can save the stream in a special (raw) format, which in turn can be convert to a more "normal" and less bulky format with a program from a tiny package called mjpegtools. I had to install this little application package to my system in order to be able to run this process but that was peanuts and took only a moment.

And here is the commands I use to "burn" the subtitles off the .srt (pure text) file into my video clip:

mplayer -sub littledemo.srt -vo yuv4mpeg:file=yuv4mpeg.y4m littledemo.avi

Now, the finished file is, in yuv4mpeg.y4m. Now we send this file through mjpegtool program mpeg2enc. We use "cat" to send the file to "mpeg2enc" using a pipe (|).

cat yuv4mpeg.y4m | mpeg2enc-f 8-o littledemo.m2v

Then you have the video clip with the subtitles embedded in ordinary mpeg2 format.

And here is a little example video clip I med with this method:



love
Mikkel


Note on revisit
On March the 14, 2013

As I wrote at the top of this post the method to burn the subtitles into the video is no longer the one I would recommend. Today I do it with mencoder. Mencoder is a brother program for mplayer. Most often mencoder is packed with mplayer in distribution. Mencoder is for manipulating video and audio files. I will give here an example of a command I used when i "burn" srt subtitles in my videos to day with mencoder.

mencoder -utf8 -subfont-text-scale 3 -sub subtextfile.srt videofile.avi -o outputfile.avi -oac copy -ovc lavc

onsdag den 26. maj 2010

Anyone who wants to play with blue screen/green screen?

Chroma-key with netpbm

Attention:
The video that I made these technical solutions for is now finished and can be viewed on youtube http://www.youtube.com/watch?v=uRXsp7LZaDQ


"Chroma key compositing (or chroma keying) is a technique for compositing two images or frames together in which a color (or a small color range) from one image is removed (or made transparent), revealing another image behind it."

"It is commonly used for weather forecast broadcasts, wherein the presenter appears to be standing in front of a large map, but in the studio it is actually a large blue or green background"

en.wikipedia.org

http://en.wikipedia.org/wiki/Chroma_key




I made this because someone on ffmpeg list asked how it could be done and I it found interesting task. I work here with the low efficacy of a single image. Then I/we could go on the road to work on how to make it working with a fifo pipe so we can apply the effect on an entire video clip. (And you could also extend it to be in a moving background. A second video stream in the background).






This script requires some preparation. First and foremost, you must find your key color. The color you want to replace with an other image. Then you must produce the background image that will replace the background of the original image.

Find your key color.. the color that best represent background color. I divided the key color in to actually being tree colors, three nuances of the key color you could say, because such a back surface actually varies quit a lot in nuances due to light and shadows.

So you open your image/video frame in an imaging editing program such as eg Gimp. Use the color picker tool. Look at the image and see if you can find the lightest spot on that background surface and click it with the color picker tool. Than look at the color pallet and read the HTML code for the color.

This code looks for example like this.

5d67ac

for netpbm to understand it it must be rewritten so that it looks like this:

rgb:5d/67/ac

Now you'll find what looks as the darkest spot on that background surface and get the HTML code for that. And finally you find a spot on that background surface that could represent something in between the darkest and the lightest spot.



this three values have to be set in to the script on the place as you see here below.

Produce the new background image.

The new background image should have the same format (height and spread) as your original video/frame/image so it is a good idea to open your frame/image in gimp and then copy paste the new background image on top of the original image and then drag around with it and scaled up and down until the new background image is quite right in relation to the original image and then save it in the PNM format with a new name.

You can play around with the three key color and with the closeness percentage. The closeness percentages is sat at the top of the script as you can see when you look at the script text here below. It is the number that represents how tolerant the color selection should be a high percentages will include more color nuances and ad a low percentages will include less color nuances so if you find that the background "eats" up parts of the image that should not be part of the background you could choose i lower number and if you find that the background is insufficiently covered you could choose a higher number.

How to use the small script?:

1th Copy paste the text/script below to your editor.

2th Insert your three key color values.

3th Save it (pure text) as a file called "chroma" in your working directory, where you also have the image that you work with and the new background image that you have prepared.

4th Open a terminal (Xterm, rxvt, Aterm of your choice) in your working directory.


5th Make the script executable

type in the terminal window:

chmod +x chroma

6th execute the script

example:

./chroma bluebox.pnm substit.pnm

where bluebox.pnm is the name of my original image and substit.pnm is the name of the file that contains the background image that i wont instead of the background.

The script:

#!/bin/sh

#script needs two arguments of the original frame/picture and

#picture with the new background. Both in PNM format, eg

#./Chroma bluebox.pnm substit.pnm

#The three deferent levels of the key color. You have to fill in your values here
dark=rgb:1d/3b/77
middle=rgb:53/61/a2
light=rgb:7a/87/cd

closeness=13

ppmchange -closeness=$closeness $dark $middle $middle $middle $light $middle $1 >ret0tmp.pnm;
ppmcolormask $middle ret0tmp.pnm >alpha.pbm;
pamcomp -alpha=alpha.pbm $1 $2 >changed.pnm;
echo "the result is in the image file: changed.pnm"


With love

Mikkel

lørdag den 8. maj 2010

Crossfade two videos clips from a command line (CLI or term)

Attention:
The video that I made these technical solutions for is now finished and can be viewed on youtube http://www.youtube.com/watch?v=uRXsp7LZaDQ

Please start by scrolling all the way down to the bottom of this post and watch the little video that is there. It will make the understanding of all this much easier.

This script can crossfade two videos from a command promote (CLI or term) in UNIX / Linux / mac. With crossfade, I mean that the first movie clip slowly tones into the next.

This command produced the example videoclip clip at the bottom of this post
./crossfade clip-a.mpg clip-b.mpg 8

I have put out the script on my homepage as a pure text file you can view it. And copy / past it to your edit or you could right-click the link and choose to download (and rename it) to your computer.

Here is the link to the script:

http://mimoart.ooz.dk/crossfade.text

HOW TO USE THIS SCRIP?

There is, as always with computers several ways to do every single thing. In this little walk-through I have chosen a one way for the sake of giving a practical example.

1st Check that you have FFmpeg and Netpbm installed (and that you are on a UNIX platform (Linux, Mac OS X, Solaris, Free BSD, etc.))

2nd Create a working directory let's just here as an example call it:

/home/mikkel/project/mymove/crossfade/

to this directory copy the two video clips that you want to crossfade (they should be in mpg format and equal in height and spread)

3rd copy / paste the text / script from the link her above to your editor and save it (pure text) as a file called "crossfade" in the same catalog.

4th Open a terminal (Xterm, rxvt, Aterm of your choice) and "cd" to the above selected directory

cd /home/mikkel/project/mymove/crossfade/

5th Make the script executable

type in the terminal window:

chmod +x crossfade

6th Choose how slow you want the transition to go. It is done with the figure at the end of command (the third argument)

in my example the figure is 8

./crossfade clip-a.mpg clip-b.mpg 8

rule of thumb is that each unit is a little more than a second. In my example here I have chosen 8 which gives me about 9 seconds in transition, you can choose a maximum of 50 which gives about a minute fading

7th Yes it is just to execute the command. In my example i write:

./crossfade clip-a.mpg clip-b.mpg 8

in the terminal window (the script can actually run from a non-X-environment as well as an X-environment terminal).

I have also made other script that uses ffmpeg and netpbm that performs video producing and video editing tasks. E. g. one to zoom in an image. One to rotate a single frame as if it was on a turntable and spun around. One for fading video clip to black. One for enhancing contrast in a very dark image etc. I'd love to send these scripts and description if anyone wants. Just write to me

contact:

http://mimoart.ooz.dk/contact.htm

Below here is notes to explain in further details.

Dependencies:
To the script there are two programs to be installed on your computer. FFmpeg and Netpbm. Netpbm is very basic software and will almost always available on your Unix / Linux machine or be easy to install. FFmpeg is planned to be compiled befor installation on your system, but it can also be found in the pre compiled version at most repositories.

Advantages of this way of crossfading video clips.

- If you have a netbook like for instance Asus eee it is much easier to work with a command then with drag and drop of the mouse because of the small screen size.

- The script can run on a very law machine without it going dead. It just takes a little longer.

- Sometimes it's more comfortable and more precise to work with text commands instead of having to sit and fiddle with the mouse

- I am use to use FFmpeg and Netpbm so for me it is a big advantage that I am not going to teach me a graphic video editing program to create this effect.

- I've tried to do the same with Kdenlive (a good graphic video editing program) on the same PC and it took much longer to render than my script takes to process. So it is faster

- It gives a much better insight into what is going on in process.


Preparation of film clips to be crossfades:
Film clips must be in mpg format which is easily done with Ffmpeg such

ffmpeg -i orig.avi -sameq clip-a.mpg

and they must have equal size for example 320 x 240

which is also easy to do with FFmpeg for example:

ffmpeg -i a.mpg -sameq -s qvga clip-a.mpg

where "QVGA" is size declaration. "QVGA" stands for the size 320 x 240

Sound
I have in this process not crossfaded sound too. I have worked with images alone and put the sound on at the end but if some want I can help to add audio processing into the script.

What happens:
The actual transition takes place at the video clips transformed to single frames. The "pamcomp" program from Netpbm takes care of merging frames two and two with a transparency mask that determines how much one image should be visible through the other. I use 30 levels of fading if it is to be a long fading for example 20 seconds, these thirty levels just spread over several frames. When this overlay process is finished for all the selected frames FFmpeg turns the frames back to mpg video again.

Before this transition process can take place some lengths of video clips must be measured. If the video clips are long (more than one minuet) it should be divided before it is write out as single frames so there will not be too many unnecessary frames in the process. This cutting is done with ffmpeg -ss and -t command and general Unix shell commands sed, expr etc. Maybe some of you will wonder why I let the script convert video clip from mpg to avi before it is measured. That is because the mpg format is not easy to measure in because it doesn't contains meta data, eg the duration and the like. avi does contain this data.

Space:
It is clear that this script requires some space on your hard disk. It writes typically around 3.000 single frames in to png images and that take up some space. In most cases 2 GB is sufficient.