2010年5月24日月曜日

久しぶりにubuntuでavisynthを使う


http://forum.doom9.org/showthread.php?t=144271
このスクリプトを改造した。
オリジナルは8mmフィルムレストア用なので、そのまま使うとシャープが強すぎて再生速度も変わる。



モーションデータはMVToolsの方が精度が高いけれども、処理が遅いのでDePanEstimateを使う。



手順
1.dvgrabでキャプチャしたdvファイルをkinoでトリミング書き出し。音声だけも書き出し
2.avisynthに読ませるために、無圧縮aviに変換





$ mencoder キャプチャしたファイル名.dv -nosound -ovc raw  -vf format=yuy2 -o avisynthに読ませるファイル名.avi
3.avsスクリプトを実行。



$ wine avs2yuv.exe スクリプト名.avs - | mencoder - -o 処理されたファイル名.avi  -ovc lavc -lavcopts vcodec=ffvhuff:vstrict=-1:pred=2:context=1 -demuxer y4m
4.書き出しておいた音声とavsスクリプトを実行された動画を合成。



$ ffmpeg -i 切り出し音声.wav -i 処理されたファイル名.avi -target ntsc-dv -|ffmpeg2theora - -x 720 -y 202 -o 書き出すファイル名.ogg #アップロードする時
$ ffmpeg -i 切り出し音声.wav -i 処理されたファイル名.avi -target ntsc-dv dvファイル名.dv  #dvにする時



5.avsファイルの拡張子をshに変えてhiglightで色分けHTMLで書き出し。



$ highlight -J 80 -z -n -l -W -t  -s ide-msvs2008  -i avsファイル.sh -o 書き出し.html






