Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Sunday, January 9, 2011

XBMC and NVidia's TwinView

I was looking for a decent media center - mostly to watch movies with an overhead projector connected to a PC. The PC is running Linux and I would like to be able to select a movie, change the volume, pause etc with my Medion (read: cheap, RF, USB connected) remote. One day I stumbled upon XBMC. It turned out to be a decent piece of software. Configuring the remote was easy. But...

I must mention here that my display setup uses the NVidia's TwinView, which serves me well. My main LCD monitor is connected through a D-Sub while the beamer via HDMI. They form a dual-screen setup with the beamer on the right of the LCD.

But there is always a catch... Actually two of them.
  1. XBMC's fullscreen ignores TwinView, so it spans both displays, or the other display is turned off. 
  2. There is video tearing visible while XBMC is running on the beamber, there is no tearing if it runs on the LCD.
The first issue can be fixed by making XBMC use so-called windowed mode. It appears as a window then. Having a window and using wmctrl it is possible to make it look like fullscreen.
The second issue regard configuring the NVdia in a proper way which makes OpenGL sync to the specified display instead of the first one. It can be achieved by exporting two environment variables __GL_SYNC_TO_VBLANK=1 and __GL_SYNC_DISPLAY=name_of_the_display_to_sync_to.

So here comes my magical bash script which launches the XBMC with a proper syncing enabled and shifts it to the beamer making the window fullscreen (mind that the beamer is on the right of the LCD, and the LCD is 1280x1024).

Enjoy.
#!/bin/bash

move_and_fullscreen(){
  NAME='XBMC Media Center'

  while [ -z "`wmctrl -l | grep \"$NAME\"`" ]
  do
      sleep 1
  done

  wmctrl -r "$NAME" -e '0,1280,-1,-1,-1'
  wmctrl -r "$NAME" -b toggle,fullscreen
}

move_and_fullscreen &
__GL_SYNC_TO_VBLANK=1 __GL_SYNC_DISPLAY_DEVICE=DFP-0 SDL_VIDEO_ALLOW_SCREENSAVER=0 exec xbmc

