Friday, January 14, 2011

Extracting frames from a live stream

Many times, downloading and saving a stream locally is not an option. For example if the stream is a live stream. If you need to extract frames from a stream like this, you need to do it on-the-fly.

A good tool for dumping media content streamed over rtmp is rtmpdump and a good tool for extracting frames from a video is ffmpeg. Luckily for us those two can be piped together, since rtmpdump by default dumps the streamed media content to standard output and ffmpeg provides the option to read the input from a pipe.

To extract one frame per second from a stream try something like this:
rtmpdump -r <rtmp_video_url> | ffmpeg -i pipe:0 -r 1 frame%05d.jpg

Tuesday, March 09, 2010

nVidia and Slackware-Current

A week ago slackware-current got a huge update and one of the things that were updated was the kernel. Kernel 2.6.33 intr0duced a new nvidia driver: nouveau, which resulted by reverse-engineering the official driver I think. The problem is that out of the box, at least for now, neither nouveau, nor the official nvidia driver are runnable on the system.

For nouveau, the Xorg that is included with slackware-current does not contain the needed xf86-video-nouveau driver.
You can download and compile this, but you need to find the suitable for your nouveau kernel module and this is not the latest from the nouveau repository:

git://anongit.freedesktop.org/git/nouveau/xf86-video-nouveau/

You could of course download the latest pair of kernel and xorg driver and this should work, but for now, I decided to stay with the official driver from nvidia. Two problems arise here. First the nouveau driver is loaded automatically in the boot process when the hardware is probed and it is conflicting with the official nvidia driver. Second, the latest nvidia driver 190.53 does not compile with kernel 2.6.33.

In order to overcome the first problem you'll probably need to blacklist the nouveau module, or unload it every time before starting X-Window. You cannon directly unload nouveau and it's dependencies using rmmod. You have to unbind the nouveau frame buffer first. See here for more info.

Anyway, blacklisting the modules is easier. Simply append this:
blacklist drm
blacklist ttm
blacklist nouveau
to /etc/modprobe.d/blacklist.conf and the old vga console driver will run the next time you boot the system.

For the latest nvidia driver (190.53) you need first to apply the patch found here:
nvidia-betasam-2.6.33.patch.txt

You can apply a patch like this:
sh ./NVIDIA-Linux-x86-190.53-pkg1.run --apply-patch nvidia-betasam-2.6.33.patch.txt

This will create a new file: NVIDIA-Linux-x86-190.53-pkg1-custom.run with the patched driver, which is compatiple with kernel 2.6.33.

Wednesday, January 28, 2009

Download kde4 from slackware-current

This is a script to mirror the kde4 packages from slackware-current. For now, those packages works for slackware 12.2 too.

The script may be executed multiple times from the same directory. It will detect the changes made in the repositoty, it will remove the obsolete local files and will only download the newer files that are not present in the local copy.

#!/bin/sh

# Copyright 2008-2009 Nikos Skalkotos, Athens, Greece
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


server=ftp://ftp.ntua.gr
url_path=pub/linux/slackware/slackware-current/testing/packages/kde4
url=$server/$url_path
dirs="deps extragear kde kde3-compat kde-l10n"
files="remove-kde3.sh remove-kde4.sh"

if [ "$1" = "--clean" ]; then
echo -n "Cleaning up..."
rm -fr $files $dirs
echo "done"
exit 0
fi

remove_obsolete() {
echo "Checking local directory \"$1\" for obsolete files..."
(cd $1
for i in `ls`; do
exists=`echo "$2" | grep $i`

if [ $i != "" -a "$exists" = "" ] ; then
echo "Removing file: $1/$i"
rm -f $i
fi
done
)
}


for filename in $files; do
#Those are small scripts, so I'll download them every time
rm -f $filename
wget -c $url/$filename
done

for dir in $dirs; do

#I need to create the dir the first time
mkdir -p "$dir"

echo
#Clean old files no longer listened in the repository
echo -n "Listing kde4/$dir content..."
dir_content=`curl -sl $url/$dir/`
echo "done"
remove_obsolete $dir "$dir_content"

