123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- namespace Publicate.Video {
- public static Invercargill.Enumerable<EncodingProfile> construct_vp9_profiles() {
- return Invercargill.ate(new EncodingProfile[] {
- new Vp9Video1080pHighFramerateProfile (),
- new Vp9Video1080pLowFramerateProfile (),
- new Vp9Video720pProfile(),
- new Vp9Video480pProfile(),
- });
- }
- public class Vp9Video1080pHighFramerateProfile : EncodingProfile {
-
- public override string[] get_first_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 1);
- }
- public override string[] get_second_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 2);
- }
- public override string output_name () {
- return @"1080p_$(get_clean_fps(fps))fps.webm";
- }
- public override string version_label (){
- return @"1080p $(get_clean_fps(fps))fps";
- }
- public override bool suitable_for (VideoInfo info) {
- return info.height >= 1080 && get_low_framerate (info.frame_rate) != info.frame_rate;
- }
- public override void setup_for (VideoInfo info) {
- codec_names = "vp9, opus";
- var width = (int) (info.ratio_frac * 1080);
- size = @"$(width)x1080";
- fps = info.frame_rate;
- }
- private string[] get_command(string input_path, string output_path, int pass) {
- return new string[] {
- "ffmpeg",
- "-i", input_path,
- "-r", fps.to_string(),
- "-vf", @"scale=$(size)",
- "-b:v", "3000k",
- "-minrate", "1500k",
- "-maxrate", "2610k",
- "-tile-columns", "2",
- "-g", "240",
- "-threads", get_num_processors().to_string(),
- "-quality", "good",
- "-crf", "31",
- "-c:v", "libvpx-vp9",
- "-c:a", "libopus",
- "-pass", pass.to_string(),
- "-speed", "4",
- "-passlogfile", @"$(output_path).logfile",
- "-y",
- output_path
- };
- }
- private string get_clean_fps(double fps) {
- var clean = (int)fps;
- if(fps - (double)clean > 0.0) {
- clean++;
- }
- return clean.to_string ();
- }
- }
- public class Vp9Video1080pLowFramerateProfile : EncodingProfile {
-
- public override string[] get_first_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 1);
- }
- public override string[] get_second_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 2);
- }
- public override string output_name () {
- return @"1080p.webm";
- }
- public override string version_label (){
- return @"1080p";
- }
- public override bool suitable_for (VideoInfo info) {
- return info.height >= 1080;
- }
- public override void setup_for (VideoInfo info) {
- codec_names = "vp9, opus";
- var width = (int) (info.ratio_frac * 1080);
- size = @"$(width)x1080";
- fps = get_low_framerate (info.frame_rate);
- }
- private string[] get_command(string input_path, string output_path, int pass) {
- return new string[] {
- "ffmpeg",
- "-i", input_path,
- "-r", fps.to_string (),
- "-vf", @"scale=$(size)",
- "-b:v", "1800k",
- "-minrate", "900k",
- "-maxrate", "2610k",
- "-tile-columns", "2",
- "-g", "240",
- "-threads", get_num_processors().to_string(),
- "-quality", "good",
- "-crf", "31",
- "-c:v", "libvpx-vp9",
- "-c:a", "libopus",
- "-pass", pass.to_string(),
- "-speed", "4",
- "-passlogfile", @"$(output_path).logfile",
- "-y",
- output_path
- };
- }
- }
- public class Vp9Video720pProfile : EncodingProfile {
-
- public override string[] get_first_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 1);
- }
- public override string[] get_second_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 2);
- }
- public override string output_name () {
- return @"720p.webm";
- }
- public override string version_label (){
- return @"720p";
- }
- public override bool suitable_for (VideoInfo info) {
- return info.height >= 720;
- }
- public override void setup_for (VideoInfo info) {
- codec_names = "vp9, opus";
- var width = (int) (info.ratio_frac * 720);
- size = @"$(width)x720";
- fps = get_low_framerate (info.frame_rate);
- }
- private string[] get_command(string input_path, string output_path, int pass) {
- return new string[] {
- "ffmpeg",
- "-i", input_path,
- "-r", fps.to_string(),
- "-vf", @"scale=$(size)",
- "-b:v", "1024k",
- "-minrate", "512k",
- "-maxrate", "1485k",
- "-tile-columns", "2",
- "-g", "240",
- "-threads", get_num_processors().to_string(),
- "-quality", "good",
- "-crf", "32",
- "-c:v", "libvpx-vp9",
- "-c:a", "libopus",
- "-pass", pass.to_string(),
- "-speed", "4",
- "-passlogfile", @"$(output_path).logfile",
- "-y",
- output_path
- };
- }
- }
- public class Vp9Video480pProfile : EncodingProfile {
-
- public override string[] get_first_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 1);
- }
- public override string[] get_second_pass_command (string input_path, string output_path) {
- return get_command (input_path, output_path, 2);
- }
- public override string output_name () {
- return @"480p.webm";
- }
- public override string version_label (){
- return @"480p";
- }
- public override bool suitable_for (VideoInfo info) {
- return info.height >= 480;
- }
- public override void setup_for (VideoInfo info) {
- codec_names = "vp9, opus";
- var width = (int) (info.ratio_frac * 480);
- size = @"$(width)x480";
- fps = get_low_framerate (info.frame_rate);
- }
- private string[] get_command(string input_path, string output_path, int pass) {
- return new string[] {
- "ffmpeg",
- "-i", input_path,
- "-r", fps.to_string(),
- "-vf", @"scale=$(size)",
- "-b:v", "750k",
- "-minrate", "375k",
- "-maxrate", "1088k",
- "-tile-columns", "2",
- "-g", "240",
- "-threads", get_num_processors().to_string(),
- "-quality", "good",
- "-crf", "33",
- "-c:v", "libvpx-vp9",
- "-c:a", "libopus",
- "-pass", pass.to_string(),
- "-speed", "4",
- "-passlogfile", @"$(output_path).logfile",
- "-y",
- output_path
- };
- }
- }
- }
|