Update: As of XBMC 10.1 I had to add SDL_VIDEO_ALLOW_SCREENSAVER=0 to disable screensaver while running XBMC. The above approach uses the windowed mode of XBMC which enables system screensaver now - it kicks in while watching movies :( (the screensaver is disabled in the fullscreen mode only).

Monday, November 15, 2010

Linux and a newborn.

Have you ever tired to put a newborn to sleep? It's tough. However it seems that linux can do it for you - actually it works pretty good for my son. Just turn the volume up and issue:

while true ; do cat /boot/vmlinuz-2.6.32-25-generic > /dev/dsp ; done

Good luck.

Sunday, September 5, 2010

Command line might: useful aliases; BASH tips

I'm a command-line-guy I guess. I use a terminal quite often (mostly with BASH), either for file management, or while working on my projects, just to launch proper application, and optionally to make it read some contents from a given file.

I found myself using quite often two particular functions:
  1. searching for a file which name contains a keyword, and
  2. figuring out what files I recently modified in the current directory.
These two functions can be easily written down as:

ls -l | grep -i some_keyword
ls -lt | head

Right, but since I use them quite often and being rather lazy I wouldn't want to type these every time... So here come aliases.
You can define an alias for a command you often type and use it instead.  So I decided to define two aliases: lsg and lst for searching for a file name containing a keyword and displaying the recently modified files respectively.

So if you type at your command prompt:

alias lsg='ls -l | grep -i'
alias lst='ls -lt | head'

From now one you can use lsg and lst freely.

If you want to make the change permanent you could add the above lines to your ~/.bashrc file, so the aliases would be accessible any time you log in.

Oh one more thing... how to use it.
If I want to find out what files I modified recently in the current directory I just type:

$ lst

and it gives me a list of recntly modified files. If I'm looking for a file which name contains a keyword "book" I issue:

$ lsg book

And I get a list of files which names contain "book" (case insensitive). It's quite useful - at least for me.

PS. Dont forget about: cd -
It will bring you up to the directory you were previously in.


Monday, August 30, 2010

Home DVD, non interlaced

This nice tiny DVD camera of mine captures footage which turns to be interlaced... While it is nice while watching on a TV, it turns to be at least annoying to watch on a computer. There are some so called comb (or mouse teeth) artifacts which annoy a lot. Of course many video players can deinterlace video on-the-fly however it turns that they do that with very different results especially concerning overall video quality.

So I poked around and it seems that one of the nicest deintralcers available is compiled into MPlayer. It is called yadif. So it's really easy to use. I fidlled with some settings for a while and ended up with a command as follows:

mencoder source.mpg -of mpeg -mpegopts tsaf:format=mpeg2:muxrate=30000 -noskip -vf yadif -o dest.mpg -oac copy -ovc lavc -lavcopts vcodec=mpeg2video:mbd=1:aspect=16/9:vbitrate=9100

It turns a file called source.mpg into a nice deinterlaced dest.mpg.

Tuesday, March 2, 2010

Pausing music when switching users in Ubuntu (Karmic and Lucid)

If you want to have a user, which currently uses the display, to have access to the sound device with all the benefits from pausing upon user switch, you need to uncheck 'Use audio devices' privileges for this user (System->User Settings->Advanced->User Priviledges).

As a matter of fact I unchecked it for all my users. These privileges are very confusing then. I guess their proper interpretation is that if:
- checked: the user locks the audio device as long as he wants, no sound switching upon user switching,
- unchecked: the user which currently uses the display has access to the audio device, sound switching takes place upon user switching.

The problem is more general and it regards permissions to access certain devices (and files in /dev directory). Historically if a user needs access to particular device he is assigned to a group which group-owns the device file. It has worked for ages in the unix world i.e. access to an audio device, cdrom, cd burner etc.

This group based approach has several well known limitations. Now it seems that such an access is controlled by consolekit/policykit/udev, which makes some sense, at least because of the dynamic nature of /dev directory. The gnome-system-tools and especially users-admin seem not to know anything about acl. I'm not sure whether it's good or bad - it depends, espoecially that gnome is cross platform - on other systems /dev might be static or there might be no acl at all.

See  https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/433654 for more details.
And some discussion here: http://ubuntuforums.org/showthread.php?t=1420051

Mind that the sound switching worked fine in previous Ubuntu release (Jaunty).

Thursday, January 21, 2010

Medion X10 remote and Linux

I've recently bought a remote for my PC. I thought it would be quite convenient to have one especially that it could be quite handy during watching DVDs.

I picked an inexpensive, radio operated, USB Medion X10 - around $10.

After plugging the USB dongle it turned out that the remote becomes a HID - dobling the keyboard. It was nice but not exactly what I needed. I want to have a remote control for my multimedia pplications - not to control the computer.

So here comes the magic word LIRC: Linux InfraRed Control.  It's a little bit misleading since the remote has nothing to do with InfraRed, but LIRC is actually an infrastructure which allows to control applications with remote controls. So I installed lirc:
apt-get install lirc
Upon configuration I selected ATI/NVidia/X10 RF Remote, and voila... the remote stopped working as a HID. Now I need to comeup with proper configurations for my multimedia applications. Here comes a complete config file /etc/lirc/lircrc I came up with:

begin
    remote = Medion_MD8800
    prog = xine
    button = DVD_Menu
    config = RootMenu
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Up
    config = EventUp
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Down
    config = EventDown
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Left
    config = EventLeft
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Right
    config = EventRight
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Vol_Up
    config = Volume+
    repeat = 1
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Vol_Down
    config = Volume-
    repeat = 1
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = OK
    config = EventSelect
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Mute
    config = Mute
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Info
    config = OSDStreamInfos
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Rewind
    config = SeekRelative-15
    repeat = 1
    delay = 5
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Play
    config = Play
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Forward
    config = SeekRelative+15
    repeat = 1
    delay = 5
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Pause
    config = Pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Power
    config = Quit
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = xine
    button = Stop
    config = Stop
    repeat = 0
    delay = 0
end

begin
    prog = Rhythmbox
    remote = *
    button = Play
    repeat = 1
    config = play
end

begin
    prog = Rhythmbox
    remote = *
    button = Pause
    repeat = 0
    config = pause
end

begin
    prog = Rhythmbox
    remote = *
    button = KEY_PLAYPAUSE
    repeat = 1
    config = playpause
end

begin
    prog = Rhythmbox
    remote = *
    button = Stop
    repeat = 1
    config = stop
end


begin
    prog = Rhythmbox
    remote = *
    button = Next
    repeat = 0
    config = next
end

begin
    prog = Rhythmbox
    remote = *
    button = Prev
    repeat = 0
    config = previous
end

begin
    prog = Rhythmbox
    remote = *
    button = Rewind
    repeat = 1
    delay = 5
    config = seek_backward
end

begin
    prog = Rhythmbox
    remote = *
    button = Vol_Up
    repeat = 5
    config = volume_up
end

begin
    prog = Rhythmbox
    remote = *
    button = Vol_Down
    repeat = 5
    config = volume_down
end

begin
    prog = Rhythmbox
    remote = *
    button = Power
    repeat = 1
    config = quit
end

begin
    remote = Medion_MD8800
    prog = totem
    button = DVD_Menu
    config = play_dvd
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Power
    config = quit
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Up
    config = up
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Down
    config = down
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Left
    config = left
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Right
    config = right
    repeat = 0
    delay = 0
end

begin
        prog = totem
        remote = Medion_MD8800
        button = OK
        repeat = 1
        config = select
end

begin
        prog = totem
        remote = Medion_MD8800
        button = DVD_Menu
        repeat = 0
        config = menu
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Vol_Up
    config = volume_up
    repeat = 5
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Vol_Down
    config = volume_down
    repeat = 5
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Mute
    config = mute
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Back
    config = quit
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Info
    config = show_playing
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Rewind
    config = seek_backward
    repeat = 1
    delay = 5
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Play
    config = play_pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Forward
    config = seek_forward
    repeat = 1
    delay = 5
end

begin
    remote = Medion_MD8800
    prog = totem
    button = Pause
    config = pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Power
    config = quit
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Up
    config = seek +60 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Down
    config = seek -60 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Left
    config = seek -6 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Right
    config = seek +6 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Vol_Up
    config = volume +1
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Vol_Down
    config = volume -1
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = OK
    config = pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Mute
    config = mute
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Rewind
    config = seek -30 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Play
    config = pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Forward
    config = seek +30 0
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Pause
    config = pause
    repeat = 0
    delay = 0
end

begin
    remote = Medion_MD8800
    prog = mplayer
    button = Stop
    config = quit
    repeat = 0
    delay = 0
end

Mind that it enables remote control for xine, rythmbox, totem and mplayer (rythmobox, and totem must have the lirc support enabled to work, see Edit/Plugins). Enjoy.

Making a nice home video DVD

Video source: a Sony handycam (DCR-SR36) which produces mpeg/2 files.

Anticipated result: a nice DVD with rich menus.

How to do it?

First, I don't want to recode the movie clips, since it would degrade their quality. So I decided to use the mpegs straight from the video camera. If there is a need to clip such a video there is a nice tool to do that: avidemux.

There is also another nice tool for DVD authoring: DVDStyler - you can create a DVD menu interactively, add/rearrange clips etc. However it seems that it takes a great deal of time to come up with nice designs.

So I stumbled upon tovid. It's a bunch of scripts which allow to author a DVD in a non-interactive way, just generating appropriate menus, thumbnails etc. And here comes a bummer.... It turned out that there the mpegs from the videocam are not 100% compatible with the DVD format, and they require ... well not recoding but remuxing (remultiplexing). In order to do that I use a buch of commands:
ffmpeg -i $1 -vcodec copy -an -f rawvideo foo.mpv
ffmpeg -i $1 -vn -acodec copy -f mp2 foo.mp2
mplex -f 8 -o $2 foo.mpv foo.mp2
rm foo.mpv foo.mp2
Actually its a script, its good to save the above contents as an executable file, let's say: mpgfix, and then run it:
mpgfix file.mpg file-fixed.mpg
So file.mpg is remuxed and saved as file-fixed.mpg. You can save the file with the same name of course, then the original one will be replaced with the remuxed one. Mind that there is no quality loss here, no recoding.

And here comes the nice part DVD authoring, I just launch one of the tovid scripts (todisc):
todisc -loop 0 -chain-videos -menu-length 2 -thumb-shape normal -aspect 16:9 -menu-title "My DVD" -pal -files *.mpg -titles *.mpg -out DVD
And after a while in the DVD directory there is a complete authored DVD :) with nice animated menus. You can generate an ISO image out of it:
mksiofs -dvd-video -o dvd.iso DVD/
And you'll get a file dvd.iso which is a complete ISO image ready to burn. Enjoy.

Friday, December 11, 2009

Screen for X11

Finally!!! I think I found a key application I've been searching for.... some time. Basically it is like GNU screen for X11 :)
Take a look at it: http://code.google.com/p/partiwm/wiki/xpra

It is also available in Ubuntu, just:

apt-get install xpra

From its description:
Xpra gives you "persistent remote applications" for X. That is, unlike normal X applications, applications run with xpra are "persistent" -- you can run them remotely, and they don't die if your connection does. You can detach them, and reattach them later -- even from another computer -- with no loss of state. And unlike VNC or RDP, xpra is for remote applications, not remote desktops -- individual applications show up as individual windows on your screen, managed by your window manager. They're not trapped in a box.

Thursday, December 10, 2009

Gnome Workspace Switcher and managing (moving) windows.

I have a dual-head setup (NVidia TwinView) where the second screen is an overhead projector. I would find it extremely useful if I could just drag windows using the Workspace Switcher between my screens. This would help a lot especially at times when the projector is blanked or switched off and I would like to move some windows to be projected when switched on/unblanked.

Beware... tadaaaaa...Since yesterday windows can be dragged not only to a different workspace (without altering their relative position) but also within the workspace. I made a modification to libwnck (the library which implements the pager and allows to manipulate windows) which implements this feature and submitted it upstream. I wonder if it is going to be committed to the next Gnome release or not... we'll see.

Anyway you you would like o use this functionality in Ubuntu 9.10 Karmic Koala, here is a link to my PPA: https://launchpad.net/~wojnicki/+archive/ppa

And if you want to compile libwnck by yourself you can find the appropriate patch at the feature request: https://bugzilla.gnome.org/show_bug.cgi?id=604207

Wednesday, November 4, 2009

Enabling laptop VGA output

The following commands enable VGA output (works presumably with any XOrg driver, tested with several ATI Radeon cards). It is especially useful if you want to make your laptop work with a projector connected with a damaged or long cable.
xrandr --newmode 1024x768N 108.0 1280 1328 1440 1688 1024 1025 1028 1066 +hsync +vsync
xrandr --addmode VGA-0 1024x768N
xrandr --output LVDS --mode 1024x768
xrandr --output VGA-0 --mode 1024x768N
The first command adds a new 1024x768 (60Hz) video mode and names it: 1024x768N. The second command assigns the video mode to the VGA port (VGA-0). While the third and fourth commands switch the LCD display (LVDS) to 1024x768 mode and the VGA port to the newly created one respectively.