#Now mirror the directory
(cd $dir; wget --mirror -nH -nd $url/$dir/)
done

Sunday, January 25, 2009

Youtube watch in normal/high quality

Anybody noticed the watch in normal/high quality link that is present in the bottom right corner of some videos in www.youtube.com?

The funny thing is that in some videos where the streaming delays while watching it in normal quality, it works perfectly in high quality. The only thing I could assume is that the videos are stored in high quality and are converted to normal quality on-the-fly instead of being stored in both formats.

This makes the option pretty useless.

Tuesday, April 08, 2008

Bit Operations: round a number to a next multiple of a power of 2

This is easier than the last bit operation post. By the way, I would like to thank "LOLmachine" for the comments - improvements in the last bit operation post....

Anyway...Multiples of a power of 2 share the property that have at least a fixed number of digits zero in the least significant position. So, all multiples of 2 have the 1 first bits zeroed, all multiples of 4 have the 2 digits zeroed, etc.

In order to round a number (x) to the next multiple of "a", where "a" is a power of 2 all you need to do is to compute this:

round(x) = (x + (a-1)) & ~(a-1)

SO, if a is 8, the above formula looks like this:

round(x) = (x + 7) & ~7;

round(14) = (14 + 7) & (~7) = 16
round(16) = (16 + 7) & (~7) = 16
round(17) = (17 + 7) & (~7) = 24

Monday, March 17, 2008

multiple gcc versions in Slackware 12.0

Slackware's default compiler nowadays is gcc-4.1.2. If you need an older compiler from the 3.x series, then you may use the one from the pasture directory of the distribution.

The problem is that you cannot have them both, because the two packages have files with the same name. So, if you try to use installpkg to install the older compiler the installer will overwrite some gcc-4.1.2 files.

Fortunately, you don't need to compile gcc by your self. Eric Hameleers (alien bob) maintains an unofficial slackbuilds repository hosted in slackware. There is a gcc package: http://www.slackware.com/~alien/slackbuilds/gcc34/ which is compatible with the official one.

Sunday, January 06, 2008

latex and footnotes

In latex if you have a footnote and a figure with b (bottom) placement attribute on the same page, then the figure will be placed under the footnote. The result is really ugly....

I was searching for a way to fix this. Of course the straight-forward solution is to use the h (here) attribute in the figure and put the figure's code in the position you want, but this is not the best thing to do.

Well.. there is a way to force the footnotes to be always placed at the bottom of the page. You can do this by using the footmisc-package. By using this package you can change the default typesetting of footnotes. If you include the line:
\usepackage[bottom]{footmisc}
in latex preamble you get the desired footnotes behavior.

Thursday, January 03, 2008

Bit Operations: find first zero bit

If anybody cares here is an algorithm to find the first zero bit in a number:
  1. Invert the number
  2. Compute the two's complement of the inverted number
  3. AND the results of (1) and (2)
  4. Find the position by computing the binary logarithm of (3)
e.x.
For the number 10110111
  1. 01001000
  2. 10111000
  3. 01001000 AND 10111000 = 00001000
  4. log2(00001000) = 3
But in a x86 processor environment there is a more simple way to do this since Intel provides a specific assembly instruction for this purpose called bsfl. This instruction return the position (index) of the least significant bit set to 1 in a 32-bit word. By using inline assembly, someone can easily create a function that finds the first zero bit by inverting a number and feeding it to this instruction. For 8-bit numbers, the code for this in gcc would look like this:
/*
* find the position of the first 0 in a 8-bit array
*/
inline unsigned short find_first_zero(uint8_t bit_array)
{
unsigned pos = 0;

__asm__("bsfl %1,%0\n\t"
"jne 1f\n\t"
"movl $32, %0\n"
"1:"
: "=r" (pos)
: "r" (~(bit_array)));

if (pos > 7)
return 8;

return (unsigned short) pos;
}

Wednesday, December 05, 2007

forkbomb

have you ever seen this:
:(){ :|:& };:

This is a bash fork bomb.

It's the same as writing:

func()
{
func | func&
}

func