<p><p>test.sh</p></p>


  1. # film restoration script by videoFred.

  2. # denoising, resizing, stabilising, sharpening, auto-levels and auto-white

  3. balance.

  4. #===========================================================================


  5.   =========

  6. film="/home/poi/ex1.avi"

  7. #GENERAL PARAMETERS

  8. #---------------------------------------------------------------------------

  9. -------------------------------------------------

  10. result="resultS5" # specify the wanted output here


  11. #COLOR AND LEVELS PARAMATERS

  12. #---------------------------------------------------------------------------

  13. -------------------------------------------------

  14. saturation=1.4   #for all outputs

  15.  

  16. gamma=1.2 # for all outputs


  17.  

  18. blue= -0  red=-0  #manual color adjustment, when returning result3. Values

  19.       can be positive or negative

  20.  

  21.  

  22. black_level=0  white_level=255 output_black=0  output_white=255 # manual


  23.             levels, when returning result4

  24.  

  25.  

  26. #SIZE, CROP AND BORDERS PARAMETERS

  27. #---------------------------------------------------------------------------

  28. -------------------------------------------------

  29. CLeft=20  CTop=20  CRight=20  CBottom=20  #crop values after Depan and


  30.       before final resizing

  31.  

  32. W=720  H=404 #final size after cropping

  33.  

  34. bord_left=0  bord_top=0  bord_right=0  bord_bot=0  #720p= borders 150


  35.  

  36.  

  37. #STABILISING PARAMETERS

  38. #---------------------------------------------------------------------------

  39. -------------------------------------------------

  40. maxstabH=30

  41. maxstabV=30 #maximum values for the stabiliser (in pixels) 20 is a good


  42.          start value

  43.  

  44. est_left=40   est_top=40  est_right=40  est_bottom=40  est_cont=1.6  #crop


  45.          and contast values for special Estimate clip

  46. #DENOISING PARAMETERS

  47. #---------------------------------------------------------------------------

  48. -------------------------------------------------

  49.  

  50. denoising_strenght=600  #denoising level of first denoiser: MVDegrainMulti()

  51. denoising_frames= 2  #number of frames for averaging (forwards and


  52.                   backwards) 3 is a good start value

  53. block_size= 16  #block size of MVDegrainMulti()

  54. block_size_v= 16

  55. block_over= 8  #block overlapping of MVDegrainMulti()


  56.  

  57.  

  58. second_denoising_strenght= 400 #denoising level of second denoiser:

  59.                            MDegrain1()

  60.  

  61. temp_radius=4  temp_luma=3  temp_chroma=3  #final smoother: TemporalSoften()


  62. #FOUR STEP SHARPENING PARAMETERS

  63. #---------------------------------------------------------------------------

  64. -----------------------------------------------------

  65.  

  66. PRE_sharp_ness= 120   PRE_radi_us= 3  #presharpening (UnsharpMask) just


  67.                 after first denoising

  68.  

  69. LSF_sharp_ness=160 LSF_radi_us=2  LSF_sub=1.5 #second sharpening parameters


  70.                (LimitedSharpenFaster) sub=subsampling

  71. USM_sharp_ness2= 50    USM_radi_us2=1  USM_thres_hold2=0  #third sharpening


  72.                  parameters (UnsharpMask)

  73.  

  74. last_sharp= 0.5 # final sharpening step after interpolation

  75.  

  76. mo_blur= 10 #this will add some motion blur, can be useful in panning


  77.          scenes etc..

  78. #AUTO LEVELS PARAMETER

  79. #---------------------------------------------------------------------------

  80. -----------------------------------------------------

  81. X=4   # X is a special parameter for reducing the autolevels effect on the

  82.   whites


  83. X2=2  # X2 is a special parameter for reducing the autolevels effect on the

  84.    blacks

  85. # END VARIABLES, BEGIN SCRIPT

  86. #===========================================================================

  87.   ======================================================

  88. SetMemoryMax(800)  #set this to 1/3 of the available memory


  89. LoadPlugin("GuavaComb.dll")

  90. LoadPlugin("TDeint.dll")

  91.  

  92. LoadPlugin("AGC.dll")

  93. LoadPlugin("Deflicker.dll")


  94. Loadplugin("Depan.dll")

  95. LoadPlugin("DepanEstimate.dll")

  96. Loadplugin("removegrain.dll")

  97. LoadPlugin("MVTools.dll")


  98. LoadPlugin("MVTools2.dll")

  99. Loadplugin("mt_masktools.dll")

  100. Loadplugin("warpsharp.dll")

  101. LoadPlugIn("LimitedSupport_09Jan06B.dll")


  102. LoadPlugin("autolevels.dll")

  103. Import("LimitedSharpenFaster.avs")

  104.  

  105. source0= Avisource(film).Lanczos4Resize(720,404).converttoYV12().TDeint()


  106. source1= Avisource(film).Lanczos4Resize(720,404).converttoYV12().TDeint()


  107. #STABILIZING

  108. #...........................................................................

  109. ............................................................................

  110. .............

  111. stab_reference= source1.crop(est_left,est_top,-est_right,-est_bottom).tweak(


  112.                 cont=est_cont).MT_binarize(threshold=80).greyscale().invert(

  113.                 )


  114. vectors = stab_reference.MSuper().MVAnalyseMulti()

  115. globalmotion = stab_reference.MVDepan(vectors)

  116. mdata=globalmotion


  117. stab2=DePanStabilize(source1,data=mdata,method=0,mirror=15,info=true,


  118.       cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,rotmax=10)


  119. WS= width(stab2)

  120. HS= height(stab2)

  121. #DENOISING


  122. #...........................................................................

  123. ............................................................................

  124. ............

  125. noise_baseclip= stab2.HDRAGC( min_gain = 3.0,avg_window=30,corrector=1,


  126.                 debug=0,coef_sat=2)

  127. #SHARPENING

  128. #...........................................................................

  129. ............................................................................

  130. ............


  131. sharp1=limitedSharpenFaster(noise_baseclip,smode=1,strength=LSF_sharp_ness,

  132.        overshoot=50,radius=LSF_radi_us, ss_X=LSF_sub, SS_Y=LSF_sub,


  133.        dest_x=W,dest_y=H)

  134. #RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5

  135. #...........................................................................

  136. ............................................................................

  137. ..............


  138. result6= sharp1.ConvertToYUY2().GuavaComb(mode="NTSC").converttoYV12()

  139. #COMPARISONS: ORIGINAL VS RESULTS

  140. #...........................................................................


  141. ............................................................................

  142. ...............

  143. resultS5= stackhorizontal(subtitle(source0,"original",size=56,align=6),


  144.           subtitle(result6,"stabiliser+AGC.dll",size=56,align=6))

  145. Eval(result)


  146.