Vp9Profiles.vala 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. namespace Publicate.Video {
  2. public static Invercargill.Enumerable<EncodingProfile> construct_vp9_profiles() {
  3. return Invercargill.ate(new EncodingProfile[] {
  4. new Vp9Video1080pHighFramerateProfile (),
  5. new Vp9Video1080pLowFramerateProfile (),
  6. new Vp9Video720pProfile(),
  7. new Vp9Video480pProfile(),
  8. });
  9. }
  10. public class Vp9Video1080pHighFramerateProfile : EncodingProfile {
  11. public override string[] get_first_pass_command (string input_path, string output_path) {
  12. return get_command (input_path, output_path, 1);
  13. }
  14. public override string[] get_second_pass_command (string input_path, string output_path) {
  15. return get_command (input_path, output_path, 2);
  16. }
  17. public override string output_name () {
  18. return @"1080p_$(get_clean_fps(fps))fps.webm";
  19. }
  20. public override string version_label (){
  21. return @"1080p $(get_clean_fps(fps))fps";
  22. }
  23. public override bool suitable_for (VideoInfo info) {
  24. return info.height >= 1080 && get_low_framerate (info.frame_rate) != info.frame_rate;
  25. }
  26. public override void setup_for (VideoInfo info) {
  27. codec_names = "vp9, opus";
  28. var width = (int) (info.ratio_frac * 1080);
  29. size = @"$(width)x1080";
  30. fps = info.frame_rate;
  31. }
  32. private string[] get_command(string input_path, string output_path, int pass) {
  33. return new string[] {
  34. "ffmpeg",
  35. "-i", input_path,
  36. "-r", fps.to_string(),
  37. "-vf", @"scale=$(size)",
  38. "-b:v", "3000k",
  39. "-minrate", "1500k",
  40. "-maxrate", "2610k",
  41. "-tile-columns", "2",
  42. "-g", "240",
  43. "-threads", get_num_processors().to_string(),
  44. "-quality", "good",
  45. "-crf", "31",
  46. "-c:v", "libvpx-vp9",
  47. "-c:a", "libopus",
  48. "-pass", pass.to_string(),
  49. "-speed", "4",
  50. "-passlogfile", @"$(output_path).logfile",
  51. "-y",
  52. output_path
  53. };
  54. }
  55. private string get_clean_fps(double fps) {
  56. var clean = (int)fps;
  57. if(fps - (double)clean > 0.0) {
  58. clean++;
  59. }
  60. return clean.to_string ();
  61. }
  62. }
  63. public class Vp9Video1080pLowFramerateProfile : EncodingProfile {
  64. public override string[] get_first_pass_command (string input_path, string output_path) {
  65. return get_command (input_path, output_path, 1);
  66. }
  67. public override string[] get_second_pass_command (string input_path, string output_path) {
  68. return get_command (input_path, output_path, 2);
  69. }
  70. public override string output_name () {
  71. return @"1080p.webm";
  72. }
  73. public override string version_label (){
  74. return @"1080p";
  75. }
  76. public override bool suitable_for (VideoInfo info) {
  77. return info.height >= 1080;
  78. }
  79. public override void setup_for (VideoInfo info) {
  80. codec_names = "vp9, opus";
  81. var width = (int) (info.ratio_frac * 1080);
  82. size = @"$(width)x1080";
  83. fps = get_low_framerate (info.frame_rate);
  84. }
  85. private string[] get_command(string input_path, string output_path, int pass) {
  86. return new string[] {
  87. "ffmpeg",
  88. "-i", input_path,
  89. "-r", fps.to_string (),
  90. "-vf", @"scale=$(size)",
  91. "-b:v", "1800k",
  92. "-minrate", "900k",
  93. "-maxrate", "2610k",
  94. "-tile-columns", "2",
  95. "-g", "240",
  96. "-threads", get_num_processors().to_string(),
  97. "-quality", "good",
  98. "-crf", "31",
  99. "-c:v", "libvpx-vp9",
  100. "-c:a", "libopus",
  101. "-pass", pass.to_string(),
  102. "-speed", "4",
  103. "-passlogfile", @"$(output_path).logfile",
  104. "-y",
  105. output_path
  106. };
  107. }
  108. }
  109. public class Vp9Video720pProfile : EncodingProfile {
  110. public override string[] get_first_pass_command (string input_path, string output_path) {
  111. return get_command (input_path, output_path, 1);
  112. }
  113. public override string[] get_second_pass_command (string input_path, string output_path) {
  114. return get_command (input_path, output_path, 2);
  115. }
  116. public override string output_name () {
  117. return @"720p.webm";
  118. }
  119. public override string version_label (){
  120. return @"720p";
  121. }
  122. public override bool suitable_for (VideoInfo info) {
  123. return info.height >= 720;
  124. }
  125. public override void setup_for (VideoInfo info) {
  126. codec_names = "vp9, opus";
  127. var width = (int) (info.ratio_frac * 720);
  128. size = @"$(width)x720";
  129. fps = get_low_framerate (info.frame_rate);
  130. }
  131. private string[] get_command(string input_path, string output_path, int pass) {
  132. return new string[] {
  133. "ffmpeg",
  134. "-i", input_path,
  135. "-r", fps.to_string(),
  136. "-vf", @"scale=$(size)",
  137. "-b:v", "1024k",
  138. "-minrate", "512k",
  139. "-maxrate", "1485k",
  140. "-tile-columns", "2",
  141. "-g", "240",
  142. "-threads", get_num_processors().to_string(),
  143. "-quality", "good",
  144. "-crf", "32",
  145. "-c:v", "libvpx-vp9",
  146. "-c:a", "libopus",
  147. "-pass", pass.to_string(),
  148. "-speed", "4",
  149. "-passlogfile", @"$(output_path).logfile",
  150. "-y",
  151. output_path
  152. };
  153. }
  154. }
  155. public class Vp9Video480pProfile : EncodingProfile {
  156. public override string[] get_first_pass_command (string input_path, string output_path) {
  157. return get_command (input_path, output_path, 1);
  158. }
  159. public override string[] get_second_pass_command (string input_path, string output_path) {
  160. return get_command (input_path, output_path, 2);
  161. }
  162. public override string output_name () {
  163. return @"480p.webm";
  164. }
  165. public override string version_label (){
  166. return @"480p";
  167. }
  168. public override bool suitable_for (VideoInfo info) {
  169. return info.height >= 480;
  170. }
  171. public override void setup_for (VideoInfo info) {
  172. codec_names = "vp9, opus";
  173. var width = (int) (info.ratio_frac * 480);
  174. size = @"$(width)x480";
  175. fps = get_low_framerate (info.frame_rate);
  176. }
  177. private string[] get_command(string input_path, string output_path, int pass) {
  178. return new string[] {
  179. "ffmpeg",
  180. "-i", input_path,
  181. "-r", fps.to_string(),
  182. "-vf", @"scale=$(size)",
  183. "-b:v", "750k",
  184. "-minrate", "375k",
  185. "-maxrate", "1088k",
  186. "-tile-columns", "2",
  187. "-g", "240",
  188. "-threads", get_num_processors().to_string(),
  189. "-quality", "good",
  190. "-crf", "33",
  191. "-c:v", "libvpx-vp9",
  192. "-c:a", "libopus",
  193. "-pass", pass.to_string(),
  194. "-speed", "4",
  195. "-passlogfile", @"$(output_path).logfile",
  196. "-y",
  197. output_path
  198. };
  199. }
  200. }
  201. }