Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to make a script that at a certain time will tune my tv tuner, start recording, keep recording for a certain amount of time, then stop. I can do the following from console:
This works, but the problem is the only way i know of to stop it is to hit control c. Also, I need a way to launch the script at a certain time. For example, if i want to record a half hour show that starts at 8pm, the script needs to auto launch at 8, run for exactly half an hour, then stop. Anyone know how to do this?
I've written 2 scripts which might be of use to you.
The first one (tvguide.py) is only really useful in australia, as it scans an australian site for tv programs you're interested in and updates your crontab to record them by calling tvrecord.sh
tvrecord.sh looks a bit similar to the previous poster. It will certainly need rework to make it do what you want, but it's probably worth looking at.
Partly because I'm lazy and have to go to work in a sec I'm going to just point you to my repo. This silly forum code won't let me insert a URL directly so you'll have to build it:
http s colon-slash-slash geheimdienst.no-ip.org slash svn/media
If you have any questions I'll be happy to answer them. If you want to post bits of my scripts that's fine, but I didn't want to post large scripts in a forum unless they're actually useful.
Just a few words:
- I use sleep instead of at to get the recording length right
- I have to first dump the stream directly from /dev/dvb/... for some reason. It might be something about my card.
- I've been experimenting with a few different modes. For example, some transmissions aren't 16/9 but just 4/3, but the dvb stream pads them with black.
If you want to test out tvguide.py for any reason, try pasting this into a file (e.g. programs.lst) and running:
tvguide.py --cron --listing programs.lst
Code:
doctor who, priority=4, fudge=-20, narrowscreen
south park
ali g, narrowscreen
the office, fudge=-20
cnnnn
new inventors, channelmatch=ABC2
speaking in tongues, duration=1510, fudge=0, priority=3
glass house, channelmatch=ABC2,fudge=-90
world news, fudge=0, priority=6, hourmatch=21, duration=1745, method=1PASS
I'm happy to explain how any of this works, but only if it's useful to someone.
Thanks a lot for the excellent replies! Here's the script I ended up with.
Code:
#!/bin/bash
if [ $# == 0 ] || [ "$1" = "-h" ] ; then
echo "Usage: $0 channel duration"
exit 1
fi
ivtv-tune -c $1 -d /dev/video0
cat /dev/video0 > rec.mpg &
CATPID=$!
echo "Recording started, Process ID is $CATPID"
RECMINS=$2
RECTIME=$((RECMINS * 10))
sleep $RECTIME
kill $CATPID
echo "Recording complete, process $CATPID terminated"
I was surprised how picky bash is about little syntax issues like where you can put spaces. What are the advantages of using mencode instead of cat? Does it make a smaller filesize? Is it practical to use mpeg4 encoding (like divx or xvid) on a realtime stream like this if I have a fast computer?
nicois I'm still interested in your tvlistings script because if that australian site gives the listings in xml format, it shouldn't be hard to adapt it to work with zap2it labs, which gives listings for many countries including canada. I'll check out your site.
I use mencoder because my TV card's an old WinTV PCI effort which output YUV raw(ish) video. The files are about three times larger than full quality DVD standard MPEG. Not nice.
I also don't get any audio if I just cat /dev/video0.
mencoder uses about 50% processor time on an Athlon 2500+ when it's recording, so you could probably reliably get away with a 1.8GHz P4 or equivalent.
have you thought of using a mythbox? Not sure of all the necessities for it to work, but it looked pretty nifty on the show that gave a brief overview of how to set it up. I can, however, see the promise in using your own script...
You might want to consider storing your mpeg on some seperately mounted filesystem if you're not doing that already. That way, if for some reason your script gets accidently killed while in it's sleep, you won't end up recording into infinity and running yourself out of disk space in some critical filesystem. You might also set a backup for your sleep/kill algorithm. Right before your sleep statement add an "at" command to also do the kill one minute AFTER the sleep/kill should have already gotten it. Just some extra insurance.
Thanks a lot for the excellent replies! Here's the script I ended up with.
What are the advantages of using mencode instead of cat? Does it make a smaller filesize? Is it practical to use mpeg4 encoding (like divx or xvid) on a realtime stream like this if I have a fast computer?
nicois I'm still interested in your tvlistings script because if that australian site gives the listings in xml format, it shouldn't be hard to adapt it to work with zap2it labs, which gives listings for many countries including canada. I'll check out your site.
I use mencoder for a couple of reasons - but I first dump the raw (mpeg2) stream to disk. This means that I don't depend on mencoder to keep up with real-time, and lets me end up with much smaller files - the DVB stream is fine if you want to burn what you captured to DVD or watch it on that system, but I stream it across a wireless network which can't keep up with 6000bit quality. Not to mention the files take a lot less disk space.
Quote:
Originally Posted by sureshot324
nicois I'm still interested in your tvlistings script because if that australian site gives the listings in xml format, it shouldn't be hard to adapt it to work with zap2it labs, which gives listings for many countries including canada. I'll check out your site.
The tvguide program doesn't act on XML unfortunately. It's a bit of a mess, partly because it was one of the first python scripts I wrote, but also because the tv site isn't even valid HTML, let alone XML. I've ended up using regular expressions and a state machine to identify the right values.
Having said that, I think it's only one method which generates a dict (aka map) of properties for each tv program to record - so you could use the rest of the script to update your crontab etc, if you liked.
ps: my uplink is a bit saturated at the moment - my apologies if you have trouble accessing my svn repo.
You might want to consider storing your mpeg on some seperately mounted filesystem if you're not doing that already. That way, if for some reason your script gets accidently killed while in it's sleep, you won't end up recording into infinity and running yourself out of disk space in some critical filesystem. You might also set a backup for your sleep/kill algorithm. Right before your sleep statement add an "at" command to also do the kill one minute AFTER the sleep/kill should have already gotten it. Just some extra insurance.
NOTE: That's just pseudo-code on the "at" command above, you'll need to look up the syntax, I forget the exact syntax at the moment.
What would happen if I used the space on my partion? Obviously the cat command would run into an error, but Linux has it's own swap partion so it would still run fine wouldn't it? And i could just delete the mpeg file. My Linux partition is only 15gb and all my windows partitions are ntfs so they are not writeable from linux.
What would happen if I used the space on my partion? Obviously the cat command would run into an error, but Linux has it's own swap partion so it would still run fine wouldn't it? And i could just delete the mpeg file. My Linux partition is only 15gb and all my windows partitions are ntfs so they are not writeable from linux.
yes, but when your root partition fills up and /tmp becomes unwritable, you're in a world of pain.
At the very least you want one partition for media/home and one for the system. Use lvm if you want extra control, if you dare.
If your root partition runs out of room, any process which tries to write a file (e.g. a lock file, log file, etc.) will fail, and will terminate. This often means you can't log into your system, run any commands except built-in bash commands on already-opened bash sessions, etc. And because log files can't be written to you won't see any meaningful errors in them.
This is one reason why you want to put /home on a separate partition - so over-zealous users can't bring the entire system to its knees. It's also good to farm off /usr or at least /usr/local, and personally I have /usr/bulk which is where I put all my big files - I've also got that partition formatted to use a different block size.
If you don't mind your system crashing when you forget to check your disk free status before recording a program then don't worry. It's only TV after all.
Ah well, I guess if worst comes to worst I can download a live cd with windows, boot off that, and then delete the file.
You could do that. Most people would prefer not to crash their system in the first place. But, you could do that.
If you only have 15Gb for Linux, consider this. The OS and installed apps may well be using close to 5Gb, depending on what you have installed. 5Gb or more would not be an unusual setup. That leaves you 10Gb to play with, assuming you have no other big stuff already eating into that remaining 10Gb . Depending on the resolution and bitrates you're recording at, 10Gb might hold anywhere from 10 hours of captured video all the way down to TWO hours or less if you've gone way overboard on the "quality" settings. You may not have a lot of breathing room in the disk space department.
If you have a seperate /home partition, the feel free to fill it. (Even more so if it's an ext2/3 filesystem - 5% is reserved for the root user anyway).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.