Advertisement
Duker

SSA's (small size anime) article on their x265 encoding settings

Oct 30th, 2021
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. Copied 2021-10-30 from https://www.ssanime.ga/ for the purpose of archival if the website goes down
  2. If the site is still up I recommend you read it there instead
  3. ---------------------
  4.  
  5. How to encode anime episodes to the smallest size, best quality, faster thank? Truth Is Nearer Than You Know
  6. One of the main concerns here is that X265 drinks up a lot of your CPU in exchange for giving a very good clear video file.
  7.  
  8. I have done a lot, and when I say a lot, literally months (4 months = ~120 days) of comparison with different types of x265 and x264 settings.
  9.  
  10. And at the end what software do I use to encode episodes? FFMPEG
  11.  
  12. Yup, it's as simple as that. Though older versions won't work out, the recent one's have latest x265 features after all. Just download it from google.
  13.  
  14.  
  15.  
  16. Look, I'm not going to waste your time to read all the stuff I want to say and I'll just give you the settings.
  17.  
  18. Here is the settings that I wrote on my python script:
  19.  
  20. { 'c:a': 'aac', 'c:v': 'libx265', 'b:a': '192k', 'profile:v': 'main', 'x265-params': ':'.join([ 'me=2', 'rd=4', 'subme=7', 'aq-mode=3', f'aq-strength=1', f'deblock=1,1', f'psy-rd=1', f'psy-rdoq=1', 'rdoq-level=2', 'merange=57', 'bframes=8', 'b-adapt=2', 'limit-sao=1', 'frame-threads=3', 'no-info=1', ]), 'crf': 24.2, 'preset': 'slow', 'pix_fmt': 'yuv420p', 'vf': ','.join([ 'smartblur=1.5:-0.35:-3.5:0.65:0.25:2.0', 'scale=1920:1080:spline16+accurate_rnd+full_chroma_int' ]), 'metadata': 'Encoder Settings=Redacted, CPU - 2xAMD EPYC 7282 32 cores/64 threads, GPU - None used', 'color_range': 1, 'color_primaries': 1, 'colorspace': 1, 'color_trc': 1, }
  21.  
  22.  
  23. And converting it into command line arguments:
  24. ffmpeg -i input.mkv -map 0:v -map 0:a -b:a 192k -c:a aac -c:v libx265 -color_primaries 1 -color_range 1 -color_trc 1 -colorspace 1 -crf 24.2 -map 0:s? -pix_fmt yuv420p -preset slow -profile:v main -vf smartblur=1.5:-0.35:-3.5:0.65:0.25:2.0,scale=1920:1080:spline16+accurate_rnd+full_chroma_int -x265-params me=2:rd=4:subme=7:aq-mode=3:aq-strength=1:deblock=1,1:psy-rd=1:psy-rdoq=1:rdoq-level=2:merange=57:bframes=8:b-adapt=2:limit-sao=1:frame-threads=3:no-info=1 output.mp4 -y
  25.  
  26.  
  27.  
  28. Now if you have spare time to read my rantings about what I found when I was researching.
  29.  
  30. First of all you see that frame-threads over there? If you are running only one instance of ffmpeg command on your pc then no need of that. But yea having frame-threads to 3 gives you extra space threads/cores to encode more episodes parallelly (if you have equal or more than 16 total threads and on linux) if you have enough free threads/cores available. With the CPU I was using 2 x AMD EPYC 7282, 32 cores 2.8GHz 64 threads (I swear it was $260 when I bought it, during Covid rate changes in a blink of an eye) most of the time 90% of CPU was taken by FFMPEG when it was encoding 5 episodes at the same time. Others were for NGINX and Webserver.
  31.  
  32.  
  33.  
  34.  
  35. You probably didn't notice it
  36. But every average ~25 minute episode was taking almost 20 minutes to 1+ hours to encode depending on how many episodes were encoded in parallel. As I was hard following SubsPlease release, you can see the time difference.
  37.  
  38. Mine:
  39. https://lh3.googleusercontent.com/-JRC3delHI8g/YTiX-13d7HI/AAAAAAAAAPE/VKrwp9pFny0nSP1yqbn_3A_AzJ8fkO5wgCLcBGAsYHQ/image.png
  40.  
  41. SubsPlease:
  42. https://lh3.googleusercontent.com/-6bDQL57ahGY/YTiYRCLXDUI/AAAAAAAAAPM/x4wOGse-UdAF0CcAMuxekyGMzITlvFBFwCLcBGAsYHQ/image.png
  43.  
  44.  
  45.  
  46. Also please remember not to convert 480p or 720p of theirs into x265, instead use the 1080p and downscale it as needed for best results. Upscaling is not at all recommended in case you have only 720p source but yet want 1080p. But in case you do want to, spline16 is not recommended. You'll have to google it.
  47.  
  48. About the parameters inside x265-params, you can study it here:
  49. https://x265.readthedocs.io/en/3.4/cli.html
  50. Although that docs is for x265 cli and not for ffmpeg directly, those parameters are what is converted into ffmpeg x265-params. So instead of giving --param you give it under x265-params separating each by a colon(:). Do remember that not all parameters in that cli documentation are applicable for ffmpeg.
  51.  
  52. To make the encoding faster:
  53. You can reduce merange=57 to something lesser like merange=32 or even lesser merange=16 and not any lesser than 16. Then why use 57? I have seen that on an overall comparison, there are some loss in line sharpness when merange is decreased. Most of the anime's it's fine to have 32 but I was aiming for all possible anime's. Also file size is slightly bigger (about ~1MB to 6MB) the lesser the merange is.
  54. Remember that merange max value is 57 and also default value defined by encoder even without mention.
  55.  
  56. Hiding Information about encoding parameters:
  57. no-info=1 hides the encoding parameters when writing the output file. Just remove it if you don't intend to hide it.
  58. What about the other parameters inside x265-params?
  59. Go through this: https://kokomins.wordpress.com/2019/10/10/anime-encoding-guide-for-x265-and-why-to-never-use-flac/
  60.  
  61. Video Parameters:
  62. libx265 obviously. Since NVENC encoder is not even an option to consider as it worsens quality.
  63. Do not control the bitrate. Anime episodes should have variable bitrates, putting any kinds of limits will kill the colors in some awesome scenes, like I messed up SAO Alicization when I was encoding it on my local PC. It will also put banding on video.
  64. slow is the best possible value for preset.
  65. 24.2 is the overall best value for CRF. I have sometimes used 23 or 22 if the file size was too small and not of good quality. 25 or 25.4 if the file size was going too large. Higher than 25.4 is not recommended as it worsens the quality of the video at places you can't imagine.
  66. main gave the best results for profile of video, I don't remember about other profiles.
  67. yuv420p standard pixel format for any anime video.
  68. Color Parameters:
  69. color_range, color_primaries, colorspace, color_trc was something I started using on a whim when I found out about it on an old anime forum, didn't see any significant differences but definitely felt like color loss after encoding was lesser when using it rather than when not using it.
  70. Remove metadata, it's unrelated if you have any.
  71. vf
  72. scale parameter is used for scaling (1080p,720p,480p)
  73. 480p: scale=848:480:spline16+accurate_rnd+full_chroma_int
  74. 720p: scale=1280:720:spline16+accurate_rnd+full_chroma_int
  75. 1080p: scale=1920:1080:spline16+accurate_rnd+full_chroma_int
  76. smartblur I found this value on a forum: https://forum.videohelp.com/threads/389480-Need-help-with-FFMpeg-and-detail-enhancement-sharpening#post2523233
  77. Audio parameters:
  78. So I'm using AAC - 192k bitrate for 1080p, 128k or 160k for 720p and 96k for 480p.
  79.  
  80. Very much recommended to use FDK_AAC rather than plain AAC. If you are on Windows, you can install personal use (non commercial) free version of FDK_AAC from here:
  81. https://github.com/m-ab-s/media-autobuild_suite
  82.  
  83.  
  84. If you are going to use AAC and want the best results, remember to follow the below bitrates
  85. Best Quality Lossless (recommended) - greater or equal to 192k
  86. Better Quality - greater or equal to 160k and less than 192k
  87. Above Average Quality - greater or equal to 128k and less than 160k
  88. Average Quality - greater or equal to 112k and less than 128k
  89. Low Quality (Small File Size) - greater or equal to 96k and less than 112k
  90. Lowest Quality (Smaller File Size) - greater or equal to 64k and less than 96k
  91. Worst Quality (File Size Negligible) - lesser or equal to 64k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement