Ver código fonte

Tweak encoding profiles

Billy Barrow 2 anos atrás
pai
commit
930d0edb7b

+ 23 - 6
src/Video/EncodingProfile.vala

@@ -28,21 +28,35 @@ namespace Publicate.Video {
     }
 
     public static Invercargill.Enumerable<EncodingProfile> construct_free_profiles() {
+        var vp9_720 = new Vp9Video720pProfile();
+        var vp9_480 = new Vp9Video480pProfile();
+        var vp9_360 = new Vp9Video360pProfile();
+        var vp9_240 = new Vp9Video240pProfile();
+        var xiph_360 = new TheoraVideo360pProfile() {alternative_to = vp9_360};
+        var xiph_240 = new TheoraVideo240pProfile() {alternative_to = vp9_240};
+
         return Invercargill.ate(new EncodingProfile[] {
             new Vp9Video1080pHighFramerateProfile (),
             new Vp9Video1080pLowFramerateProfile (),
-            new Vp9Video720pProfile(),
-            new Vp9Video480pProfile(),
-            new TheoraVideo360pProfile(),
-            new TheoraVideo240pProfile(),
+            vp9_720,
+            vp9_480,
+            vp9_360,
+            xiph_360,
+            vp9_240,
+            xiph_240,
         });
     }
 
     public static Invercargill.Enumerable<EncodingProfile> construct_all_profiles() {
         var vp9_720 = new Vp9Video720pProfile();
         var vp9_480 = new Vp9Video480pProfile();
+        var vp9_360 = new Vp9Video360pProfile();
+        var vp9_240 = new Vp9Video240pProfile();
+        var xiph_360 = new TheoraVideo360pProfile() {alternative_to = vp9_360};
+        var xiph_240 = new TheoraVideo240pProfile() {alternative_to = vp9_240};
         var avc_720 = new H264Video720pProfile() {alternative_to = vp9_720};
         var avc_480 = new H264Video480pProfile() {alternative_to = vp9_480};
+        var avc_240 = new H264Video240pProfile() {alternative_to = xiph_240};
 
         return Invercargill.ate(new EncodingProfile[] {
             new Vp9Video1080pHighFramerateProfile (),
@@ -51,8 +65,11 @@ namespace Publicate.Video {
             avc_720,
             vp9_480,
             avc_480,
-            new TheoraVideo360pProfile(),
-            new TheoraVideo240pProfile(),
+            vp9_360,
+            xiph_360,
+            vp9_240,
+            xiph_240,
+            avc_240,
         });
     }
 

+ 72 - 14
src/Video/H264Profiles.vala

@@ -18,8 +18,11 @@ namespace Publicate.Video {
             return info.height >= 720;
         }
         public override void setup_for (VideoInfo info) {
-            codec_names = "avc1.64001f, mp4a.40.2";
+            codec_names = "avc1.42c028, mp4a.40.2";
             var width = (int) (info.ratio_frac * 720);
+            if(width % 2 != 0) {
+                width++;
+            }
             size = @"$(width)x720";
             fps = get_low_framerate (info.frame_rate);
         }
@@ -33,12 +36,12 @@ namespace Publicate.Video {
                 "-pix_fmt", "yuv420p",
                 "-profile:v", "baseline",
                 "-movflags", "+faststart",
-                "-b:v", "1024k",
-                "-minrate", "512k",
-                "-maxrate", "1485k",
+                "-b:v", "750k",
+                "-minrate", "375k",
+                "-maxrate", "1088k",
                 "-threads", get_num_processors().to_string(),
-                "-preset", "slow",
-                "-crf", "33",
+                "-preset", "slower",
+                "-crf", "39",
                 "-c:v", "libx264",
                 "-c:a", "aac",
                 "-pass", pass.to_string(),
@@ -64,11 +67,14 @@ namespace Publicate.Video {
             return @"480p H.264";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 720;
+            return info.height >= 480;
         }
         public override void setup_for (VideoInfo info) {
-            codec_names = "avc1.64001f, mp4a.40.2";
-            var width = (int) (info.ratio_frac * 720);
+            codec_names = "avc1.42c01f, mp4a.40.2";
+            var width = (int) (info.ratio_frac * 480);
+            if(width % 2 != 0) {
+                width++;
+            }
             size = @"$(width)x480";
             fps = get_low_framerate (info.frame_rate);
         }
@@ -82,12 +88,64 @@ namespace Publicate.Video {
                 "-pix_fmt", "yuv420p",
                 "-profile:v", "baseline",
                 "-movflags", "+faststart",
-                "-b:v", "750k",
-                "-minrate", "375k",
-                "-maxrate", "1088k",
+                "-b:v", "500k",
+                "-minrate", "175k",
+                "-maxrate", "750k",
+                "-threads", get_num_processors().to_string(),
+                "-preset", "slower",
+                "-crf", "42",
+                "-c:v", "libx264",
+                "-c:a", "aac",
+                "-pass", pass.to_string(),
+                "-passlogfile", @"$(output_path).logfile",
+                "-y",
+                output_path
+            };
+        }
+    }
+
+    public class H264Video240pProfile : 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 @"240p.mp4";
+        }
+        public override string version_label (){
+            return @"240p H.264";
+        }
+        public override bool suitable_for (VideoInfo info) {
+            return info.height >= 240;
+        }
+        public override void setup_for (VideoInfo info) {
+            codec_names = "avc1.42c015, mp4a.40.2";
+            var width = (int) (info.ratio_frac * 240);
+            if(width % 2 != 0) {
+                width++;
+            }
+            size = @"$(width)x240";
+            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)",
+                "-pix_fmt", "yuv420p",
+                "-profile:v", "baseline",
+                "-movflags", "+faststart",
+                "-b:v", "125k",
+                "-minrate", "70k",
+                "-maxrate", "425k",
                 "-threads", get_num_processors().to_string(),
