OSDN Git Service

fix scale option of mencoder when blu-ray and interlaced option.
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
index 25b848d..4a2b37f 100644 (file)
@@ -38,9 +38,11 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
     if re.search("MW1",opts):\r
         size = "QVGA_BASE"\r
         crf=crf+4\r
+        sar=0\r
     if re.search("MW2", opts):\r
         size = "WVGA_BASE"\r
         crf=crf+2\r
+        sar=0\r
     if re.search("v", opts):\r
         is24fps=1\r
         crf=int(configreader.getConfEnv("animation_crf"))\r
@@ -180,18 +182,21 @@ def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,uselavf=0,
         ofps="-ofps 30000/1001"\r
         #fps="-fps 30000/1001"\r
         fps=""\r
-        x264fps="30000/1001"\r
+        x264fps="30000/1001 --keyint 30"\r
         x264interlaced=1\r
         encvf="-vf hqdn3d=2:1:2"\r
         harddup=",harddup"\r
         encvf=encvf+harddup\r
         x264streamsize=str(tsize[0])+u"x"+str(tsize[1])\r
+        if usebluray==1:\r
+            encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup\r
+            x264streamsize=u"1920x1080"\r
     if tsize[0] <= 0 or tsize[1] <= 0:\r
         encvf="-sws 9 -vf yadif=0,pp=l5"\r
         harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"\r
         ofps="-ofps 30000/1001"\r
         fps="-fps 30000/1001"\r
-        x264fps="30000/1001"\r
+        x264fps="30000/1001 --keyint 30"\r
         tsize=[1280,720]\r
         encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup\r
         x264streamsize=u"1280x720"\r
@@ -310,7 +315,7 @@ def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,
         tsize=getMovieBaseSize2(pin)\r
         fps=""\r
         s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" "\r
-        x264fps="30000/1001"\r
+        x264fps="30000/1001 --keyint 30"\r
         x264interlaced=1\r
         filter=""\r
         x264streamsize=str(tsize[0])+u"x"+str(tsize[1])\r
@@ -380,6 +385,12 @@ def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更された
     ffmpeg=configreader.getConfPath("ffmpeg")\r
     os.environ['LANG']="ja_JP.UTF-8"\r
     exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"\r
+    try:\r
+        recdblist.addCommandSelfLog(pin, exe)\r
+    except Exception, inst:\r
+        print type(inst)\r
+        print str(inst)\r
+        print traceback.print_exc(file=sys.stdout)\r
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')\r
     rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")\r
     sizeMaxX=0\r
@@ -431,6 +442,12 @@ def getMoviePAR2(pin):
     ffmpeg=configreader.getConfPath("ffmpeg")\r
     os.environ['LANG']="ja_JP.UTF-8"\r
     exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"\r
+    try:\r
+        recdblist.addCommandSelfLog(pin, exe)\r
+    except Exception, inst:\r
+        print type(inst)\r
+        print str(inst)\r
+        print traceback.print_exc(file=sys.stdout)\r
     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')\r
     rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")\r
     sizeMaxX=0\r
@@ -528,7 +545,9 @@ def getParSize(pin,y):
     return [tX,tY]\r
 def getX264CoreVersion():\r
     x264=configreader.getConfPath("x264")\r
+    #print x264\r
     t1=commands.getoutput(x264+" --help|grep core")\r
+    #print t1\r
     rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")\r
     rM=rT.match(t1)\r
     v=-1\r
@@ -551,8 +570,38 @@ def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsi
     if interlaced==1:\r
         x264interlaced="--tff --nal-hrd vbr"\r
     if bluray==1:\r
-        x264bluray="--weightp 1 --bframes 3 --nal-hrd vbr --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 "\r
-        x264_addline=""\r
+        if getX264CoreVersion()<115:\r
+            x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 "\r
+            x264_addline=""\r
+            if fps=="24000/1001 --keyint 24" or fps =="24000/1001":\r
+                if x264streamsize=="1280x720":\r
+                    x264bluray=u"--ref 6 "+x264bluray\r
+                if x264streamsize=="1920x1080":\r
+                    x264bluray=u"--ref 4 "+x264bluray\r
+            elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":\r
+                if x264streamsize=="1280x720":\r
+                    x264bluray=u"--ref 6 --pulldown double "+x264bluray\r
+                if x264streamsize=="1920x1080":\r
+                    if interlaced==0:\r
+                        x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray\r
+                    else:\r
+                        x264bluray=u"--ref 4 "+x264bluray\r
+        elif getX264CoreVersion()>=115:\r
+            x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 "\r
+            x264_addline=""\r
+            if fps=="24000/1001 --keyint 24" or fps =="24000/1001":\r
+                if x264streamsize=="1280x720":\r
+                    x264bluray=u"--ref 6 "+x264bluray\r
+                if x264streamsize=="1920x1080":\r
+                    x264bluray=u"--ref 4 "+x264bluray\r
+            elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":\r
+                if x264streamsize=="1280x720":\r
+                    x264bluray=u"--ref 6 --pulldown double "+x264bluray\r
+                if x264streamsize=="1920x1080":\r
+                    if interlaced==0:\r
+                        x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray\r
+                    else:\r
+                        x264bluray=u"--ref 4 "+x264bluray\r
     x264_thread="auto"\r
     try:\r
         xtt=configreader.getConfEnv("x264_thread")\r
@@ -564,7 +613,7 @@ def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsi
     x264_addline=configreader.getConfEnv("x264_addline")\r
     if getX264CoreVersion()>103:\r
         x264res=u"--input-res "+x264streamsize\r
-        exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin\r
+        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\r
     else:\r
-        exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize\r
+        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\r
     return exe\r