From 93e92027324926af8806740c52a0093ef7e679c8 Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Sat, 17 Jul 2010 08:38:10 +0000 Subject: [PATCH] implement interlaced encode option(alpha ver). git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@647 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/readme.txt | 2 + rec10/trunk/src/ts2x264.py | 294 +++------------------------------------------ rec10/trunk/src/tv2mp4.py | 2 + 3 files changed, 23 insertions(+), 275 deletions(-) diff --git a/rec10/trunk/src/readme.txt b/rec10/trunk/src/readme.txt index d65b2b3..922cd0c 100644 --- a/rec10/trunk/src/readme.txt +++ b/rec10/trunk/src/readme.txt @@ -69,6 +69,8 @@ chdata.pyを実行してください(python chdata.py) yukikaze.jp@gmail.com [History] +?/?/? 0.9.8 release +インターレース保持エンコードに試験的対応 10/07/10 0.9.7 release ヒストリーチャンネルのタイトルを修正 ffmpeg使用時にscale拡大をするように修正 diff --git a/rec10/trunk/src/ts2x264.py b/rec10/trunk/src/ts2x264.py index e446e54..c131ea9 100644 --- a/rec10/trunk/src/ts2x264.py +++ b/rec10/trunk/src/ts2x264.py @@ -21,6 +21,7 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" quality=4 quality=int(configreader.getenv("x264_preset")) crf=int(configreader.getenv("crf")) + deinterlace=1 if re.search("H", opts): size = "HD" if re.search("S", opts): @@ -41,6 +42,8 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" if re.search("a", opts): is24fps=1 crf=int(configreader.getenv("animation_crf")) + if re.search("I", opts): + deinterlace=0 if re.search("q",opts): quality=quality-2 if re.search("w",opts): @@ -58,120 +61,21 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" if re.search("p",opts): crf=crf-2 if re.search("d",opts): - #encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf) - encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf) + encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace) elif re.search("5",opts): - #encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf) - encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf) - elif re.search("Y",opts): - encode_sar(pin,pout,size,is24fps,quality,crf) - elif re.search("Z",opts): - encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf) + encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace) elif re.search("b",opts): try: tm2v=pin.replace(".ts",".m2v") - #encode(tm2v, pout,size,is24fps,quality,crf) - encode_sar(tm2v, pout,size,is24fps,quality,crf) + encode_sar(tm2v, pout,size,is24fps,quality,crf,deinterlace) except Exception, inst: recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)) else: try: - #encode(pin, pout,size,is24fps,quality,crf) - encode_sar(pin, pout,size,is24fps,quality,crf) + encode_sar(pin, pout,size,is24fps,quality,crf,deinterlace) except Exception, inst: recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)) -def encode(pin,pout,size,is24fps,quality,crf): - mencoder=configreader.getpath("mencoder") - x264=configreader.getpath("x264") - encvf="" - txt="" - encvf="-vf yadif=0,pp=l5" - harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" - ofps="-ofps 30000/1001" - fps="-fps 30000/1001" - x264fps="--fps 30000/1001" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="5000" - x264_thread="auto" - try: - xtt=configreader.getenv("x264_thread") - xtt=int(xtt) - if xtt>0: - x264_thread=str(xtt) - except: - x264_thread="auto" - x264_addline=configreader.getenv("x264_addline") - if is24fps==1: - ofps="-ofps 24000/1001" - fps="-fps 30000/1001" - x264fps="--fps 24000/1001" - x264tune="--tune animation" - encvf="-vf pullup,softskip" - harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup" - if size == "HD": - encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup - x264streamsize=u"1280x720" - x264_bitrate="2500" - elif size == "WVGA": - encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup - x264streamsize=u"854x480" - x264_bitrate="1500" - elif size == "FullHD": - encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup - x264streamsize=u"1920x1080" - x264_bitrate="5000" - elif size == "SD": - encvf = encvf + ",scale=720:-2::0:3,expand=720:480"+harddup - x264streamsize=u"720x480" - x264_bitrate="1250" - elif size == "QVGA_BASE": - encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup - x264streamsize=u"320x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup - x264streamsize=u"854x480" - x264_bitrate="1500" - else: - encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup - x264streamsize=u"1280x720" - x264_bitrate="2500" - if quality==1: - x264preset=u"--preset ultrafast" - elif quality==2: - x264preset=u"--preset veryfast" - elif quality==3: - x264preset=u"--preset fast" - elif quality==4: - x264preset=u"--preset medium" - elif quality==5: - x264preset=u"--preset slow" - elif quality==6: - x264preset=u"--preset slower" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - x264crf=u"--crf "+str(crf) - os.environ['LANG']="ja_JP.UTF-8" - random.seed(pin) - random.jumpahead(10) - streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999))) - os.system(u"mkfifo "+streampath) - encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" &" - encexe=encexe+u" nice -n 19 "+x264+" "+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) - txt="" - try: - txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8') - except: - "" - os.system("rm "+streampath) - recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) -def encode_sar(pin,pout,size,is24fps,quality,crf): +def encode_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1): mencoder=configreader.getpath("mencoder") x264=configreader.getpath("x264") encvf="" @@ -203,6 +107,13 @@ def encode_sar(pin,pout,size,is24fps,quality,crf): x264tune="--tune animation" encvf="-vf pullup,softskip" harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup" + if deinterlace==0: + ofps="-ofps 60000/1001" + fps="-fps 60000/1001" + x264fps="--fps 60000/1001" + x264tune="--tune animation --tff --nal-hrd vbr" + encvf="-vf hqdn3d=2:1:2" + harddup=",harddup" if size == "HD": tsize=get_par_size(pin,720) encvf = encvf + ",scale=-3:720::0:3"+harddup @@ -248,7 +159,7 @@ def encode_sar(pin,pout,size,is24fps,quality,crf): if size == "WVGA_BASE" or size == "QVGA_BASE": x264profile=" --level 32 --profile baseline " else: - x264profile=" --level 41 --profile high " + x264profile=" --level 42 --profile high " x264crf=u"--crf "+str(crf) os.environ['LANG']="ja_JP.UTF-8" random.seed(pin) @@ -267,85 +178,8 @@ def encode_sar(pin,pout,size,is24fps,quality,crf): os.system("rm "+streampath) recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) -def encode_ffmpeg(pin,pout,size,is24fps,quality,crf): - """ - - """ - ffmpeg=configreader.getpath("ffmpeg") - x264=configreader.getpath("x264") - fps=u"-r 29.970030 " - x264fps="--fps 30000/1001" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="2500" - x264_thread="auto" - try: - xtt=configreader.getenv("x264_thread") - xtt=int(xtt) - if xtt>0: - x264_thread=str(xtt) - except: - x264_thread="auto" - x264_addline=configreader.getenv("x264_addline") - if size == "HD": - s = "-s 1280x720 " - x264streamsize=u"1280x720" - x264_bitrate="2500" - elif size == "WVGA": - s = "-s 854x480 " - x264streamsize=u"854x480" - x264_bitrate="1500" - elif size == "FullHD": - s = "-s 1920x1080 " - x264streamsize=u"1920x1080" - x264_bitrate="5000" - elif size == "SD": - s = "-s 720x480 " - x264streamsize=u"720x480" - x264_bitrate="1250" - elif size == "QVGA_BASE": - s = "-s 320x240 " - x264streamsize=u"320x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - s = "-s 854x480 " - x264streamsize=u"854x480" - x264_bitrate="1500" - else: - s = "-s 1280x720 " - x264streamsize=u"1280x720" - x264_bitrate="2500" - if quality==1: - x264preset=u"--preset ultrafast" - elif quality==2: - x264preset=u"--preset veryfast" - elif quality==3: - x264preset=u"--preset fast" - elif quality==4: - x264preset=u"--preset medium" - elif quality==5: - x264preset=u"--preset slow" - elif quality==6: - x264preset=u"--preset slower" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - 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 - |" - 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) - try: - txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8') - except: - "" - recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) -def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf): + +def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf,deinterlace=1): """ """ @@ -418,7 +252,7 @@ def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf): if size == "WVGA_BASE" or size == "QVGA_BASE": x264profile=" --level 32 --profile baseline " else: - x264profile=" --level 41 --profile high " + x264profile=" --level 42 --profile high " x264crf=u"--crf "+str(crf) txt="" os.environ['LANG']="ja_JP.UTF-8" @@ -432,96 +266,6 @@ def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf): except: "" recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) -def encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf): - """ - - """ - ffmpeg=configreader.getpath("ffmpeg") - x264=configreader.getpath("x264") - fps=u"-r 29.970030 " - x264fps="--fps 30000/1001" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="2500" - x264_thread="auto" - try: - xtt=configreader.getenv("x264_thread") - xtt=int(xtt) - if xtt>0: - x264_thread=str(xtt) - except: - x264_thread="auto" - x264_addline=configreader.getenv("x264_addline") - if size == "HD": - 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": - 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": - 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" - x264_bitrate="1250" - elif size == "QVGA_BASE": - s = "-s 320x240 " - x264streamsize=u"320x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - s = "-s 854x480 " - x264streamsize=u"854x480" - x264_bitrate="1500" - else: - 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" - elif quality==2: - x264preset=u"--preset veryfast" - elif quality==3: - x264preset=u"--preset fast" - elif quality==4: - x264preset=u"--preset medium" - elif quality==5: - x264preset=u"--preset slow" - elif quality==6: - x264preset=u"--preset slower" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - 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 - |" - 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) - try: - txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8') - except: - "" - recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) def getMovieSize(pin): ffmpeg=configreader.getpath("ffmpeg") os.environ['LANG']="ja_JP.UTF-8" diff --git a/rec10/trunk/src/tv2mp4.py b/rec10/trunk/src/tv2mp4.py index 9043a68..feb8ce1 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -40,6 +40,8 @@ def raw2mp4(pin,pout,opt): duration="-fps 29.970030 " if re.search("a",opt): duration="-fps 23.976023 " + elif re.search("I",opt): + duration="-fps 59.940060 " elif re.search("v",opt): duration="-fps 23.976023 " if re.search("d",opt): -- 2.11.0