You are not logged in.
Hello,
Original Problem:
My tv tuner, pvr-150, was giving me trouble running on any normal tv programs, apparently due to its encoder. I couldn't get it running in tvtime accordingly. Everything else that ran it had no support for switching channels at all. I could switch channels by command line and view/hear the current in another program. This was a lousy way to do things.
Original Solution:
I made bash functions to change the channel on my tv tuner within certain channel boundaries (I have channels 2-24) "up" and "down", and another called "channel" which switched to the specified channel. I later turned them into full scripts in /usr/bin (I prefer to keep things there even if not binary, sue me ) and gave the proper permissions.
Results & My New Problem:
They all work perfectly as bash aliases run from konsole. As scripts, "channel" works when run from krunner, ie krunner -> channel 3, but "up" and "down" do not work properly, which I need to use instead of console bash in order to cleanly bind them to keys on my keyboard.
Probable Failure:
The channel variable, CURCHANNEL, appears to not be read in correctly / changed when run as a script. It always stays at I think chan 24. I suspect I don't quite understand how these variables are saved/retrieved in console bash versus in a script.
So... :
Anyone know how to fix my understanding of this variable or think of an alternative method? I'd really like to change channels with my volUp/volDown keys on my multimedia keyboard that i never used anyway.
Referenced Scripts:
(Note1: The only difference between these and the bash aliases is the #!/bin/bash)
(Note2: I have CURCHANNEL=0 at the head of ~/.bashrc)
#!/bin/bash
CURCHANNEL=$(($CURCHANNEL+1))
if [ $CURCHANNEL -gt 24 ]; then
CURCHANNEL=2
fi
if [ $CURCHANNEL -lt 2 ]; then
CURCHANNEL=24
fi
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
#!/bin/bash
CURCHANNEL=$(($CURCHANNEL-1))
if [ $CURCHANNEL -gt 24 ]; then
CURCHANNEL=2
fi
if [ $CURCHANNEL -lt 2 ]; then
CURCHANNEL=24
fi
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
#!/bin/bash
CURCHANNEL=${@}
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
Thanks for any help
Last edited by FrozenFox (2009-01-13 14:29:07)
Offline
You need to export the curchannel variable to the environment after each script has run.
so
export CURCHANNEL
at the end of each script. You will then be able to use it in subsequent scripts.
hth
Offline
Sigh. I tried to do something similar earlier to no avail, and tried your suggestion with no luck. It does not appear to be working. I can export CURCHANNEL = whatever in a bash console and it works fine, but at the end of the up script, it does not change anything somehow. Curchannel never globally changes, but appears to do so locally as expected. The console output and up script as changed follow. I removed the CURCHANNEL stuff from ~/.bashrc as well just to be sure that wasn't messing anything up, didn't help. I also tried export before the curchannel+1 line, and to specify the whole value at the end of this script, etc, no luck.
Upon setting the last line to be curchannel=15, then viewing console output, it still shows 3, so it's clearly not even setting.
Apologies if I misunderstood something in your post.
fox@FoxDen ~/ $ up
Curchannel is 3
/dev/video0: 67.250 MHz (Signal Detected)
Switched to channel 4
fox@FoxDen ~/ $ up
Curchannel is 3
/dev/video0: 67.250 MHz (Signal Detected)
Switched to channel 4
#!/bin/bash
echo "Curchannel is $CURCHANNEL"
CURCHANNEL=$(($CURCHANNEL+1))
if [ $CURCHANNEL -gt 24 ]; then
CURCHANNEL=2
fi
if [ $CURCHANNEL -lt 2 ]; then
CURCHANNEL=24
fi
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
export CURCHANNEL
Last edited by FrozenFox (2009-01-13 13:39:57)
Offline
hmm... in that case, might be worth just recording the value in a .currentchannel file or something in your home folder, not sure why it's not working, I don't do a lot of bash scripting. You can then read and write the value with consistency.
Offline
EDIT: I've finished my scripts. I could probably combine them into one, but meh. Too lazy atm. Been doing this crap for long enough. I might do it another day, might not. For now, these seem to work okay.
Note: If your sound is crap, close mplayer and run the tvswitch [option] again.
Took your advice. It's messy, but I suppose it will work better for me in the long run, having my previous channel saved.
If anyone knows why the above variable stuff wouldn't work, feel free to post why (as I'm still curious), but my problem is "solved".
If anyone has pvr-150's, they may find these short scripts as helpful as me, so I will post them. Also, as soon as i figure out how to switch to composite or s video or whatnot, I will make a script for that too and tack it onto this same thread. That should be within a day or two, probably today.
The point of these versus default v4l/ivtv tools alone is 'tvswitch' will let you easily make the tuner unlagged (no decoder) for games in composite/svideo mode then switch back to tv mode with the mpeg2 decoder deal. The channel changer lets you go between a range, is easier to type n remember, and saves your channels from reboots n such.
NECESSARY FIRST STEPS:
1) mkdir ~/.tv
2) echo 3 > ~/.tv/curchannel
3) You need mplayer installed, a working pvr-150 (it might work, tweaked or not, with something else) set up n ready
Then the scripts should work okay:
CHANGE INPUTS: Tuner, Composite1, Composite2, S-Video1, S-Video2
#!/bin/bash
# Info:
# tvswitch
# Contributed by FrozenFox <frozenfoxz at gmail d0t c0m>
# Ver: 0.1.1a
# Usage:
# tvswitch tuner Switch to TV Mode on Last Used Channel, Lagged
# tvswitch composite1 Switch to Composite Video/Audio 1, Unlagged For Games
# tvswitch svideo1 Switch to S-Video 1, Unlagged For Games
# tvswitch composite2 Switch to Composite Video/Audio 2, Unlagged For Games
# tvswitch svideo2 Switch to S-Video 2, Unlagged For Games
# Assumptions:
# (May work otherwise with/without tweaks)
# Tuner: Hauppauge PVR-150 on /dev/video0.
# TV: US Cable / NTSC
# Run: mkdir ~/.tv
# Run: echo 3 > ~/.tv/curchannel
# Notes:
# Thanks to jdeslip for part at http://ubuntuforums.org/showthread.php?p=3299935 .
# See above for different video and audio settings you may want.
# No error-handling in-script.
# Can easily be bound to a key or shortcut for quick use.
# Untested beyond first two functions. Briefly.
# Please don't kill me for poor scripting :P.
# Take in cmd line choice
CHOICE=${@}
# Handle 5 possibilities: tuner, composite1-2, svideo1-2
case "$CHOICE" in
'tuner')
echo "Using Lagged TV-Tune 1"
v4lctl setinput "Tuner 1"
changechannel `cat ~/.tv/curchannel`
mplayer /dev/video0
;;
'composite1')
echo "Using Unlagged Composite 1"
v4l2-ctl -v width=720,height=480
v4lctl setinput "Composite 1"
aplay -q -f dat /dev/video24 &
mplayer -rawvideo format=hm12:h=480:w=720:fps=29.97 -nocache -demuxer 26 /dev/video32 -framedrop -vo xv
killall aplay
;;
'svideo1')
echo "Using Unlagged S-Video 1"
v4l2-ctl -v width=720,height=480
v4lctl setinput "S-Video 1"
aplay -q -f dat /dev/video24 &
mplayer -rawvideo format=hm12:h=480:w=720:fps=29.97 -nocache -demuxer 26 /dev/video32 -framedrop -vo xv
killall aplay
;;
'composite2')
echo "Using Unlagged Composite 2"
v4l2-ctl -v width=720,height=480
v4lctl setinput "Composite 2"
aplay -q -f dat /dev/video24 &
mplayer -rawvideo format=hm12:h=480:w=720:fps=29.97 -nocache -demuxer 26 /dev/video32 -framedrop -vo xv
killall aplay
;;
'svideo2')
echo "Using Unlagged S-Video 2"
v4l2-ctl -v width=720,height=480
v4lctl setinput "S-Video 2"
aplay -q -f dat /dev/video24 &
mplayer -rawvideo format=hm12:h=480:w=720:fps=29.97 -nocache -demuxer 26 /dev/video32 -framedrop -vo xv
killall aplay
;;
esac
# Leave a blank
echo ""
CHANGE CHANNELS: Up, Down, or Custom
#!/bin/bash
# Info:
# changechannel
# Contributed by FrozenFox <frozenfoxz at gmail d0t c0m>
# Ver: 0.1.1a
# Usage:
# changechannel X Moves to channel X
# changechannel up Moves to current channel + 1
# chanegchannel down Moves to current channel - 1
# Assumptions:
# (May work otherwise with/without tweaks)
# Tuner: Hauppauge PVR-150 on /dev/video0.
# TV: US Cable / NTSC
# Run: mkdir ~/.tv
# Run: echo 3 > ~/.tv/curchannel
# Notes:
# Wraps around to your lowest/highest channels
# for quick browsing without static
# channels if changed up/down (not custom).
# No error-handling in-script.
# Can easily be bound to a key for quick use.
# Not thoroughly tested.
# Please don't kill me for poor scripting :P.
# Custom channel range
MINCHANNEL=2 # The lowest channel you receive
MAXCHANNEL=24 # The highest channel you receive
# Resume and note previous channel
CURCHANNEL=`cat ~/.tv/curchannel`
echo "Started on channel $CURCHANNEL"
# Handle 3 possibilities: up, down, custom
case ${@} in
'up') # Increase channel
# Calculate next channel
CURCHANNEL=$(($CURCHANNEL+1))
# Wrap around channels if necessary
if [ $CURCHANNEL -gt $MAXCHANNEL ]; then
CURCHANNEL=$MINCHANNEL
fi
if [ $CURCHANNEL -lt $MINCHANNEL ]; then
CURCHANNEL=$MAXCHANNEL
fi
# Move to next channel
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
;;
'down') # Decrease channel
# Calculate previous channel
CURCHANNEL=$(($CURCHANNEL-1))
# Wrap around channels if necessary
if [ $CURCHANNEL -gt $MAXCHANNEL ]; then
CURCHANNEL=$MINCHANNEL
fi
if [ $CURCHANNEL -lt $MINCHANNEL ]; then
CURCHANNEL=$MAXCHANNEL
fi
# Move to previous channel
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
;;
[0-999]*) # Change to custom channel
# 'Calculate' desired channel
CURCHANNEL=${@}
# Move to custom channel
ivtv-tune -tus-cable -c$CURCHANNEL -d /dev/video0
echo "Switched to channel $CURCHANNEL"
;;
esac
# Make note of the new channel
rm ~/.tv/curchannel
echo $CURCHANNEL > ~/.tv/curchannel
# Leave a blank
echo ""
Last edited by FrozenFox (2009-01-13 18:44:54)
Offline
It is a little messier than you were hoping for, but having said that, you could alter your scripts now though so that it automagically reloads the same channel as you were watching before -1 for design goal +1 for added features
Offline
Indeed
Ty much.
Editing the original post to include a new script that will allow you to specify what port to switch to (tuner,composite1,svideo1,composite2,svideo2). I have no idea if anything but the first 2 work properly or at all, and have no interest in testing them, but it should work fine.
Offline