Optimierte ffmpeg-Einstellungen
This commit is contained in:
parent
c8905402eb
commit
dd58aae222
1 changed files with 59 additions and 42 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.1 2010/01/01 22:32:48 stb Exp $
|
||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.2 2010/01/02 00:51:02 stb Exp $
|
||||
#
|
||||
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||
# zu transkodieren.
|
||||
|
@ -20,6 +20,12 @@ import xml.dom.minidom
|
|||
host = "tivo.lassitu.de"
|
||||
mak = "7194378159"
|
||||
|
||||
|
||||
arset = dict()
|
||||
arset["Family Guy"] = 43
|
||||
arset["The Colbert Report"] = 43
|
||||
arset["The Daily Show With Jon Stewart"] = 43
|
||||
|
||||
class flushfile(object):
|
||||
def __init__(self, f):
|
||||
self.f = f
|
||||
|
@ -34,20 +40,10 @@ except OSError:
|
|||
pass
|
||||
pwmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||
authhandler = urllib2.HTTPDigestAuthHandler(pwmgr)
|
||||
cookiejar = cookielib.MozillaCookieJar("tivo/.cookies.txt")
|
||||
cookiejar = cookielib.MozillaCookieJar(os.getcwd() + "/tivo/.cookies.txt")
|
||||
opener = urllib2.build_opener(authhandler, urllib2.HTTPCookieProcessor(cookiejar))
|
||||
urllib2.install_opener(opener)
|
||||
transcode_srcopts = []
|
||||
transcode_srcopts.extend(["-aspect", "4:3"])
|
||||
transcode_srcopts.append("-i")
|
||||
transcode_dstopts = []
|
||||
transcode_dstopts.extend(["-threads", "8"])
|
||||
transcode_dstopts.extend(["-vcodec", "libx264", "-b", "1200kb"])
|
||||
#transcode_dstopts.extend(["-croptop", "8", "-cropbottom", "8", "-cropleft", "8", "-cropright", "8"])
|
||||
transcode_dstopts.extend(["-croptop", "60", "-cropbottom", "60", "-cropleft", "4", "-cropright", "4"])
|
||||
transcode_dstopts.extend(["-y", "-deinterlace"])
|
||||
#transcode_dstopts.extend(["-aspect", "4:3"])
|
||||
transcode_dstopts.extend(["-aspect", "16:9"])
|
||||
tmp = "/tmp"
|
||||
tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
|
||||
tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
|
||||
|
||||
|
@ -75,48 +71,64 @@ def getTagText(element, tagname):
|
|||
return ""
|
||||
|
||||
|
||||
def transcode(file, passno):
|
||||
def transcode(file, passno, ar):
|
||||
print "--- transcoding pass %d" % passno
|
||||
try:
|
||||
os.remove(tmpmp4)
|
||||
except OSError:
|
||||
pass
|
||||
transcode_opts = [ "ffmpeg" ];
|
||||
transcode_opts.extend(transcode_srcopts)
|
||||
# transcode_opts.extend(["-t", "60"]) # testing only: only 60 seconds
|
||||
transcode_opts.extend(["-aspect", "4:3", "-i"])
|
||||
transcode_opts.append(tmpmp2)
|
||||
transcode_opts.extend(transcode_dstopts)
|
||||
|
||||
if passno == 2:
|
||||
transcode_opts.extend(["-acodec", "libfaac", "-ab", "96kb"])
|
||||
transcode_opts.extend(["-acodec", "libfaac", "-ab", "128kb"])
|
||||
transcode_opts.extend(["-pass", "%d" % passno])
|
||||
transcode_opts.extend(["-vcodec", "libx264"])
|
||||
if passno == 2:
|
||||
transcode_opts.extend(["-vpre", "fastfirstpass"])
|
||||
else:
|
||||
transcode_opts.extend(["-vpre", "hq"])
|
||||
transcode_opts.extend(["-threads", "0", "-b", "1200kb"])
|
||||
if ar == 43:
|
||||
transcode_opts.extend(["-croptop", "8", "-cropbottom", "8", "-cropleft", "8", "-cropright", "8"])
|
||||
transcode_opts.extend(["-aspect", "4:3"])
|
||||
else:
|
||||
transcode_opts.extend(["-croptop", "64", "-cropbottom", "64", "-cropleft", "8", "-cropright", "8"])
|
||||
transcode_opts.extend(["-aspect", "16:9"])
|
||||
transcode_opts.extend(["-y", "-deinterlace"])
|
||||
transcode_opts.append(tmpmp4)
|
||||
print " %s" % " ".join(transcode_opts)
|
||||
subprocess.check_call(transcode_opts)
|
||||
|
||||
|
||||
def download_decode(file, url, mak):
|
||||
def download_decode(file, url, mak, ar):
|
||||
try:
|
||||
os.makedirs(dir)
|
||||
except OSError:
|
||||
pass
|
||||
print "--- dowloading \"%s\"" % url
|
||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
||||
"--user", "tivo:%s" % mak, "--url", url], \
|
||||
stdout=subprocess.PIPE)
|
||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||
"--out", tmpmp2, "-"], stdin=p_curl.stdout)
|
||||
status = {}
|
||||
(spid, sse) = os.wait()
|
||||
status.update({spid: sse})
|
||||
(spid, sse) = os.wait()
|
||||
status.update({spid: sse})
|
||||
if status.get(p_curl.pid) >> 8 != 0:
|
||||
print "error downloading file: %d" % (status.get(p_curl.pid) >> 8)
|
||||
exit(1)
|
||||
if status.get(p_decode.pid) >> 8 != 0:
|
||||
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
|
||||
exit(1)
|
||||
transcode(file, 1)
|
||||
transcode(file, 2)
|
||||
if not os.path.exists(tmpmp2):
|
||||
print "--- dowloading \"%s\"" % url
|
||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
||||
"--user", "tivo:%s" % mak, "--url", url], \
|
||||
stdout=subprocess.PIPE)
|
||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||
"--out", tmpmp2, "-"], stdin=p_curl.stdout)
|
||||
status = {}
|
||||
(spid, sse) = os.wait()
|
||||
status.update({spid: sse})
|
||||
(spid, sse) = os.wait()
|
||||
status.update({spid: sse})
|
||||
if status.get(p_curl.pid) >> 8 != 0:
|
||||
print "error downloading file: %d" % (status.get(p_curl.pid) >> 8)
|
||||
exit(1)
|
||||
if status.get(p_decode.pid) >> 8 != 0:
|
||||
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
|
||||
exit(1)
|
||||
transcode(file, 1, ar)
|
||||
transcode(file, 2, ar)
|
||||
print "--- copying to \"%s\"" % file
|
||||
shutil.copy(tmpmp4, "%s.mp4" % file)
|
||||
os.remove(tmpmp2)
|
||||
|
@ -128,8 +140,9 @@ def savetoc():
|
|||
fd.close()
|
||||
exit(0)
|
||||
|
||||
|
||||
downloaddb = anydbm.open("tivo/.downloads", "c")
|
||||
curdir = os.getcwd()
|
||||
os.chdir(tmp)
|
||||
downloaddb = anydbm.open(curdir + "/tivo/.downloads", "c")
|
||||
print "*** Getting listing"
|
||||
dom = xml.dom.minidom.parseString(gettoc())
|
||||
cookiejar.save()
|
||||
|
@ -147,12 +160,16 @@ for i in items:
|
|||
if episode == "":
|
||||
episode = date
|
||||
name = "%s - %s" % (title, episode)
|
||||
dir = "tivo/%s" % (title)
|
||||
dir = "%s/tivo/%s" % (curdir, title)
|
||||
file = "%s/%s" % (dir, name)
|
||||
name = name.encode("utf-8");
|
||||
dir = dir.encode("utf-8");
|
||||
file = file.encode("utf-8");
|
||||
|
||||
ar = 169
|
||||
if arset.has_key(title):
|
||||
ar = arset[title]
|
||||
|
||||
if inprogress == "Yes":
|
||||
print "*** skipping \"%s\": is currently being recorded" % name
|
||||
continue
|
||||
|
@ -160,7 +177,7 @@ for i in items:
|
|||
print "*** skipping \"%s\": already downloaded" % name
|
||||
continue
|
||||
print "*** downloading \"%s\"" % name
|
||||
download_decode(file, url, mak)
|
||||
download_decode(file, url, mak, title)
|
||||
downloaddb[name] = date
|
||||
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
|
||||
downloaddb.sync()
|
||||
|
|
Loading…
Reference in a new issue