-                "-preset", "slow",
-                "-crf", "34",
+                "-preset", "slower",
+                "-crf", "48",
                 "-c:v", "libx264",
                 "-c:a", "aac",
                 "-pass", pass.to_string(),

+ 7 - 4
src/Video/TheoraProfiles.vala

@@ -1,6 +1,7 @@
 
 namespace Publicate.Video {
 
+
     public class TheoraVideo360pProfile : EncodingProfile {
         
         public override string[] get_first_pass_command (string input_path, string output_path) {
@@ -11,7 +12,8 @@ namespace Publicate.Video {
                 "-s", size,
                 "-c:v", "theora",
                 "-c:a", "libvorbis",
-                "-b:v", "300k",
+                "-qscale:v", "4",
+                "-qscale:a", "4",
                 "-y",
                 output_path
             };
@@ -23,7 +25,7 @@ namespace Publicate.Video {
             return @"360p.ogv";
         }
         public override string version_label (){
-            return @"360p";
+            return @"360p Theora";
         }
         public override bool suitable_for (VideoInfo info) {
             return info.height >= 360;
@@ -46,7 +48,8 @@ namespace Publicate.Video {
                 "-s", size,
                 "-c:v", "theora",
                 "-c:a", "libvorbis",
-                "-b:v", "150k",
+                "-qscale:v", "4",
+                "-qscale:a", "4",
                 "-y",
                 output_path
             };
@@ -58,7 +61,7 @@ namespace Publicate.Video {
             return @"240p.ogv";
         }
         public override string version_label (){
-            return @"240p";
+            return @"240p Theora";
         }
         public override bool suitable_for (VideoInfo info) {
             return info.height >= 240;

+ 100 - 0
src/Video/Vp9Profiles.vala

@@ -211,4 +211,104 @@ namespace Publicate.Video {
 
     }
 
+    public class Vp9Video360pProfile : 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 @"360p.webm";
+        }
+        public override string version_label (){
+            return @"360p";
+        }
+        public override bool suitable_for (VideoInfo info) {
+            return info.height >= 360;
+        }
+        public override void setup_for (VideoInfo info) {
+            codec_names = "vp9, opus";
+            var width = (int) (info.ratio_frac * 360);
+            size = @"$(width)x360";
+            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", "276k",
+                "-minrate", "138k",
+                "-maxrate", "400k",
+                "-tile-columns", "1",
+                "-g", "240",
+                "-threads", get_num_processors().to_string(),
+                "-quality", "good",
+                "-crf", "36",
+                "-c:v", "libvpx-vp9",
+                "-c:a", "libopus",
+                "-pass", pass.to_string(),
+                "-speed", "4",
+                "-passlogfile", @"$(output_path).logfile",
+                "-y",
+                output_path
+            };
+        }
+
+    }
+
+    public class Vp9Video240pProfile : 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 @"240p.webm";
+        }
+        public override string version_label (){
+            return @"240p";
+        }
+        public override bool suitable_for (VideoInfo info) {
+            return info.height >= 240;
+        }
+        public override void setup_for (VideoInfo info) {
+            codec_names = "vp9, opus";
+            var width = (int) (info.ratio_frac * 240);
+            size = @"$(width)x240";
+            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", "150k",
+                "-minrate", "75k",
+                "-maxrate", "218k",
+                "-tile-columns", "0",
+                "-g", "240",
+                "-threads", get_num_processors().to_string(),
+                "-quality", "good",
+                "-crf", "37",
+                "-c:v", "libvpx-vp9",
+                "-c:a", "libopus",
+                "-pass", pass.to_string(),
+                "-speed", "4",
+                "-passlogfile", @"$(output_path).logfile",
+                "-y",
+                output_path
+            };
+        }
+
+    }
+
 }