but it looks a lot more cryptic.

Thursday, May 10, 2007

Matlab R2007b ugly bug

Just installed the latest Matlab software on my Slackware 11 PC and after using it for less than 120 seconds it crashed. I tried to replicate the conditions under which matlab crashed and it was really easy. In matlab's main window in the menu I went to File->Preferences... and in the Preferences window just pressing Fonts in the left navigation bar was enough to crash Matlab.

It must have been a java related thing, because I managed to fix it by just updating matlab's java jre. OK, well here is a solution:

  1. Download java's latest jre and select the Linux (self-extracting file).
  2. Extract the jre: "sh jre-6u1-linux-i586.bin". This will create a jre1.6.0_01 directory. I did not want to update slackware's java. I leave mr. Volkerding to do that for me :). Matlab comes with a local copy of jre and this is what is used by default unless the MATLAB_JAVA enviromental variable is set to point to an external jre directory when $MATLAB_ROOT/bin/matlab script is executed. The matlab's local copy of java is under $MATLAB_ROOT/sys/java/jre/glnx86, at least for the linux x86 version.
  3. I copied the jre1.6.0_01 directory there and updated the jre.cfg file of the directory with the new jre version "echo jre1.6.0_01 > jre.cfg". The old version was 1.5.0.
  4. I also removed the old jre directory: jre1.5.0 but this is optional.
After this everything worked fine.
Happy "Matlabing"

Wednesday, November 01, 2006

Mplayer rc1

Mplayer entered in rc state. It must have been more than 2-3 years it was on a pre-release state.
I guess 1.0pre8 must have been the last pre-release version.
8 pre-releases is not that much... Links 2.1 is in pre-release 23 :)

Monday, May 29, 2006

slackware-current and TV-Card

Ok, After having for years a TV Card hooked on one of my motherboard's PCI slots and never using it I decided to configure it and make it usable. My card is an old PixelView PV_BT878P+ (REV .9F) card with a TPI8PSB02D tuner on it, or at least that what it is printed on the tuner :).

It wasn't hard at all. I just open /usr/src/linux-2.6.16.18/Documentation/video4linux/CARDLIST.bttv and the most relative card values for my case were:
16 -> Prolink Pixelview PlayTV (bt878)
37 -> Prolink PixelView PlayTV pro
50 -> Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP
70 -> Prolink Pixelview PV-BT878P+ (Rev.4C,8E)

For the tuner I opened /usr/src/linux-2.6.16.18/Documentation/video4linux/CARDLIST.tuner and since I couldn't find the exact model I tried those values:
tuner=28 - LG PAL_BG+FM (TPI8PSB01D)
tuner=29 - LG PAL_BG (TPI8PSB11D)

To make the modules load correct through hotplug I just created a new file in /etc/modprobe.d/, I named it v4l with those options in it:

# i2c
alias char-major-89 i2c-dev
options i2c-algo-bit bit_test=1

# bttv
alias char-major-81 videodev
alias char-major-81-0 bttv
options bttv card=70 radio=1 tuner=28

card=70 and tuner=28 gave me the best result I think. The signal is a lot weaker than the one I have on my TV and if I remember correct it's also weaker than the one I had in windows years ago, but at least the card works. I use tvtime as a TV application.

What exactly is the problem? the card, the modules, tvtime, me?

Tuesday, April 11, 2006

strange problem with Greek subtitles in mplayer

Ok, a few days ago, I compiled mplayer again, using the source from the CVS this time. Everything seems to be fine, until I discovered a really strange problem when displaying greek subtitles in avi movies.
The Greek were sort of inverted horizontaly.
Instead of displaying:
"Τι κάνεις" it looked more like "ςιενάκ ιτ".
English were displayed fine, so "Τι κάνεις John" looked like "ςιενάκ ιτ John".

I tried using a windows arial.ttf font with the same results. What I had to do is keep the font encoding to Modern Greek (ISO-8859-7) but change the Subtitle encoding in Subtitle & OSD tab to Western European Languages with Euro (ISO-8859-15). I don't know why but after doing this it worked.

Thursday, March 30, 2006