adevice=hw.2,0:指定音频设备。当使用OSS音频系统时,adevice的值为/dev/xxx,当使用ALSA音频系统时,则为形如hw:2,0的硬件ID。需注意的是,由于命令行不能出现冒号,应将hw:2,0中的冒号改为逗号;
amode=1:指定声音模式。0为单声道,1为立体声;
audiorate=48000:输入声音采样率;
forceaudio:强制采集音频,即便v4l库未发现有音频源;
volume=100:指定视频采集卡上混频器的音量;
immediatemode=0:0表示同时采集与缓存音频与视频流(mencoder的默认值),1表示只采集视频流,而音频流则会通过回环线路由电视卡送至声卡(mplayer的默认值)。由于我使用的是mencoder,所以设为0;
normid=8:采集卡的电视标准编号;
buffersize=1024:采集缓冲区的大小,单位为MB
width=768:height=576:输出视频像素宽度与高度;
outfmt=i420:输出视频数据格式;
-oac mp3lame:指定音频编码器为mp3lame;
-lameopts fast:preset=standard:指定音频编码器的选项;
-ovc lavc:指定视频编码器为libavcodec;
-lavcopts vcodec=mpeg4:vhq:vbitrate=1800:指定视频编码器选项。
需要说明的是,由rtv.sh录制的avi文件没有索引,所以直接用mplayer播放无法快进与快退。为此,可以用下面的脚本程序自动生成索引后再播放(其中,参数$1为avi视频文件名):
#!/bin/bash mplayer -forceidx -saveidx "${1%avi}idx" "$1"
若想回放已经录制过且生成了索引的视频,则可以使用下面的脚本程序(其中,参数$1为avi视频文件名):
#!/bin/bash mplayer -loadidx "${1%avi}idx" "$1"
到这里,用于播放与录制电视节目的脚本程序rtv.sh就介绍完了。下面再来介绍用于停止播放或录制的脚本程序stop_rtv.sh。这个就比较简单了,无非就是杀死相应的进程而已。源代码如下:
#!/bin/bash # Define a function for returning a process id function get_pid_by_name() { local process_str echo "Searching process $1..." process_str=`ps aux | grep "$1" | tr --squeeze-repeats '[:blank:]+' '\t' | cut -f 2` if [ -n "$process_str" ]; then # The process for grep appears in the second field process_str=`echo $process_str | cut -s -d ' ' -f 1` if [ -n "$process_str" ]; then temp_pid=$process_str echo "The process id is $temp_pid!" else echo "The process $1 cannot be found, perfect!" fi else echo "The process $1 cannot be found, perfect!" fi } # Declare pid as integers declare -i temp_pid=-1 mplayer_pid=-1 mencoder_pid=-1 tee_pid=-1 # Kill mencoder process get_pid_by_name mencoder mencoder_pid=$temp_pid temp_pid=-1 if [ $(($mencoder_pid!=-1)) = 1 ]; then # The SIGINT has no effect on mencoder processes while SIGKILL will cause loss of /dev/video0 node kill -2 $mencoder_pid && echo "mencoder has been killed!" else echo "mencoder process does not exist!" fi # Kill tee process get_pid_by_name tee tee_pid=$temp_pid temp_pid=-1 if [ $(($tee_pid!=-1)) = 1 ]; then kill -2 $tee_pid && echo "tee has been killed!" else echo "tee process does not exist!" fi # Kill mplayer process if not in nowatch mode if [ "$1" != "nowatch" ]; then get_pid_by_name mplayer mplayer_pid=$temp_pid temp_pid=-1 if [ $(($mplayer_pid!=-1)) = 1 ]; then # Note: mplayer is started by using sudo, therefore when killing it, sudo should also be used sudo -u orlando kill -2 $mplayer_pid && echo "mplayer has been killed!" else echo "mplayer process does not exist!" fi fi echo "TV recording and playing have been stopped!"
有了rtv.sh与stop_rtv.sh两个脚本,再将其与at命令结合,则可以实现定时录制与播放节目了。例如: