encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
elif re.search("5",opts):
encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
+ elif re.search("Y",opts):
+ encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf)
elif re.search("b",opts):
try:
tm2v=pin.replace(".ts",".m2v")
except:
""
recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
-
-def encode_ffmpeg_y4m(pin,pout,size,is24fps,quality,crf):
+def encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf):
"""
"""
x264_thread="auto"
x264_addline=configreader.getenv("x264_addline")
if size == "HD":
- s = "-s 1280x720 "
- #x264streamsize=u"1280x720"
+ padx=get16_9ffmpeg_s(pin,1280,720)
+ s = "-s "+str(1280-2*padx)+"x720 "
+ if padx>0:
+ s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
+ x264streamsize=u"1280x720"
x264_bitrate="2500"
elif size == "WVGA":
- s = "-s 854x480 "
- #x264streamsize=u"854x480"
+ padx=get16_9ffmpeg_s(pin,854,480)
+ s = "-s "+str(854-2*padx)+"x480 "
+ if padx>0:
+ s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
+ x264streamsize=u"854x480"
x264_bitrate="1500"
elif size == "FullHD":
- s = "-s 1920x1080 "
- #x264streamsize=u"1920x1080"
+ padx=get16_9ffmpeg_s(pin,1920,1080)
+ s = "-s "+str(1920-2*padx)+"x1080 "
+ if padx>0:
+ s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
+ x264streamsize=u"1920x1080"
x264_bitrate="5000"
elif size == "SD":
s = "-s 720x480 "
- #x264streamsize=u"720x480"
+ x264streamsize=u"720x480"
x264_bitrate="1250"
elif size == "QVGA_BASE":
s = "-s 320x240 "
- #x264streamsize=u"320x240"
+ x264streamsize=u"320x240"
x264_bitrate="300"
elif size == "WVGA_BASE":
s = "-s 854x480 "
- #x264streamsize=u"854x480"
+ x264streamsize=u"854x480"
x264_bitrate="1500"
else:
- s = "-s 1280x720 "
- #x264streamsize=u"1280x720"
+ padx=get16_9ffmpeg_s(pin,1280,720)
+ s = "-s "+str(1280-2*padx)+"x720 "
+ if padx>0:
+ s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
+ x264streamsize=u"1280x720"
x264_bitrate="2500"
if quality==1:
x264preset=u"--preset ultrafast"
x264crf=u"--crf "+str(crf)
txt=""
os.environ['LANG']="ja_JP.UTF-8"
- #exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
- random.seed(pin)
- random.jumpahead(10)
- streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999))+".y4m")
- os.system(u"mkfifo "+streampath)
- exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -f yuv4mpeg "+s+fps+"-deinterlace -an -f rawvideo - |"
- exe=exe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" \""+streampath+"\" "+x264streamsize
+ exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
+ exe=exe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
exe = "nice -n 19 " + exe
txt=""
recdblist.printutf8(exe)
except:
""
recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
+def getMovieSize(pin):
+ ffmpeg=configreader.getpath("ffmpeg")
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+u" \""+pin+"\" 2>&1"
+ txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
+ rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
+ sizeMaxX=0
+ sizeMaxY=0
+ txtls=txts.split("\n")
+ for t in txtls:
+ rM=rT.match(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])
+ tX2=tX*tEX*10/tEY
+ if tX2>10*int(tX2/10):
+ tX2=tX2/10+1
+ if sizeMaxX<tX:
+ sizeMaxX=tX2
+ sizeMaxY=tY
+ return [sizeMaxX,sizeMaxY]
+def getMovieDAR(pin):
+ ffmpeg=configreader.getpath("ffmpeg")
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+u" \""+pin+"\" 2>&1"
+ txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
+ rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+DAR\D+(\d+:\d+)\D+.*\Z")
+ sizeMaxX=0
+ darx=0
+ dary=0
+ txtls=txts.split("\n")
+ for t in txtls:
+ rM=rT.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
+ darx=tEX
+ dary=tEY
+ return [darx,dary]
+def get16_9ffmpeg_s(pin,x,y):
+ try:
+ tDAR=getMovieDAR(pin)
+ if (tDAR[0]==16 and tDAR[1]==9):
+ return 0
+ else:
+ tSize=getMovieSize(pin)
+ tn=y-tSize[1]*x/tSize[0]
+ tn=tn/4
+ tn=tn*2#偶数にするための処理
+ return tn
+ except:
+ return 0
\ No newline at end of file