Advertisement
Guest User

DVD/ISO convolution-optimized transcoding to h264 formats

a guest
Nov 24th, 2015
1,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.49 KB | None | 0 0
  1.  
  2. #--------------- How to manage DVD-ISO file transcoding to the h264 format (mp4) with optimized quality ------------------
  3. #
  4. # Save this file as "MyProject.avs". Below the long description, there is a usable template script.
  5. #
  6. # This is an Avisynth project to be used with a corresponding AviDemux settings/preset package.
  7. # Source material should stem from DVD/ISO in NTSC format, 30 fps interlaced or non-interlaced (switch on/off yadif).
  8. # Adjust to other formats at your need.
  9. # Instructions below are valid for Windows OS, plz use the corresponding install procedures in case of LINUX.
  10. #
  11. # Its special features are:
  12. # customized convolutional processing, together with a smart filtering chain, and upsampling technique.
  13. #
  14. # Results in many cases will look remarkably better than what the regular video players in a computer will deliver from the DVD directly.
  15. # Players on current consumer hardware in realtime operation can hardly make use of sophisticated upsampling filters, they would become slow.
  16. # Further, with certain types of DVDs, typical attempts with one-click-default transcoding procedures will look quite poor and blurred,
  17. # thus we seek something better. Also, the upsampling makes the resulting videos more independent from the quality of the player.
  18. #
  19. # The purpose is to make the video look sharp, smooth, and calm, while not losing any texture e.g. of the skin or a rocky landscape.
  20. # Naturally, this depends on your decision to allow sufficient bitrates.
  21. # Experience shows good quality with space consumption from 10 to 30 MB's per minute of video length, according to the type and
  22. # style of the video. Interlaced sources will result in 60fps, but can take 20-30% more space than 30fps. Much more pleasant to view.
  23. # Encoding time is fair for the quality, depending on the computer and CPU. You may make 5 to 20 frames per second.
  24. # (5 fps speed was checked out with a cheap Windows tablet, sitting in the corner all night chewing..)
  25. #
  26.  
  27. # ------------------------------------------------------------------------------
  28. # Prerequisites
  29. # ------------------------------------------------------------------------------
  30. #
  31. # A.1. Install Avisynth+ 64 bit
  32. # (Standard avisynth may be usable, but you need to check out for yourself. If your OS is 64bit, then stick to that in all of these tools here.)
  33. # http://avisynth.nl/index.php/Main_Page; then search the Plus-versions download.
  34. #
  35. # Avisynth works with avs-scripts that define input, a chain of processings, and output.
  36. # This text here serves as a template, and already can be used as an Avisynth project script,
  37. # but for actual work you need to enter the particular input file specifications, *************
  38. # and sometimes tailor a couple of settings to certain properties of the video.
  39. #
  40. # A.2. Find the yadif.dll deinterlacer - it not there, it is easy to download. See the avisynth filter listings for deinterlacing.
  41. # It should be found in a directory like C:\programs\AviSynth+\plugins\yadif.dll.
  42. # This is the deinterlacer that we use for creating 60fps videos (double framerate).
  43. # You may experiment with any other deinterlacers, but this one is fairly fast, and serves video with good sharpness.
  44. # The known yadif artifacts are being mitigated somewhat, by some particular filtering processes within this project.
  45. # Caution! Some DVDs are _not_ interlaced, then switch off deinterlacing with putting # comment tags, before the yadif lines in the script below.
  46. #
  47. # A.3. DGIndex and DGDecode - (tested version is 1.4.8.)
  48. # You also need the mpeg2 decoding tool for Avisynth -- dgdecode.dll
  49. # It should be found in a directory like C:\programs\AviSynth+\dgdecode.dll, or put it there.
  50. # It is part of a package together with the DGIndex.exe utility.
  51. # These tools must come from the same version number. DGIndex and DGDecode from different update versions are incompatible.
  52. # Hint: There are load commands in the script below, for yadif.dll and dgdecode.dll.
  53. # Thus, the dll files have to be found in the corresponding directories. Edit the path specifications in the load() commands.
  54. #
  55. # DGIndex.exe is the first program to use, it has to prepare the ISO file to be understood by the actual decoder,
  56. # by creating an additional d2v file.
  57. #
  58. #
  59. # B.1. Install Avidemux 64 bit -- www.avidemux.org - (tested version is 2.6.8)
  60. # This is the actual transcoding program that reads the Avisynth video data, applies more filtering, and invokes the in-built x264 encoder.
  61. # It has a nice user interface that lets you select and test filter processing like color corrections, resizing, sharpening etc..
  62. # Below at the bottom, you will find a customized MyProject.py script file that has been tuned to the generic properties of this project.
  63. # You'll have to save away that file and later load it in Avidemux as a project script.
  64. #
  65. # B.2. Install AVSProxy and AVSProxy-Gui - (tested version is 2.20)
  66. # AVSProxy is a helper utility for the AviDemux transcoding program, to be used together with Avisynth.
  67. # It may come packaged already with Avidemux.
  68. # In this type of project, AviDemux will not open a file but rather a virtual channel created by AVSProxy.
  69. # Thus, AVSProxy connects the Avidemux program with Avisynth, that serves the decoded and preprocessed video raw data from the ISO file.
  70.  
  71.  
  72.  
  73. # ------------------------------------------------------------------------------
  74. # Operational Instructions
  75. # ------------------------------------------------------------------------------
  76. #
  77. # 0. Short version
  78. #
  79. # ("MyProject" always means the actual name of your ISO file, and of corresponding work scripts that you make for it.)
  80. #
  81. # Index MyProject.ISO with DGindex. Make it decode and write the audio wav also!
  82. # You may have to select beforehand the actual video segment with [ and ] buttons.
  83. # The resulting files are "MyProject.d2v" and "MyProject...kHz.WAV".
  84. #
  85. # Create a copy of this template you are reading right now, and name it "MyProject.avs".
  86. # Edit the "MyProject.avs" file, to have the read command in MPEG2Source() point to the d2v file.
  87. # Caution: When the video is not interlaced, remove the yadif() from the avs, else only every other frame will move and you waste file space and CPU.
  88. # Open resulting avs with avsproxy_gui.exe, [Custom] tab.
  89. #
  90. # Start Avidemux and connect it to the Avisynth channel, that was created with the steps mentioned above.
  91. # Open the "MyProject.py" settings file from the Menu - Tinypy - RunProject dialog. (Only after connecting w/proxy, else crash.)
  92. # Check that all audio is deactivated.
  93. # Adjust Video - Filters (optionally), and encoder compression rate (22-24 are the most useful compression values for this type of conversion).
  94. # From the filters, Contrast and Avisynth color filters are both optional and can be removed if the result is ok without. The Presets yield nice depth.
  95. # Remove the final sharpening filter, when results look oversharpened.
  96. # Check container type, normally use mp4.
  97. # Check start and end of the video. The copied py template file does not serve a correct video length, but this won't stop the show.
  98. # Set desired encoding time interval with the A and B buttons, or encode the whole. Without editing the WAV, [A] can start only with 0:00.
  99. # (Probably leave out the menu stuff already in DGIndex, as it spoils audio timing.)
  100. # Save the py settings file again, for your particular project.
  101. #
  102. # In the File menu, save the file "MyProject.mp4" and wait some hours for the encoding to complete. Encoding with audio included would run even slower.
  103. #
  104. # Audio: Open the resulting file with Avidemux, and set video to [copy].
  105. # Select your "MyProject...WAV" in the [audio] menu. Set audio compression to mp3.
  106. # Save the file again as "MyProject-audio.mp4". It will take some minutes.
  107. # Check that the audio sync is ok, else you may repeat the last step with setting an audio delay, often 250ms.
  108. # or you may even edit the WAV with an audio editor to correct sync problems.
  109. #
  110. # *ready* - below, there is the verbose full description.
  111. # ------------------------------------------------------------------------------------
  112. #
  113. #
  114. # 1. Index and audio preparation
  115. #
  116. # 1.1. Locate your target ISO file, that contains the video DVD data.
  117. # In our example, it is named "MyProject.ISO".
  118. # Run DGIndex.exe and drag the ISO file on it.
  119. # After a second, you should see the add files window and your file, just click OK.
  120. # The video preview will show up. (Often starts with black frames).
  121. #
  122. # 1.2. Use the time slider and the <,>,[,] Buttons to move the selection pointers. This is because some videos
  123. # require you to select the valid time intervals to transcode, while other parts will return unusable data, like menus
  124. # with incompatible timing information etc. that ruin the audio sync, or contain ad segments.
  125. # With [ and ] you can set the start and end of your selection that will now be indexed.
  126. # The indexing process will create a file with the name "MyProject.d2v". Takes some minutes.
  127. # You may want to create distinct segments to merge later, e.g. an intro, a main movie, a footage/making movie, and teaser sequences.
  128. #
  129. # 1.3. Make sure that DGIndex must write a WAV audio file while indexing.
  130. # In the [Audio] menu, select Output Method = Decode AC3 to WAV. Also, select conversion [48->44.1kHz] to [high].
  131. # The WAV file is the safest in that it does not carry tricky timing information, that can disturb the transcoding or playback processes.
  132. # The resulting audio file will have a complex name like "MyProject..........44.1kHz.WAV". You later need to feed this to AviDemux.
  133. #
  134. # (If you want to transcode the DVD menus, you may have to locate their audios yourself, that may be anywhere,
  135. # and cut out the relevant parts with an audio editor.
  136. # You may even have to decompile the ISO and search for menu audio in the VOB raw files.
  137. # DGIndex cannot properly process the menu sequences of certain DVDs, audio may come out wrong.)
  138. #
  139. # 1.4. Start the indexing with the menu [File] [Save Project].
  140. # For the save file name use "MyProject.d2v" in your transcodings directory, e.g. "F:\transcodings\MyProject.d2v"
  141. # This will take a while, perhaps 15 minutes, depending on your CPU. There is a progress indicator, anyway. When complete, it says "FINISHED".
  142. #
  143. #
  144. # 2. AVS Proxy preparation
  145. #
  146. # 2.1. Edit the script file. (A copy of this one you are reading right now. It should be named "MyProject.avs")
  147. # You need to enter the actual d2v full file path below, in the MPEG2Source(..) command.
  148. #
  149. # 2.2. You can select different convolution matrices.
  150. # Remove the # sign from _one_ of the GeneralConvolution() lines to activate it.
  151. #
  152. # The best choice of matrix may depend on the impact by postprocessing filters in the original DVD production,
  153. # and perhaps even on the physical camera lense and array.
  154. # The supplied matrices thus are estimates of a deconvolutional process that can optimize sharpness of the video,
  155. # corresponding to the typical errors and artifacts, like ringing and halo,
  156. # that were caused by e.g. the post production filtering (that takes into account the behavior of typical DVD players),
  157. # and by the lenses and cam pixel arrays.
  158. # You are free to experiment with the parameters. There is a whole universe of Math about convolution, z-transformation and digital filtering.
  159. # With some experience, the operator can learn to guess how to adjust parameters for particular details, e.g. radius of halo and of ringing.
  160. # Asymmetric matrices need a border preset, as they will create a shift of the whole video area. Such border is specified in the script already.
  161. #
  162. # 2.3. (optional) You may want to experiment with different color space conversions, as a few videos will come out with tainted colors.
  163. # This must correspond with the color correction settings in Avidemux.
  164. #
  165. # 2.4. (optional) You may tune the border preset and removal, but also the Avidemux project that follows with its filtering, has its
  166. # own preprocessing-borders and removal/crop, so the final size and aspect correction has to be done there.
  167. #
  168. # 2.5. (optional) Create a single-picture gallery display with the Loop command.
  169. # Below, you will find a template for creating an intro video that shows pictures from the menus, and other pictures that the DVD might serve.
  170. # The idea is to create a loop for each picture, that shows it for half a second.
  171. # You will need to find out the starting frames in the raw video, where the pictures are.
  172. # This method should be used with an extra project segment, as it is not compatible with the DVD audio,
  173. # and you will need to hack a customized audio file, or a silent one of the correct length.
  174. #
  175. # 2.6. (optional) There is a testing-template below, to create a sequence of many convolution-settings and view them directly one after the other.
  176. # Enter starting time and duration of the video test segment, that will repeat with the different settings.
  177. #
  178. # Please note that the result can only be judged after encoding the test sequence and watching it in the player. ###
  179. # This is because also the x264 encoder is set to have deliberate influence in the final result.
  180. #
  181. #
  182. # 2.7. *** When you are ready with the avs file editing, open AVSProxy-GUI.exe. ***
  183. # Select the [Custom] tab.
  184. # Pull the MyProject.avs file into the GUI, in the frame below the Custom tab.
  185. # Click [Show Details]. You may have to deactivate the [Automatically start Avidemus] option.
  186. # You should see the message "Waiting for client to connect.."
  187. # Now we can proceed to the actual encoding suite Avidemux.
  188. #
  189. #
  190. #
  191. # 3. Setting up Avidemux and starting the actual encoding
  192. #
  193. # It is recommended to process the audio only after successful video encoding, because audio will slow down the task.
  194. #
  195. # 3.1. Start Avidemux
  196. #
  197. # 3.2. In the [File] menu, "Connect to avsproxy".
  198. # The video should show up, and Avsproxy Detail frame should show the message "Client connected".
  199. #
  200. # 3.3. In the [File] menu, open the project file "MyProject.py". You will have to copy it from the project template given below at the end.
  201. # This is done with [Tinypy Project] [Run Project] and select the .py file.
  202. #
  203. # There may be situations where you need to edit that file before opening, e.g. because Avidemux would crash.
  204. # Invalid audio can make Avidemux crash. The py file should at that stage contain no information about an audio track, but set it disabled.
  205. #
  206. # Now we have one caveat. The py does not have the correct video duration because it was just copied from a template.
  207. # At least, it should specify a duration that is higher than any DVD length expected. This will make things easier.
  208. # (But py-template copying saves us a lot of time setting up the filters plus encoder, though we can also
  209. # load and save a filtering bench, and save particular encoder settings.)
  210. #
  211. # 3.4 To get to the correct basic duration, use the rightmost of the little round blue transport buttons.
  212. # The time pointer should jump to the actual end of the video. Encoding would stop at that time stamp, anyway.
  213. # Now we must decide whether we encode the whole video, or want to select a main video with its start
  214. # and end time points (otherwise, result may come surrounded with menus and gimmicks). Better, exclude menus with DGIndex already.
  215. # Use the red [A][B] buttons to set the start and end frames, after finding the correct positions.
  216. # Audio timing expects that [A] is set to 0:00 else you have to precisely edit out the start-offset with an audio editor.
  217. # For testing, of course A can be set to any interesting starting point.
  218. #
  219. # 3.5. Check and tune the filters. (Click [Filters] button) ***
  220. # The predefined filters for this project should show up.
  221. # You can use the [Preview] only after selecting which stage you want to preview, e.g. you click the filter before "swsResize",
  222. # to see the video in its biggest upsampling dimension. Or you click the last filter, and then [Preview].
  223. # (optional) Tuning:
  224. # 3.5.1 ChromaShift.
  225. # There are two chroma shifts, horizontal and vertical, and the vertical is done with rotating the video before and after.
  226. # Check, if the color is sitting at the center of the luminance. Else there is some sort of "rainbow".
  227. # The Filter lets you shift color left or right, up or down (with the rotation-embedded shifter);
  228. # normally we set the shift to a value among (0, 1, 2, -1, -2). The preset is already valid for most videos.
  229. # There may be videos that need a different _scaling_ of the chroma shift correction, which means you seem
  230. # to get it wrong for a half pixel in any direction.
  231. # In this case, that ChromaShift filter needs to be moved around in the list of filters, e.g. to another location in the _resized_ domains,
  232. # i.e. to be placed within the 720 or the 1600 or the 960 resolution.
  233. # For the up-down shift, of course, move it together with the two rotation filters before and after.
  234. # Be aware that chroma shifting will destroy a couple of lines or rows, which needs to be addressed with the preprocessing border width.
  235. # Incorrect chroma position will increase file size and look less sharp, or become really ugly.
  236. # 3.5.2 FluxSmooth.
  237. # This is the temporal cleaner, that helps to smoothen out artifacts. Settings higher than 30 will
  238. # probably create echoes, e.g. in moving landscapes. Default is 15.
  239. # Don't use the spatial parameter, unless the video is really noisy, else it will destroy textures (of the skin, the wall, the carpet etc.)
  240. # Resulting file size will be influenced by the wise usage of this filter. Echoes will increase file size.
  241. # 3.5.3. Add Borders / Crop, means preprocessing-borders.
  242. # Adding and removing borders will depend on details in the original video size, and on the chroma shift settings.
  243. # This needs quite some nudging and checking, if you want a precise result without bordering artifacts or losing width or height.
  244. # Be aware that the resizing needs to account for the pixels of the border width also, thus only after border removal we should result in the 960x640 size.
  245. # Some videos have a width slightly smaller than 720, then we must cut off the black bars at the right and left,
  246. # and adjust resizing-width in a way that preserves the aspect ratio (i.e. people should not look thinner or fatter).
  247. # 3.5.4 swsResize
  248. # You need to disable the [Lock Aspect Ratio]. Also, opening the parameter dialog does not preserve values because of this glitch.
  249. # Memorize dimensions before opening the parameter edit.
  250. # Enter the pixel width of the dimensions. The final resizing should yield a 960x640 video,
  251. # though you may of course experiment with any target size. The 4/3 factor benefits also in adding some subtle,
  252. # nice texture that makes hair, water, etc. sparkle.
  253. # The idea is to make an upsampled video, with a certain factor that will make artifacts look smoother, and for preventing the
  254. # video player that you use to watch, from adding its own non-ideal filtering impact.
  255. # The intermediate resizing in the chain is a tuning method for the chroma shift and the sharpening filter, and further smoothens some artifacts.
  256. # Intermediate size of 1600 is a compromise between useful color shift plus tight horizontal sharpening radius, with processing speed.
  257. # 3.5.4 Contrast
  258. # You may use this setting according to your taste, or remove it. Many DVDs look a bit pale after the conversion.
  259. # This filter is meant to be used with ChromaU only, and stepping up "U" contrast for one increment, or ChromaV only, with stepping down.
  260. # The effect is making the color red more intense.
  261. # 3.5.5 Avisynth color filter. (In Avidemux here; the same function is available in avisynth, but without the user interface)
  262. # This is a subtle correction for the notorious colorspace problems. You may remove it, if the result is ok without.
  263. # [Y] is used to enhance the black-and-white contrast to the full computer screen range. Useful values go from 10 to 20.
  264. # Gamma value could be used from 0.2 to 1.5 (zero seems to switch it off), and deals with the dark parts of the picture.
  265. # Often, the video has its black parts not dark enough.
  266. # So, we can adjust the contrast for the bright parts (boost but stop it before any details disappear, that are almost white already.)
  267. # Then we can correct the dark parts with the gamma.
  268. # [U] and [V] don't allow different settings. Set both the U and V contrast around 8-12 to achieve slightly more intense colors.
  269. # You may check the video without the color filters, to see if it is similar enough to the original.
  270. # But still, this can be judged only after encoding, and is a matter of taste.
  271. # 3.5.6 Sharpen convolution
  272. # This is a built-in preset sharpener in Avidemux, that is used for its linearity and precision.
  273. # If the video turns out oversharpened, you may as a first measure remove the last instance of this filter at the bottom of the filter manager.
  274. # In the upsampled section, this sharpener is included twice. The second instance is used only for tweaking the color information.
  275. # The extra color sharpening is up to the taste and will depend on the particular original video color encoding.
  276. # The problem behind this comes from the fact that color is encoded only with half of the luminance resolution, and this will add up at re-encoding.
  277. # So we have to choose between a setting with colors bleeding out (overflowing) of some structures, or leaving a pale border around
  278. # other structures (which might look a bit sharper then but also quite artificial).
  279. # Optional choices for the pale halos are: a) remove final sharpener; b) remove extra color sharpener.
  280. #
  281. # 3.6. Check the Encoder [Video Output] [x264] [Configure]
  282. # The preset is doing a nice job, still you may want to tweak the compression parameter. Default is 22 for high quality.
  283. # For ***** 4:3 ***** videos, the Output section tab needs to be adjusted to NTSC 4:3. (PAL was never tested with this project.)
  284. #
  285. # 3.7. [File][Save] - Save the MyProject.mp4 file and wait some hours for its completion.
  286. #
  287. # 3.8. How to add the audio.
  288. # Open the "MyProject.mp4" with Avidemux once again. For this, start another empty instance of Avidemux.
  289. # Set [Video Output] to [copy].
  290. # In the Audio menu, select the WAV file made by DGIndex as an audio track.
  291. # Set [Audio Output] to mp3 compression. Set audio delay to 220ms as a trial. You may have to repeat the process until you found the correct delay.
  292. # Set [Output Format] to mp4.
  293. # Save the video as "Myproject-audio.mp4".
  294. #
  295. # ------------------- ready -------------------
  296.  
  297.  
  298.  
  299.  
  300. # ------------------------------------------------------------------------------
  301. # Technical remarks
  302. # ------------------------------------------------------------------------------
  303. # The benefit in the packaged process concept lies in the synergy of all the filtering steps, together with the behavior of the x264 encoder.
  304. # One particular trick is the upsampling. It is done by resizing the 720x480px to 1600x960,
  305. # and then to a final 960x640 (add border values here also, then crop for remaining borders, down to the target size).
  306. # Upsampling allows to apply filters with a higher quality in the higher resolution domain,
  307. # it will deliberately influence the built-in sharpening filters of Avidemux,
  308. # also the bandwith-filtering of the resizers will make the pixels "rounder" and mitigate interlacing artifacts,
  309. # and the particular choice of a 4/3 from original size
  310. # will also create a minimal texture in the video, that looks nice in the eye, and adds up to beautify the deinterlacing.
  311. # There is an optional color shift correction, and while the available filter can only shift the color information for
  312. # the length of a whole pixel, then when we do this in the upsampled domain, we end up with fractional pixel shifts in
  313. # the color, and this is exactly what is required, due to the color coding methods in the MPEG2 formats, when we convert that to h264.
  314. # One of the most important features of the 960x640 format is that the video players will influence quality no more,
  315. # as player filterings are set to the 960 density for that matter, but there is no data beyond the 720 density, to be touched by this.
  316. # The encoder will optimize this situation quite well, und use only slightly higher bitrates than with encoding at 720px directly.
  317. # The convolution can make the video almost pixel-sharp (judged in the 720 domain), given that the original has detailed data in that range at all.
  318. # Other "diagonal" matrix parameters have been added to further soften the interlacing artifacts. You may further experiment with this.
  319. # One quite smart feature is that the convolutional sharpening, the temporal smoothener, and the motion detection in the encoder,
  320. # all work together very well.
  321. # The encoder will recognize structures in the moving blocks, and use a softening algorithm that slows down the changes from one block to the next.
  322. # The worst unwanted changes among any two adjacent frames will come from the deinterlacer's "bobbing" function,
  323. # and they will be softened, especially when the camera moves.
  324. # Another change comes from the natural math-rounding errors around pixel size. They would kind of flicker.
  325. # The convolution takes into account not just one pixel but a surrounding area, that holds still information about the pixel,
  326. # from the blurring halo.
  327. # As a result, the encoder will recognize easier those moving structures and blocks among a sequence of frames, and therefor,
  328. # small scale structures in the picture will be recognized and improved by using and averaging all data that
  329. # describes that structure over a number of frames.
  330. # In short, little structures close to pixel size will be translated more precisely, and look sharper and at the same time smoother.
  331. # Further, the encoder preset has turned off certain optimizations so to preserve all texture.
  332. # OTOH, another setting has been changed to allow some minimal distortion in moves, to save an amount of file size.
  333. # The video will look often more calm and natural than the original DVD, in the computer's DVD player. Some hardware standalone players may still perform better.
  334.  
  335.  
  336.  
  337.  
  338.  
  339. # ---------------------------------------------------------------
  340. # AVISYNTH SCRIPT TO BE RUN BY AVSPROXY starts here:
  341. # ---------------------------------------------------------------
  342.  
  343. #--- optionally to load old MPEG2:
  344. # LoadPlugin("C:\programs\AviSynth+\plugins+\mpeg2dec3.dll")
  345. # see the help files if you need this.
  346.  
  347. # --- load command for the indexed video:
  348. # Caveat - MyProject.d2v will point also to the original MyProject.ISO,
  349. # that you cannot remove from its directory until the project has finished.
  350. LoadPlugin("F:\programs\AviSynth+\dgdecode.dll")
  351. MPEG2Source ("F:\transcodings\MyProject.d2v",cpu=0,info=2) # ****************************************************** edit input file here
  352.  
  353. # (usage)
  354. # MPEG2Source (string d2v, int "idct", int "cpu", bool "iPP", int "moderate_h", int "moderate_v", string "cpu2", int "upConv", bool "iCC",
  355. # bool "i420", int "info", bool "showQ", bool "fastMC")
  356. # cpu=0..7 - post processing
  357. # iPP=false - force progressive postprocessing
  358. # cpu2="ooooxx" deringing only (LH LV CH CV LR CR)
  359. # upConv= 0=no upsample, 1=YUY2/4:2:2, 2=RGB24
  360. # iCC=false - force progressive upsample
  361. # info=1 add debug to video, 2=debug to textchannel
  362.  
  363.  
  364.  
  365.  
  366. #-- Deinterlace Yadif
  367. Load_Stdcall_plugin("F:\programs\AviSynth+\plugins\yadif.dll")
  368. Yadif(mode=1)
  369. # check whether the DVD is interlaced at all, else hide above lines with the # comment sign.
  370.  
  371. /*
  372. # Loop some Frames -- if there is a picture gallery
  373. tx = 69.234 # enter in seconds, position of first frame of picture gallery
  374. f = 59.9 # frame rate after deinterlacing!
  375. n = int(tx * f) + 3 # you may simply correct this offset (default = +3), if it does not hit
  376. n1 = 30 # enter here: how many double-frames to create per picture
  377. # if still more pics, add to the looping from top, in reverse! order
  378. Loop(n1,n+32,n+33)
  379. Loop(n1,n+30,n+31)
  380. Loop(n1,n+28,n+29)
  381. Loop(n1,n+26,n+27)
  382. Loop(n1,n+24,n+25)
  383. Loop(n1,n+22,n+23)
  384. Loop(n1,n+20,n+21)
  385. Loop(n1,n+18,n+19)
  386. Loop(n1,n+16,n+17)
  387. Loop(n1,n+14,n+15)
  388. Loop(n1,n+12,n+13)
  389. Loop(n1,n+10,n+11)
  390. Loop(n1,n+8,n+9)
  391. Loop(n1,n+6,n+7)
  392. Loop(30,n+4,n+5)
  393. Loop(n1,n+2,n+3)
  394. Loop(n1,n,n+1)
  395. */
  396.  
  397.  
  398. # ----------------------------- the asymmetric convolution needs a run-in border to compensate for the pixel shift:
  399. AddBorders(4,0,2,4,$AAAAAA)
  400. #AddBorders(clip clip, int left, int top, int right, int bottom [, int color])
  401. # - the border is grey, and for best results, its brightness should be adapted to the average brightness of the video.
  402. # switch this off for symmetric matrix, then also the crop() at the end.
  403.  
  404.  
  405. # ----------------------------- the data format for convolution has to be RGB:
  406. #ConvertToRGB(clip [, string matrix] [, bool interlaced] [, string ChromaInPlacement] [, string chromaresample])
  407. ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
  408.  
  409. # -- default for this preset package: PC.709 = HDTV full range
  410. # Rec.709 should be used when your source is DVD or HDTV
  411. # -- alternative DVD color space:
  412. # "Rec601" : Use 601 coefficients, scaled to TV range [16,235].
  413. # "PC.601" : Use 601 coefficients, keep full range [0,255].
  414. # chromaresample= ("point", "bilinear", "bicubic", "lanczos", "lanczos4", "blackman", "spline16", "spline36", "spline64", "gauss" and "sinc")
  415. # default is "bicubic".
  416.  
  417.  
  418.  
  419.  
  420. # ------------------------------ These are the customized convolutional matrices, collected from projects:
  421. # try those marked with *** first!
  422. #
  423. # --- symmetric matrices:
  424. # increase the central value to make the filter softer
  425.  
  426. #GeneralConvolution(0, "-2 0 3 0 -2 0 -1 -3 -1 0 2 -6 56 -6 2 0 -1 -3 -1 0 -1 0 3 0 -1") # C2 crystal clear entry level
  427. #GeneralConvolution(0, "-1 0 3 0 -1 0 -1 -3 -1 0 3 -5 56 -5 3 0 -1 -3 -1 0 -1 0 3 0 -1") # Crystal Outline used on a 4:3 video *** ***
  428. # needs good source and is very crispy
  429. #GeneralConvolution(0, "-2 0 7 0 -2 0 -2 -6 -2 0 6 -10 112 -10 6 0 -2 -6 -2 0 -2 0 8 0 -2") # Crystal Outline B, softer
  430. #GeneralConvolution(0, "-2 0 7 0 -2 0 -2 -6 -2 0 5 -8 112 -8 5 0 -2 -6 -2 0 -2 0 6 0 -2") # Crystal Outline C, softer
  431. #GeneralConvolution(0, "-1 0 3 0 -1 0 -1 -3 -1 0 3 -5 48 -5 3 0 -1 -3 -1 0 -1 0 3 0 -1") # if it is blurred more
  432. #GeneralConvolution(0, "-1 0 3 0 -1 0 -1 -3 -1 0 3 -6 48 -6 3 0 -1 -3 -1 0 -1 0 3 0 -1") # was used for a blurred noninterlaced video
  433. #GeneralConvolution(0, "0 0 3 0 -0 0 -1 -3 -1 0 4 -4 44 -4 4 0 -1 -3 -1 0 0 0 3 0 0") # C3 level crystal clear, different halo *** ***
  434.  
  435. #GeneralConvolution(0, "-3 0 4 0 -3 0 -1 -3 -1 0 12 -12 56 -12 12 0 -1 -3 -1 0 -3 0 4 0 -3") #test 11
  436. #GeneralConvolution(0, "-2 0 3 0 -2 0 -1 -3 -1 0 11 -12 56 -12 11 0 -1 -3 -1 0 -1 0 3 0 -1") #test 12
  437.  
  438. # ----------------------------------------------------------------
  439. # --- asymmetric matrices (finer compensation of ringing):
  440. # increase the 5th value to make the filter softer, 4th (<0) for horizontal sharpness,
  441. # nudge the first two values for "ringing" that has a 3-4 px distance from the original edge
  442. # good choice helps the encoder a lot, to preserve detail while not inflating file size
  443.  
  444. GeneralConvolution(0, "2 -5 12 -20 112 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0") # crystal clear with good compensation ***
  445. #GeneralConvolution(0, "3 -4 8 -10 112 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0") # crystal soft for non-interlaced DVD
  446. # - this is for newer videos that have very fine detail and lot of sharpener was used in the production *** *** ***
  447. #GeneralConvolution(0, "3 -3 9 -13 112 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0") # crystal non-interlaced; sharper
  448.  
  449.  
  450. #GeneralConvolution(0, "2 -6 15 -20 96 0 0 -0 -4 -12 0 0 -6 -0 15 0 0 0 0 -4 0 0 0 0 0") # X8 *** *** ***
  451. # - this one turns out quite generic and is very good for many blurred videos!
  452. #GeneralConvolution(0, "5 -13 15 -20 120 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0") # a3
  453. # - recommended for videos with less of detail resolution
  454.  
  455. #GeneralConvolution(0, "5 -13 17 -21 100 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0") # a2
  456. #GeneralConvolution(0, "2 -6 13 -16 96 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0") # a1
  457.  
  458. #GeneralConvolution(0, "2 -7 11 -12 28 0 0 0 2 -3 0 0 -1 0 3 0 0 0 0 -1 0 0 0 0 0") # C1 asymmetric
  459.  
  460. #GeneralConvolution(0, "1 -2 4 -5 24 0 0 -0 -2 -3 0 0 -2 -0 3 0 0 0 0 -1 0 0 0 0 0") # X5
  461. #GeneralConvolution(0, "2 -4 12 -20 96 0 0 -0 -8 -12 0 0 -8 -0 12 0 0 0 0 -4 0 0 0 0 0") # X6
  462. #GeneralConvolution(0, "2 -5 15 -20 96 0 0 -0 -6 -12 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0") # X7 - very sharp with compensation ***
  463. # - differs from X8 mainly in the treatment of the deinterlacing artifacts
  464.  
  465.  
  466.  
  467. #-------------- convolution tuning test bed -------------
  468. # use this template to insert a number of test matrices,
  469. # and repeat the same short video segment multiple times, with changing the matrix and printing the specimen number/tag on it.
  470. #---test start time = minutes*60 + ss.ddd #(seconds)
  471. tpos=0*60+56 # start time
  472. rff=29.97*2 # frame rate
  473. fpos=int(tpos*rff)
  474. #--test slice length:
  475. tsl=int(40*rff)
  476.  
  477. #Trim(fpos, -tsl) + blankclip(last,15) \
  478. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -5 12 -20 112 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("cc") + blankclip(last,15)\
  479. # + Trim(fpos, -tsl).GeneralConvolution(0, "3 -4 8 -10 112 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0").subtitle("cn") + blankclip(last,15)\
  480.  
  481. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -6 15 -20 96 0 0 -0 -4 -12 0 0 -6 -0 15 0 0 0 0 -4 0 0 0 0 0").subtitle("x8") + blankclip(last,15)\
  482. # + Trim(fpos, -tsl).GeneralConvolution(0, "5 -13 15 -20 120 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("a3") + blankclip(last,15)\
  483. # + Trim(fpos, -tsl).GeneralConvolution(0, "5 -13 17 -21 100 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("a2") + blankclip(last,15)\
  484. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -4 12 -20 128 0 0 -0 -8 -12 0 0 -8 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("3") + blankclip(last,15)\
  485. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -4 12 -20 148 0 0 -0 -8 -12 0 0 -8 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("4") + blankclip(last,15)\
  486. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -5 14 -20 96 0 0 -0 -6 -12 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("5") + blankclip(last,15)\
  487. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -5 10 -20 96 0 0 -0 -6 -12 0 0 -4 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("6") + blankclip(last,15)\
  488. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -5 15 -20 96 0 0 -0 -6 -12 0 0 -6 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("7") + blankclip(last,15)\
  489. # + Trim(fpos, -tsl).GeneralConvolution(0, "2 -5 16 -20 96 0 0 -0 -6 -12 0 0 -4 -0 12 0 0 0 0 -4 0 0 0 0 0").subtitle("8") + blankclip(last,15)
  490.  
  491.  
  492.  
  493.  
  494.  
  495. # -- remove the border (if AddBorders() was used)
  496. #Crop(clip clip, int left, int top, int -right, int -bottom, bool align)
  497. Crop(0,2,-2,-2)
  498.  
  499.  
  500. # -- back to standard format for avsproxy:
  501. ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
  502.  
  503. #---------------------------------------------------------------------------------------------------------------------
  504. # we are done with the script here.
  505. #---------------------------------------------------------------------------------------------------------------------
  506. #---------------------------------------------------------------------------------------------------------------------
  507. #---------------------------------------------------------------------------------------------------------------------
  508.  
  509.  
  510.  
  511.  
  512. # ------------------------------------------------------------------------------
  513. # Project template for *Avidemux*
  514. # ------------------------------------------------------------------------------
  515. # Copy away this section starting with "#PY" into another file, and name it "MyProject.py"
  516. #
  517. # Don't copy the start and end comment markers below, /* and */
  518. # This file is hidden from avisynth with the comment markers.
  519. # After creating the py file, you may remove this whole section from this avs file.
  520. #
  521. # Use the MyProject.py with Avidemux to load the whole package of settings at once.
  522. # Open it with "Run Project" from the Tinypy menu, but only after you have already connected to Avisynth.
  523. # After setting-up and tweaking for your particular video is complete, save the py project as <name of the video>.py
  524. #
  525. # Tweaks:
  526. # Check start and end markers (A,B) of the video. Default audio procedure works only with A = 0:00.
  527. # Check for the color shifts, both vertical and horizontal. Sometimes shifts may be obsolete, sometimes needs more.
  528. # You can move around the color shift between the resizing operations, to tune that on subpixel level.
  529. # Leave out the final sharpener, if result looks oversharpened.
  530. # Switch off the color contrast filter if skin looks too brown, or even reverse its direction.
  531. # Nudge gamma and contrast when black or white areas are pale or overloading.
  532. #
  533.  
  534. /*
  535.  
  536. #PY <- Needed to identify #
  537. #--automatically built--
  538.  
  539. adm = Avidemux()
  540. adm.loadVideo("::ADM_AVS_PROXY::")
  541. adm.clearSegments()
  542. adm.addSegment(0, 0, 10000000000)
  543. adm.markerA = 0
  544. adm.markerB = 0
  545. adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=22", "general.threads=0", "general.preset=ultrafast", "general.tuning=film"
  546. , "general.profile=baseline", "general.fast_decode=False", "general.zero_latency=False"
  547. , "general.fast_first_pass=True", "level=-1", "vui.sar_height=27", "vui.sar_width=32", "MaxRefFrames=5", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
  548. , "intra_refresh=False", "MaxBFrame=5", "i_bframe_adaptive=2"
  549. , "i_bframe_bias=0", "i_bframe_pyramid=2", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=-1", "i_deblocking_filter_beta=0", "cabac=True", "interlaced=False"
  550. , "constrained_intra=False", "tff=True"
  551. , "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=False", "analyze.b_p16x16=True", "analyze.b_b16x16=True"
  552. , "analyze.weighted_pred=2", "analyze.weighted_bipred=True"
  553. , "analyze.direct_mv_pred=3", "analyze.chroma_offset=1", "analyze.me_method=2", "analyze.me_range=17", "analyze.mv_range=-1", "analyze.mv_range_thread=-1"
  554. , "analyze.subpel_refine=9", "analyze.chroma_me=True"
  555. , "analyze.mixed_references=True", "analyze.trellis=2", "analyze.psy_rd=1.100000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True", "analyze.dct_decimate=True"
  556. , "analyze.noise_reduction=0", "analyze.psy=True"
  557. , "analyze.intra_luma=0", "analyze.inter_luma=0", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=4", "ratecontrol.qp_max=58"
  558. , "ratecontrol.qp_step=8", "ratecontrol.bitrate=0"
  559. , "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=0"
  560. , "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.400000"
  561. , "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.400000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
  562. adm.addVideoFilter("fluxsmooth", "temporal_threshold=15", "spatial_threshold=0")
  563. adm.addVideoFilter("addBorder", "left=0", "right=2", "top=2", "bottom=2")
  564. adm.addVideoFilter("swscale", "width=1600", "height=968", "algo=2", "sourceAR=2", "targetAR=2")
  565. adm.addVideoFilter("chromashift", "u=-1", "v=-1")
  566. adm.addVideoFilter("Sharpen", "luma=True", "chroma=True")
  567. adm.addVideoFilter("contrast", "coef=0.900000", "offset=40", "doLuma=False", "doChromaU=False", "doChromaV=True")
  568. adm.addVideoFilter("colorYuv", "y_gain=0.000000", "y_bright=0.000000", "y_gamma=1.900000", "y_contrast=15.000000", "u_gain=0.000000"
  569. , "u_bright=0.000000", "u_gamma=0.000000", "u_contrast=12.000000", "v_gain=0.000000", "v_bright=0.000000"
  570. , "v_gamma=0.000000", "v_contrast=0.000000", "matrix=0", "levels=0", "opt=False", "colorbars=0", "analyze=1", "autowhite=False", "autogain=False")
  571. adm.addVideoFilter("rotate", "angle=90")
  572. adm.addVideoFilter("chromashift", "u=-1", "v=-1")
  573. adm.addVideoFilter("rotate", "angle=270")
  574. adm.addVideoFilter("Sharpen", "luma=False", "chroma=True")
  575. adm.addVideoFilter("swscale", "width=968", "height=646", "algo=2", "sourceAR=1", "targetAR=1")
  576. adm.addVideoFilter("crop", "top=4", "bottom=2", "left=4", "right=8")
  577. adm.addVideoFilter("Sharpen", "luma=True", "chroma=True")
  578. adm.audioClearTracks()
  579. adm.audioCodec(0, "Lame", "bitrate=128", "preset=0", "quality=1", "disableBitReservoir=False");
  580. adm.audioSetDrc(0, 0)
  581. adm.audioSetShift(0, 0,0)
  582. adm.setContainer("MP4V2", "optimize=0", "add_itunes_metadata=1")
  583.  
  584.  
  585.  
  586. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement