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
|
#!/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
|
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||||
# zu transkodieren.
|
# zu transkodieren.
|
||||||
|
@ -20,6 +20,12 @@ import xml.dom.minidom
|
||||||
host = "tivo.lassitu.de"
|
host = "tivo.lassitu.de"
|
||||||
mak = "7194378159"
|
mak = "7194378159"
|
||||||
|
|
||||||
|
|
||||||
|
arset = dict()
|
||||||
|
arset["Family Guy"] = 43
|
||||||
|
arset["The Colbert Report"] = 43
|
||||||
|
arset["The Daily Show With Jon Stewart"] = 43
|
||||||
|
|
||||||
class flushfile(object):
|
class flushfile(object):
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
self.f = f
|
self.f = f
|
||||||
|
@ -34,20 +40,10 @@ except OSError:
|
||||||
pass
|
pass
|
||||||
pwmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
pwmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||||
authhandler = urllib2.HTTPDigestAuthHandler(pwmgr)
|
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))
|
opener = urllib2.build_opener(authhandler, urllib2.HTTPCookieProcessor(cookiejar))
|
||||||
urllib2.install_opener(opener)
|
urllib2.install_opener(opener)
|
||||||
transcode_srcopts = []
|
tmp = "/tmp"
|
||||||
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"])
|
|
||||||
tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
|
tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
|
||||||
tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
|
tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
|
||||||
|
|
||||||
|
@ -75,48 +71,64 @@ def getTagText(element, tagname):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def transcode(file, passno):
|
def transcode(file, passno, ar):
|
||||||
print "--- transcoding pass %d" % passno
|
print "--- transcoding pass %d" % passno
|
||||||
try:
|
try:
|
||||||
os.remove(tmpmp4)
|
os.remove(tmpmp4)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
transcode_opts = [ "ffmpeg" ];
|
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.append(tmpmp2)
|
||||||
transcode_opts.extend(transcode_dstopts)
|
|
||||||
if passno == 2:
|
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(["-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)
|
transcode_opts.append(tmpmp4)
|
||||||
|
print " %s" % " ".join(transcode_opts)
|
||||||
subprocess.check_call(transcode_opts)
|
subprocess.check_call(transcode_opts)
|
||||||
|
|
||||||
|
|
||||||
def download_decode(file, url, mak):
|
def download_decode(file, url, mak, ar):
|
||||||
try:
|
try:
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
print "--- dowloading \"%s\"" % url
|
if not os.path.exists(tmpmp2):
|
||||||
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
print "--- dowloading \"%s\"" % url
|
||||||
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
|
||||||
"--user", "tivo:%s" % mak, "--url", url], \
|
"--insecure", "--cookie", "tivo/.cookies.txt", \
|
||||||
stdout=subprocess.PIPE)
|
"--user", "tivo:%s" % mak, "--url", url], \
|
||||||
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
stdout=subprocess.PIPE)
|
||||||
"--out", tmpmp2, "-"], stdin=p_curl.stdout)
|
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
|
||||||
status = {}
|
"--out", tmpmp2, "-"], stdin=p_curl.stdout)
|
||||||
(spid, sse) = os.wait()
|
status = {}
|
||||||
status.update({spid: sse})
|
(spid, sse) = os.wait()
|
||||||
(spid, sse) = os.wait()
|
status.update({spid: sse})
|
||||||
status.update({spid: sse})
|
(spid, sse) = os.wait()
|
||||||
if status.get(p_curl.pid) >> 8 != 0:
|
status.update({spid: sse})
|
||||||
print "error downloading file: %d" % (status.get(p_curl.pid) >> 8)
|
if status.get(p_curl.pid) >> 8 != 0:
|
||||||
exit(1)
|
print "error downloading file: %d" % (status.get(p_curl.pid) >> 8)
|
||||||
if status.get(p_decode.pid) >> 8 != 0:
|
exit(1)
|
||||||
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
|
if status.get(p_decode.pid) >> 8 != 0:
|
||||||
exit(1)
|
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
|
||||||
transcode(file, 1)
|
exit(1)
|
||||||
transcode(file, 2)
|
transcode(file, 1, ar)
|
||||||
|
transcode(file, 2, ar)
|
||||||
print "--- copying to \"%s\"" % file
|
print "--- copying to \"%s\"" % file
|
||||||
shutil.copy(tmpmp4, "%s.mp4" % file)
|
shutil.copy(tmpmp4, "%s.mp4" % file)
|
||||||
os.remove(tmpmp2)
|
os.remove(tmpmp2)
|
||||||
|
@ -128,8 +140,9 @@ def savetoc():
|
||||||
fd.close()
|
fd.close()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
curdir = os.getcwd()
|
||||||
downloaddb = anydbm.open("tivo/.downloads", "c")
|
os.chdir(tmp)
|
||||||
|
downloaddb = anydbm.open(curdir + "/tivo/.downloads", "c")
|
||||||
print "*** Getting listing"
|
print "*** Getting listing"
|
||||||
dom = xml.dom.minidom.parseString(gettoc())
|
dom = xml.dom.minidom.parseString(gettoc())
|
||||||
cookiejar.save()
|
cookiejar.save()
|
||||||
|
@ -147,12 +160,16 @@ for i in items:
|
||||||
if episode == "":
|
if episode == "":
|
||||||
episode = date
|
episode = date
|
||||||
name = "%s - %s" % (title, episode)
|
name = "%s - %s" % (title, episode)
|
||||||
dir = "tivo/%s" % (title)
|
dir = "%s/tivo/%s" % (curdir, title)
|
||||||
file = "%s/%s" % (dir, name)
|
file = "%s/%s" % (dir, name)
|
||||||
name = name.encode("utf-8");
|
name = name.encode("utf-8");
|
||||||
dir = dir.encode("utf-8");
|
dir = dir.encode("utf-8");
|
||||||
file = file.encode("utf-8");
|
file = file.encode("utf-8");
|
||||||
|
|
||||||
|
ar = 169
|
||||||
|
if arset.has_key(title):
|
||||||
|
ar = arset[title]
|
||||||
|
|
||||||
if inprogress == "Yes":
|
if inprogress == "Yes":
|
||||||
print "*** skipping \"%s\": is currently being recorded" % name
|
print "*** skipping \"%s\": is currently being recorded" % name
|
||||||
continue
|
continue
|
||||||
|
@ -160,7 +177,7 @@ for i in items:
|
||||||
print "*** skipping \"%s\": already downloaded" % name
|
print "*** skipping \"%s\": already downloaded" % name
|
||||||
continue
|
continue
|
||||||
print "*** downloading \"%s\"" % name
|
print "*** downloading \"%s\"" % name
|
||||||
download_decode(file, url, mak)
|
download_decode(file, url, mak, title)
|
||||||
downloaddb[name] = date
|
downloaddb[name] = date
|
||||||
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
|
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
|
||||||
downloaddb.sync()
|
downloaddb.sync()
|
||||||
|
|
Loading…
Reference in a new issue