+ recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
+ zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip"))
+ zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip"))
+ os.remove(log_ffmpeg)
+ os.remove(log_x264)
+def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処
+ ffmpeg=configreader.getConfPath("ffmpeg")
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
+ try:
+ recdblist.addCommandSelfLog(pin, exe)
+ except Exception, inst:
+ print type(inst)
+ print str(inst)
+ print traceback.print_exc(file=sys.stdout)
+ txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
+ rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
+ rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
+ sizeMaxX=0
+ sizeMaxY=0
+ txtls=txts.split("\n")
+ for t in txtls:
+ rM=rT.search(t)
+ rM2=rT2.search(t)
+ if rM:
+ sizetxt=rM.group(1)
+ partxt=rM.group(2)
+ tX=int(sizetxt.split("x")[0])
+ tY=int(sizetxt.split("x")[1])
+ tEX=int(partxt.split(":")[0])
+ tEY=int(partxt.split(":")[1])
+ if sizeMaxX<tX:
+ sizeMaxX=tX
+ sizeMaxY=tY
+ if rM2:
+ sizetxt=rM2.group(1)
+ tX=int(sizetxt.split("x")[0])
+ tY=int(sizetxt.split("x")[1])
+ if sizeMaxX<tX:
+ sizeMaxX=tX
+ sizeMaxY=tY
+ os.remove(pin+".size.ts")
+ return [sizeMaxX,sizeMaxY]
+def getMoviePAR2(pin):
+ ffmpeg=configreader.getConfPath("ffmpeg")
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
+ try:
+ recdblist.addCommandSelfLog(pin, exe)
+ except Exception, inst:
+ print type(inst)
+ print str(inst)
+ print traceback.print_exc(file=sys.stdout)
+ txts = unicode(commands.getoutput(exe.encode('utf-8')), 'utf-8', 'ignore')
+ rT = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
+ rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
+ sizeMaxX = 0
+ parx = 0
+ pary = 0
+ txtls = txts.split("\n")
+ for t in txtls:
+ rM = rT.match(t)
+ rM2 = rT2.match(t)
+ if rM:
+ sizetxt = rM.group(1)
+ dartxt = rM.group(2)
+ tX = int(sizetxt.split("x")[0])
+ tY = int(sizetxt.split("x")[1])
+ tEX = int(dartxt.split(":")[0])
+ tEY = int(dartxt.split(":")[1])
+ if sizeMaxX < tX:
+ sizeMaxX = tX
+ if tX == 1920 and tY == 1080:
+ parx = 1
+ pary = 1
+ else:
+ parx = tEX
+ pary = tEY
+ rM = rT.match(t)
+ if rM2:
+ sizetxt = rM2.group(1)
+ sartxt = rM2.group(2)
+ dartxt = rM2.group(3)
+ tX = int(sizetxt.split("x")[0])
+ tY = int(sizetxt.split("x")[1])
+ tEX = int(dartxt.split(":")[0])
+ tEY = int(dartxt.split(":")[1])##dar=sarxpar
+ tSX = int(sartxt.split(":")[0])
+ tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx
+ if sizeMaxX < tX:
+ sizeMaxX = tX
+ if tX == 1920 and tY == 1080:
+ parx = 1
+ pary = 1
+ else:
+ if tEX * tSY == tEY * tSX:
+ parx = 1
+ pary = 1
+ elif tEX * tSY * 3 == tEY * tSX * 4:
+ parx = 4
+ pary = 3
+ elif tEX * tSY * 4 == tEY * tSX * 3:
+ parx = 3
+ pary = 4
+ elif tEX * tSY * 9 == tEY * tSX * 16:
+ parx = 16
+ pary = 9
+ elif tEX * tSY * 16 == tEY * tSX * 9:
+ parx = 9
+ pary = 16
+ os.remove(pin+".size.ts")
+ return [parx,pary]
+def getParSize(pin,y):
+ tSize=getMovieBaseSize2(pin)
+ if tSize[1] != 0 :
+ tX=tSize[0]*10*y/tSize[1]
+ tY=y
+ if tX>int(tX/10)*10:
+ tX=tX/10+1
+ else:
+ tX=tX/10
+ else:
+ tX=-1
+ tY=-1
+ return [tX,tY]
+def getX264CoreVersion():
+ x264=configreader.getConfPath("x264")
+ #print x264
+ t1=commands.getoutput(x264+" --help|grep core")
+ #print t1
+ rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")
+ rM=rT.match(t1)
+ v=-1
+ if rM:
+ v=int(rM.group(1))
+ return v
+def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0,interlaced=0,bluray=0):
+ x264=configreader.getConfPath("x264")
+ os.environ['LANG']="ja_JP.UTF-8"
+ x264_sar="--sar "+sar
+ x264preset=u"--preset "+preset
+ x264fps="--fps "+fps
+ x264interlaced=""
+ x264bluray=""
+ x264_addline=configreader.getConfEnv("x264_addline")
+ if crf==-1:
+ x264bitrate=u"--bitrate "+str(bitrate)
+ else:
+ x264crf=u"--crf "+str(crf)
+ if interlaced==1:
+ x264interlaced="--tff --nal-hrd vbr"
+ if bluray==1:
+ if getX264CoreVersion()<115:
+ x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 "
+ x264_addline=""
+ if fps=="24000/1001 --keyint 24" or fps =="24000/1001":
+ if x264streamsize=="1280x720":
+ x264bluray=u"--ref 6 "+x264bluray
+ if x264streamsize=="1920x1080":
+ x264bluray=u"--ref 4 "+x264bluray
+ elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":
+ if x264streamsize=="1280x720":
+ x264bluray=u"--ref 6 --pulldown double "+x264bluray
+ if x264streamsize=="1920x1080":
+ if interlaced==0:
+ x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray
+ else:
+ x264bluray=u"--ref 4 "+x264bluray
+ elif getX264CoreVersion()>=115:
+ x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 "
+ x264_addline=""
+ if fps=="24000/1001 --keyint 24" or fps =="24000/1001":
+ if x264streamsize=="1280x720":
+ x264bluray=u"--ref 6 "+x264bluray
+ if x264streamsize=="1920x1080":
+ x264bluray=u"--ref 4 "+x264bluray
+ elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":
+ if x264streamsize=="1280x720":
+ x264bluray=u"--ref 6 --pulldown double "+x264bluray
+ if x264streamsize=="1920x1080":
+ if interlaced==0:
+ x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray
+ else:
+ x264bluray=u"--ref 4 "+x264bluray
+ x264_thread="auto"
+ try:
+ xtt=configreader.getConfEnv("x264_thread")
+ xtt=int(xtt)
+ if xtt>0:
+ x264_thread=str(xtt)
+ except:
+ x264_thread="auto"
+ x264_addline=configreader.getConfEnv("x264_addline")
+ if getX264CoreVersion()>103:
+ x264res=u"--input-res "+x264streamsize
+ exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin
+ else:
+ exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize
+ return exe