mPlayRecTv - assista e grave a programação da TV com MPlayer
Publicado por Pedro Robson Leão 23/04/2005
[ Hits: 6.485 ]
Grave a programação da tv usando crontab/at e mplayer.
Após problemas com alguns aplicativos encontrei os parametros necessários para usar o mplayer e fazer minhas gravações.
Criei um script para fazer isto e conto com todos para aprimorar o script.
Agora com suporte a v4l e v4l2.
#!/bin/bash
#name : mPlayRecTv
#born : 01-April-2005 (it is not lie)
#author : Pedro Robson Leão (pedro.leao@ig.com.br)
#description: A simple interface to play and rec tv with mplayer.
#change log :
#20050401 ** first version.
#20050423 ajust para v4l2.
#mencoder -tv driver=v4l:norm=palm:channel=3:chanlist=us-cable:width=320:height=240:input=0 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=900 -oac mp3lame -lameopts cbr:br=64 -o output.avi tv://
#mplayer -tv driver=v4l:norm=palm:channel=3:chanlist=us-cable:width=352:height=240:input=0 -vo sdl tv://
#-- default Parameters
driver=${driver:-v4l2};
norm=${norm:-palm};
channel=${channel:-3};
channelist=${channelist:-us-cable};
width=${width:-320};
height=${height:-240};
ovc=${ovc:-lavc -lavcopts};
vcodec=${vcodec:-mpeg4};
vbitrate=${vbitrate:-900};
oac=${oac:-mp3lame -lameopts};
cbr=${cbr:-br=64};
input=${input:-Television};
output=${output:-output.avi};
vo=${vo:-sdl};
log=${log:-/dev/null};
time=;
play=1;
myname=$0;
#-- convert hour and minuts to seconds
function convTime() {
value=${1};
value=${value//:/};
min=$((value%100));
hour=$((value/100))
min=$((min*60));
hour=$((hour*3600));
sec=$((hour+min));
echo $sec;
}
#-- error message
function errMsg() {
echo "Use: ${myname} [options ...]";
echo;
echo "Default options:";
echo "--driver=${driver} [v4l/v4l2]";
echo "--norm=${norm} [palm/paln/pal/ntsc]";
echo "--channel=${channel}";
echo "--channelist=${channelist}";
echo "--width=${width}";
echo "--height=${height}";
echo "--ovc=${ovc}";
echo "--vcodec=${vcodec}";
echo "--vbitrate=${vbitrate}";
echo "--oac=${oac}";
echo "--cbr=${cbr}";
echo "--input=${input} [Television/Composite1/S-Video]";
echo "--output=${output}";
echo "--vo=${vo}";
echo "--log=${log}";
echo;
echo;
case $1 in
pid) echo "ERROR IN PLAY/REC : To debug errors to play/rec use --log option and see log to many informations.";;
input) echo "INVALID INPUT : Use --input with [Television/Composite1/S-Video]";;
mplayer|mencoder) echo "CAN'T FOUND PROGRAM ${1}";
esac
}
#-- Change input parameters to getopts format
set -- ${*//--driver/-d};
set -- ${*//--norm/-n};
set -- ${*//--channel/-c};
set -- ${*//--channelist/-l};
set -- ${*//--width/-W};
set -- ${*//--heigth/-H};
set -- ${*//--ovc/-V};
set -- ${*//--vcodec/-C};
set -- ${*//--vbitrate/-b};
set -- ${*//--oac/-A};
set -- ${*//--cbr/-R};
set -- ${*//--input/-i};
set -- ${*//--output/-o};
set -- ${*//--vo/-O};
set -- ${*//--play/-p};
set -- ${*//--rec/-r};
set -- ${*//--log/-L};
set -- ${*//--time/-T};
set -- ${*//--help/-h};
#- get parameters
while getopts d:n:c:l:W:H:V:C:b:A:R:i:o:O:prhL:T: value 2>/dev/null ; do
case $value in
d) driver="${OPTARG}";;
n) norm="${OPTARG}";;
c) channel="${OPTARG}";;
l) channelist="${OPTARG}";;
w) width="${OPTARG}";;
H) heigth="${OPTARG}";;
V) ovc="${OPTARG}";;
C) vcodec="${OPTARG}";;
b) vbitrate="${OPTARG}";;
A) oac="${OPTARG}";;
R) cbr="${OPTARG}";;
i) input="${OPTARG}";;
o) output="${OPTARG}";;
O) vo="${OPTARG}";;
L) log="${OPTARG}";;
T) time="${OPTARG}";;
p) play=1;;
r) play=;;
h) errMsg help; exit 0;;
*) errMsg help; exit 0;;
esac
done
#-- convert input parms
case ${input} in
Television) input=0;;
Composite1) input=1;;
S-Video) input=2;;
*) errMsg input; exit 0;;
esac
#-- convert norm para minusculo
norm=$( echo ${norm} | tr A-Z a-z );
#-- Ajusta parametros para v4l2
if [ "${driver}" = "v4l2" ] ; then
#0 = PAL; 1 = NTSC; 2 = SECAM; 3 = PAL-Nc; 4 = PAL-M; 5 = PAL-N; 6 = NTSC-JP; 7 = PAL-60;
case ${norm} in
pal) norm=0;;
ntsc) norm=1;;
secam) norm=2;;
pal-nc|palnc) norm=3;;
pal-m|palm) norm=4;;
pal-n|paln) norm=5;;
ntsc-jp|paljp) norm=6;;
pal-60|pal60) norm=7;;
esac
normopc="normid";
else
normopc="norm";
fi
gparms="driver=${driver}:${normopc}=${norm}:channel=${channel}:chanlist=${channelist}:width=${width}:height=${height}:input=${input}";
if [ ! -z ${play} ] ; then
command="mplayer -tv ${gparms} -vo ${vo} tv://";
msglog="${0} play channel ${channel} ";
else
command="mencoder -tv ${gparms} -ovc ${ovc} vcodec=${vcodec}:vbitrate=${vbitrate} -oac ${oac} cbr:${cbr} -o ${output} tv://";
msglog="${0} rec channel ${channel} ";
fi
#-- verify command
if ! which $( echo $command | cut -d" " -f1 ) >/dev/null; then
errMsg $command;
exit 1;
fi
#-- execute the mplayer our mencoder
start=$(date);
echo ${command};
${command} >${log} 2>&1 &
cmdpid=${!};
#-- in error case no has pid
[ -z "${cmdpid}" ] && errMsg pid && exit 0;
#-- get time to reproduction
time=$( convTime ${time} );
#-- if time reproduction, kill proccess after time
[ ${time} -ge 1 ] && sleep ${time} && kill ${cmdpid};
end=$(date);
#-- write log message
logger 0 "${msglog} pid:${cmdpid} start:${start} end:${end}";
exit 1;
Compara igualdade entre arquivos
Instalação do Cisco Packettracer 7.2 no Debian 10
Serviço de conexão 3G - Debian
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como impedir exclusão de arquivos por outros usuários no (Linux)
Cirurgia no Linux Mint em HD Externo via USB
Anúncio do meu script de Pós-Instalação do Ubuntu
Alguém executou um rm e quase mata a Pixar! (1)
Por que passar nas disciplinas da faculdade é ruim e ser reprovado é b... (6)
Alguém pode me indicar um designer freelancer? [RESOLVIDO] (3)









