27 December, 2009

Embedded MPlayer in Tk

Ok, something a bit more interesting.

I've been using mplayer since 'bout 94 (near as I can recall), it's has been and continues to be my video player of choice. In spite of that, I still learn things now and again. Today was an instance of learning a little something about it I didn't know before.

Mplayer supports a slave mode, this was news to me. In that mode it is geared to receive commands to manipulate the player. The intention is to allow the creation of front-ends which are plentiful for that reason. I found this especially useful in embedding Mplayer into a Tk window and binding Tk controls to the player.

Below is a rough sampling of how it can be done.


#!/usr/bin/tclsh
package require Tk

proc Exit { } {
exit
}

proc Play { } {
upvar #0 playerId playerId
puts $playerId "pause"
}

proc ReadPipe {chan} {
upvar #0 playerId playerId
set d [read $chan]
foreach line [split $d \n] {
set line [string trim $line]
if {[regexp {^\*\*\* screenshot '(.*?)' \*\*\*} $line -> filename]} {
# delay to permit the file to appear
after 250 [list OnScreenshot $filename]
}
}
if {[eof $chan]} {
fileevent $chan readable {}
close $chan
set playerId ""
}
}

proc EmbedPlayer { w } {
upvar #0 fileList fileList
upvar #0 playerId playerId
set cmd mplayer
lappend cmd -slave -vf scale=1540:1050 -wid [winfo id $w] -idle

set pipe [open |$cmd r+]
fconfigure $pipe -blocking 0 -buffering line
fileevent $pipe readable [list ReadPipe $pipe]
set playerId $pipe

puts $playerId "load [lindex $fileList 0]"
set fileList [lrange $fileList 1 end]
}

proc main { { fileList [list]} } {
wm title . "User Interface"
wm protocol . WM_DELETE_WINDOW [list Exit]
wm withdraw .

frame .video -width 1540 -height 800
grid .video -sticky news

frame .controls -width 1540 -height 100
button .play -text "Play" -command Play
grid .play -sticky news

grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1


option add *tearOff false
. configure -menu [menu .menu]
.menu add cascade -label File -menu [menu .menu.file]
.menu.file add command -label Exit -command Exit
bind .video {
bind %W
{}
EmbedPlayer %W
}
wm deiconify .
}

#---main---
set fileList $argv
main


I stripped this segment out of a more involved utility I'm working on so it isn't as clean as it could be.

Issue ./mplayerUi and Bobs Your Uncle.

Playing Video On Desktop

I've been screwing around with MPlayer for a bit today. Specifically, I was trying to configure it to display on the desktop rather than a movable window.

I found a couple things worth noting:
1) if you don't have hw support you won't be able to apply it to your background nor scale it. Check for xv support by issuing the 'xvinfo' command. I found I didn't have the proper driver configured and therefore had to tweak my xorg.conf
2) The required command to scale the video up (in my case) isn't intuitive.

I had success with the following command:


$ mplayer -vf scale=1024:720 -rootwin DesiresAndDiversions.mpg


Cheers.

Diamond Radeon HD 3450 X Configuration

Spent some time today playing with Mplayer. Got stuck applying the video to the root window because I didn't have xv support enabled. As a result, did some Googlin' and had to reconfig my xorg.conf; attached.


$ cat /etc/X11/xorg.conf
Section "Monitor"
Identifier "Configured Monitor"
EndSection

Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 24
EndSection

Section "Module"
Load "glx"
Disable "dri2"
EndSection

Section "Device"
Identifier "Configured Video Device"
Driver "fglrx"
EndSection

Section "DRI"
Mode 0666
EndSection

Section "Extensions"
Option "Composite" "Enable"
EndSection

26 December, 2009

Text-to-Speech

It's been quite some time since I've authored a post. Been busy at work and haven't found too much time to find new things to play with.

I did however take a little time over Christmas to rattle on the keyboard. I found a text-to-speech utility that proves promising to play with.


# apt-get install espeak


Then, simply run it.


$ espeak "hello, how are you doing?"


Easy, peezy.

22 November, 2009

Playing On-Line Station Streams

I have a couple of my favorite radio stations here in the twin cities that I enjoy listening to. Trouble is since 99% of the world is Windoze users they tend to author their streaming links to the masses. I found that you can play the audio streams from these stations by issuing the proper commands.

93X KXXR-FM

$ mplayer http://citadelcc-kxxr-fm.wm.llnwd.net/citadelcc_KXXR_FM


92 KQRS

$ mplayer http://citadelcc-kqrs-fm.wm.llnwd.net/citadelcc_KQRS_FM

20 November, 2009

Mplayer Dvd Audio

I've been burning DVDs like I have for the past couple years. Until recently I've not had any issues playing them back, but the latest discs have had trouble playing.
The audio track seems to be defaulted to commentary, which is at best annoying.

I found how to change the audio channel by playing with mplayer using the following:


$ mplayer dvd://1 -alang en


Cheers.

06 October, 2009

Quick-n-Dirty CD Replication

Assuming you have a CD that isn't copy protected sometimes you want to replicate it without user interface based tools....the command line.

Real quick, but you can replicate the disk contents by generating an ISO image by issuing the command:

dd if=/dev/sr0 of=PingBootDisk.iso


This assumes the CDROM is mounted at /dev/sr0, you can establish the device by issuing the 'mount' command and examining the file systems.

Next, use cdrecord; the trick again is to establish the device. Isolate the device by issuing the following command:

cdrecord -scanbus


Then burn the disk ISO image by issuing the following:

cdrecord -v dev=1,0,0 PingBootDisk.iso