OSDN Git Service

change function name.
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
index 0043e62..aebf113 100644 (file)
@@ -21,8 +21,8 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
     size="HD"
     crf=18
     quality=4
-    quality=int(configreader.getenv("x264_preset"))
-    crf=int(configreader.getenv("crf"))
+    quality=int(configreader.getEnvSetting("x264_preset"))
+    crf=int(configreader.getEnvSetting("crf"))
     deinterlace=1
     if re.search("H", opts):
         size = "HD"
@@ -40,10 +40,10 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
         crf=crf+2
     if re.search("v", opts):
         is24fps=1
-        crf=int(configreader.getenv("animation_crf"))
+        crf=int(configreader.getEnvSetting("animation_crf"))
     if re.search("a", opts):
         is24fps=1
-        crf=int(configreader.getenv("animation_crf"))
+        crf=int(configreader.getEnvSetting("animation_crf"))
     if re.search("I", opts):
         deinterlace=0
     if re.search("q",opts):
@@ -64,17 +64,17 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
         crf=crf-2
     if re.search("d",opts):#二カ国語放送の場合
         tm2v=pin.replace(".ts",".m2v")
-        encode_ffmpeg_sar(tm2v,pout,size,is24fps,quality,crf,deinterlace)
+        encodeFFmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace)
     elif re.search("5",opts):#5.1chの場合
-        encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace)
+        encodeFFmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace)
     else:
         try:
-            encode_sar(pin, pout,size,is24fps,quality,crf,deinterlace)
+            encodeSar(pin, pout,size,is24fps,quality,crf,deinterlace)
         except Exception, inst:
-            recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
-def encode_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
-    mencoder=configreader.getpath("mencoder")
-    encvf=""
+            recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
+def encodeSar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
+    mencoder=configreader.getPathSetting("mencoder")
+    egetPath
     txt=""
     encvf="-sws 9 -vf yadif=0,pp=l5"
     harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
@@ -95,32 +95,32 @@ def encode_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
         encvf="-sws 9 -vf pullup,softskip"
         harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
     if size == "HD":
-        tsize=get_par_size(pin,720)
+        tsize=getParSize(pin,720)
         encvf = encvf + ",scale=-3:720::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x720"
         x264_bitrate="2500"
     elif size == "WVGA":
-        tsize=get_par_size(pin,480)
+        tsize=getParSize(pin,480)
         encvf = encvf + ",scale=-3:480::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x480"
         x264_bitrate="1500"
     elif size == "FullHD":
-        tsize=get_par_size(pin,1080)
+        tsize=getParSize(pin,1080)
         encvf = encvf + ",scale=-3:1080::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x1080"
         x264_bitrate="5000"
     elif size == "QVGA_BASE":
-        tsize=get_par_size(pin,240)
+        tsize=getParSize(pin,240)
         encvf = encvf + ",scale=-3:240::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x240"
         x264_bitrate="300"
     elif size == "WVGA_BASE":
-        tsize=get_par_size(pin,480)
+        tsize=getParSize(pin,480)
         encvf = encvf + ",scale=-3:480::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x480"
         x264_bitrate="1500"
     else:
-        tsize=get_par_size(pin,720)
+        tsize=getParSize(pin,720)
         encvf = encvf + ",scale=-3:720::0:3"+harddup
         x264streamsize=str(tsize[0])+u"x720"
         x264_bitrate="2500"
@@ -171,7 +171,7 @@ def encode_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
     streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999)))
     os.system(u"mkfifo "+streampath)
     encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" & "
-    encexe=encexe+get_x264_commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf)
+    encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf)
     #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u"  --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
     encexe=u"nice -n 19 " +encexe
     recdblist.printutf8(encexe)
@@ -182,11 +182,11 @@ def encode_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
         ""
     os.system("rm "+streampath)
     recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
-def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
+def encodeFFmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
     """
 
     """
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     fps=u"-r 29.970030 "
     x264fps="30000/1001"
     x264streamsize=""
@@ -198,37 +198,37 @@ def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
     filter="-deinterlace"
     x264sar=str(tsar[0])+":"+str(tsar[1])
     if size == "HD":
-        tsize=get_par_size(pin,720)
+        tsize=getParSize(pin,720)
         s = "-s "+str(tsize[0])+"x720 "
         x264streamsize=str(tsize[0])+u"x720"
         x264_bitrate="2500"
     elif size == "WVGA":
-        tsize=get_par_size(pin,480)
+        tsize=getParSize(pin,480)
         s = "-s "+str(tsize[0])+"x480 "
         x264streamsize=str(tsize[0])+u"x480"
         x264_bitrate="1500"
     elif size == "FullHD":
