Mptv

Allikas: Pingviini viki

Siin on pisike minu (Kasutaja:V6sa) arendatud skript, mis genereerib mplayeri käsu TV salvestamiseks kõvakettale. Käivitamiseks näiteks:

./mptv.py tv3 v2ljundfail.asf
#!/usr/bin/python

############################################################################
#    Copyright (C) 2007 by v6sa                                            #
#    v6sa@v6sa.pingviin.org                                                #
#                                                                          #
#    This program is free software; you can redistribute it and#or modify  #
#    it under the terms of the GNU General Public License v2 as published  #
#    by the Free Software Foundation                                       #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
############################################################################

import sys,os

# Kanalite tabel:
channels = [ ['etv',    59.25],
             ['kanal2', 223.50],
             ['tv3',    527.85],
             ['yle1',   182.50],
             ['yle2',   196.50],
             ['mtv3',   495.50],
             ['svt',    583.50],
             ['nelonen',719.50]]

# Programm mida k2ivitakase on mencoder
command="mencoder "

# V2ljundfaili FPS
command+=" -ofps 25 "

# J2tab vahele esimesed kaks sekundit (kanali valimise myra)
command += " -ss 2 "

# 8MB puhver, aga see vist siin yleyldse ei m6ika
command += " -cache 8192 "

# Vali oma koodek:
# Lahja MPEG-2
#command += "-ovc lavc -lavcopts vcodec=mpeg1video"
# x264, v2ga n6udlik!
#command+="-ovc x264 -x264encopts subq=4:bframes=2:b_pyramid:weight_b"
# Realtime MPEG-4
#command+="-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:turbo"
# Fast MPEG-4
command+="-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv"

# Kaks threadi, sobiv kahetuumalisele
command+=":threads=2"

# Iga kaheksas kaader on keyframe, vajalik korrektseks seek-imiseks videovoos
command+=":keyint=8"

# Heli pakib MP3-ks
command+=" -oac mp3lame "

# V2ljundkonteineri pluginas, kuna v2ljundfaili parameeter on .ASF, 
#siis pannakse ta ka ASF konteinerisse mis on sobiv striimimiseks.
command+=" -of lavf "

# Video l6ikamine, cropdetect parameetrid:
crop=[695,530,10,15]
#command+="-vf cropdetect"
command+=" -vf crop="+str(crop[0])+":"+str(crop[1])+":"+str(crop[2])+":"+str(crop[3])

# Lihtne deinterlace:
command+=",pp=lb"

# Skaleerimine:
command+=",scale=400:300 "
#command+=",scale=520:390 "
#command+=",scale=640:480 "
#command+=",scale=320:240 "
#command+=",scale=200:150 "

# Keyframe-de puuk
command+=" -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames "

# Vaatame telekat
command+=" tv:// "
# TV mooduli parameetrid
command+=" -tv buffersize=1024:driver=v4l2:width=720:height=578"
# Heli loeb sisse ALSA kaudu (/dev/dsp1 -> telekakaardi heli)
command+=":alsa:adevice=hw.1,0:amode=1:immediatemode=0:audiorate=32000"

# Sagedustabel
freq=channels[0][1]
for channel in channels:
 if channel[0] == sys.argv[1]:
   freq = channel[1]
command+=":freq="+str(freq)

# Heli resamplimine telekakaardi 32kHz -> standartne 44.1kHz
command+=" -af-adv force=0 -af resample=44100:0:2 "

# Kuhu salvestada
command+=" -o "+sys.argv[2]+" "
print command
os.system(command)