You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svcd.py 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ###############################################
  2. # Convert to SVCD adm tinypy script
  3. # Mean 2011
  4. ###############################################
  5. import ADM_imageInfo
  6. import ADM_image
  7. finalSizeWidth=720 # Start with DVD target, we'll adjust later
  8. finalSizeHeight=[ 480,576,480]
  9. #
  10. adm=Avidemux()
  11. gui=Gui()
  12. #
  13. MP2=80
  14. supported=[MP2]
  15. ##########################
  16. # Compute resize...
  17. ##########################
  18. source=ADM_image.image()
  19. dest=ADM_image.image()
  20. desc=""
  21. true_fmt=ADM_imageInfo.get_video_format(desc)
  22. if(true_fmt is None):
  23. raise
  24. fmt=true_fmt
  25. if(true_fmt==ADM_image.FMT_FILM):
  26. fmt=ADM_image.FMT_NTSC
  27. source.width=adm.getWidth()
  28. source.height=adm.getHeight()
  29. source.fmt=fmt
  30. dest.fmt=fmt
  31. print("Format : "+str(fmt))
  32. dest.width=16
  33. dest.height=16
  34. #*****************************
  35. # Dialog...
  36. #*****************************
  37. #
  38. mnuResolution = DFMenu("Resolution:");
  39. mnuSourceRatio = DFMenu("Source Aspect Ratio:");
  40. mnuSourceRatio.addItem("1:1")
  41. mnuSourceRatio.addItem("4:3")
  42. mnuSourceRatio.addItem("16:9")
  43. mnuDestRatio = DFMenu("Destination Aspect Ratio:");
  44. mnuDestRatio.addItem("4:3")
  45. mnuDestRatio.addItem("16:9")
  46. dlgWizard = DialogFactory("auto SVCD ("+desc+")");
  47. dlgWizard.addControl(mnuSourceRatio);
  48. dlgWizard.addControl(mnuDestRatio);
  49. res=dlgWizard.show()
  50. if res!=1:
  51. exit()
  52. source.ar=mnuSourceRatio.index
  53. dest.ar=mnuDestRatio.index+1
  54. resizer=source.compute_resize(source,dest,finalSizeWidth,finalSizeHeight,ADM_imageInfo.aspectRatio)
  55. if(resizer is None):
  56. exit()
  57. print("Resize to "+str(resizer.width)+"x"+str(resizer.height))
  58. # Correct so that result is 2/3 D1 i.e. 480xxxx
  59. newW=resizer.width
  60. newW=(newW*480)/720
  61. newW=newW&0xffc
  62. resizer.width=newW
  63. resizer.leftright=(480-newW)/2
  64. source.apply_resize(resizer)
  65. ############################
  66. # Handle audio....
  67. ############################
  68. tracks=adm.audioTracksCount()
  69. print("We have "+str(tracks)+ " audio tracks.")
  70. if tracks==0:
  71. gui.displayError("Audio","No audio tracks!")
  72. exit()
  73. for i in range(0,tracks):
  74. encoding=adm.audioEncoding(i)
  75. fq=adm.audioFrequency(i)
  76. channels=adm.audioChannels(i)
  77. reencode=False
  78. # 1 check frequency
  79. if(fq != 44100):
  80. adm.audioSetResample(i,44100)
  81. reencode=True
  82. if(not(encoding in supported)):
  83. reencode=True
  84. if(channels!=2):
  85. adm.audioSetMixer(i,"STEREO")
  86. reencode=True
  87. if(True==reencode):
  88. adm.audioCodec(i,"TwoLame","bitrate=224")
  89. ##################################
  90. # Video
  91. ##################################
  92. ff_ar=0
  93. if(resizer.ar==ADM_image.AR_16_9):
  94. ff_ar=1
  95. #
  96. adm.videoCodec("ffMpeg2","params=CQ=4","lavcSettings=:version=2:MultiThreaded=2:me_method=5:_GMC=0:_4MV=0:_QPEL=0:_TRELLIS_QUANT=1:qmin=2:qmax=31:max_qdiff=3:max_b_frames=2:mpeg_quant=1:is_luma_elim_threshold=1:luma_elim_threshold=4294967294:is_chroma_elim_threshold=1:chroma_elim_threshold=4294967291:lumi_masking=0.050000:is_lumi_masking=1:dark_masking=0.010000:is_dark_masking=1:qcompress=0.500000:qblur=0.500000:minBitrate=0:maxBitrate=2400:user_matrix=1:gop_size=18:interlaced=0:bff=0:widescreen="+str(ff_ar)+":mb_eval=2:vratetol=8000:is_temporal_cplx_masking=0:temporal_cplx_masking=0.000000:is_spatial_cplx_masking=0:spatial_cplx_masking=0.000000:_NORMALIZE_AQP=0:use_xvid_ratecontrol=0:bufferSize=112:override_ratecontrol=0:dummy=0","matrix=1")
  97. ###################################
  98. # Container = Mpeg PS/DVD
  99. ###################################
  100. #
  101. adm.setContainer("ffPS","muxingType=1","acceptNonCompliant=False","muxRatekBits=2800","videoRatekBits=2400","bufferSizekBytes=112")
  102. #