-        tsize=get_par_size(pin,1080)
+        tsize=getParSize(pin,1080)
         s = "-s "+str(tsize[0])+"x1080 "
         x264streamsize=str(tsize[0])+u"x1080"
         x264_bitrate="5000"
     elif size == "SD":
-        tsize=get_par_size(pin,480)
+        tsize=getParSize(pin,480)
         s = "-s "+str(tsize[0])+"x480 "
         x264streamsize=str(tsize[0])+u"x480"
         x264_bitrate="1250"
     elif size == "QVGA_BASE":
-        tsize=get_par_size(pin,240)
+        tsize=getParSize(pin,240)
         s = "-s "+str(tsize[0])+"x240 "
         x264streamsize=str(tsize[0])+u"x240"
         x264_bitrate="300"
     elif size == "WVGA_BASE":
-        tsize=get_par_size(pin,480)
+        tsize=getParSize(pin,480)
         s = "-s "+str(tsize[0])+"x480 "
         x264streamsize=str(tsize[0])+u"x480"
         x264_bitrate="1500"
     else:
-        tsize=get_par_size(pin,720)
+        tsize=getParSize(pin,720)
         s = "-s "+str(tsize[0])+"x720 "
         x264streamsize=str(tsize[0])+u"x720"
         x264_bitrate="2500"
@@ -260,7 +260,7 @@ def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
     txt=""
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - | "
-    exe=exe+get_x264_commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf)
+    exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf)
     exe = "nice -n 19 " + exe
     txt=""
     recdblist.printutf8(exe)
@@ -270,7 +270,7 @@ def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
         ""
     recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
 def getMovieBaseSize(pin):
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -292,7 +292,7 @@ def getMovieBaseSize(pin):
                 sizeMaxY=tY
     return [sizeMaxX,sizeMaxY]
 def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -315,7 +315,7 @@ def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更された
     os.remove(pin+".size.ts")
     return [sizeMaxX,sizeMaxY]
 def getMoviePAR(pin):
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -343,7 +343,7 @@ def getMoviePAR(pin):
                     pary=tEY
     return [parx,pary]
 def getMoviePAR2(pin):
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -372,7 +372,7 @@ def getMoviePAR2(pin):
     os.remove(pin+".size.ts")
     return [parx,pary]
 def getMovieDAR(pin):
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -400,7 +400,7 @@ def getMovieDAR(pin):
                     dary=tEY
     return [darx,dary]
 def getMovieDAR2(pin):
-    ffmpeg=configreader.getpath("ffmpeg")
+    ffmpeg=configreader.getPathSetting("ffmpeg")
     os.environ['LANG']="ja_JP.UTF-8"
     exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
@@ -428,7 +428,7 @@ def getMovieDAR2(pin):
                     dary=tEY
     os.remove(pin+".size.ts")
     return [darx,dary]
-def get_par_size(pin,y):
+def getParSize(pin,y):
     tSize=getMovieBaseSize2(pin)
     if tSize[1] != 0 :
         tX=tSize[0]*10*y/tSize[1]
@@ -441,8 +441,8 @@ def get_par_size(pin,y):
         tX=-1
         tY=-1
     return [tX,tY]
-def get_x264core_version():
-    x264=configreader.getpath("x264")
+def getX264CoreVersion():
+    x264=configreader.getPathSetting("x264")
     t1=commands.getoutput(x264+" --help|grep core")
     rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")
     rM=rT.match(t1)
@@ -450,8 +450,8 @@ def get_x264core_version():
     if rM:
         v=int(rM.group(1))
     return v
-def get_x264_commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0):
-    x264=configreader.getpath("x264")
+def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0):
+    x264=configreader.getPathSetting("x264")
     os.environ['LANG']="ja_JP.UTF-8"
     x264_sar="--sar "+sar
     x264preset=u"--preset "+preset
@@ -460,17 +460,17 @@ def get_x264_commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264stream
         x264bitrate=u"--bitrate "+str(bitrate)
     else:
         x264crf=u"--crf "+str(crf)
-    x264_addline=configreader.getenv("x264_addline")
+    x264_addline=configreader.getEnvSetting("x264_addline")
     x264_thread="auto"
     try:
-        xtt=configreader.getenv("x264_thread")
+        xtt=configreader.getEnvSetting("x264_thread")
         xtt=int(xtt)
         if xtt>0:
             x264_thread=str(xtt)
     except:
         x264_thread="auto"
-    x264_addline=configreader.getenv("x264_addline")
-    if get_x264core_version()>103:
+    x264_addline=configreader.getEnvSetting("x264_addline")
+    if getX264CoreVersion()>103:
         x264res=u"--input-res "+x264streamsize
         exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin
     else: