Billy Barrow 1 lună în urmă
părinte
comite
e6daf8d61b
3 a modificat fișierele cu 50 adăugiri și 30 ștergeri
  1. 6 11
      src/EncodingProfile.vala
  2. 38 13
      src/VideoInfo.vala
  3. 6 6
      src/Vp9Profiles.vala

+ 6 - 11
src/EncodingProfile.vala

@@ -28,18 +28,13 @@ namespace Webmify {
     }
 
     public static Invercargill.Enumerable<EncodingProfile> construct_profiles() {
-        var vp9_720 = new Vp9Video720pProfile();
-        var vp9_480 = new Vp9Video480pProfile();
-        var vp9_360 = new Vp9Video360pProfile();
-        var vp9_240 = new Vp9Video240pProfile();
-
         return Invercargill.Iterate.these<EncodingProfile>(
-            new Vp9Video1080pHighFramerateProfile (),
-            new Vp9Video1080pLowFramerateProfile (),
-            vp9_720,
-            vp9_480,
-            vp9_360,
-            vp9_240
+            new Vp9Video240pProfile(),
+            new Vp9Video360pProfile(),
+            new Vp9Video480pProfile(),
+            new Vp9Video720pProfile(),
+            new Vp9Video1080pHighFramerateProfile(),
+            new Vp9Video1080pLowFramerateProfile()
         );
     }
 

+ 38 - 13
src/VideoInfo.vala

@@ -32,25 +32,50 @@ namespace Webmify {
             var root = parser.get_root().get_object();
             var streams = root.get_array_member("streams");
 
-            streams.foreach_element((a, i, n) => {
-                var stream = n.get_object();
-                var type = stream.get_string_member("codec_type");
-                if(type == "video") {
-                    width = (int)stream.get_int_member("width");
-                    height = (int)stream.get_int_member("height");
-                    aspect_ratio = stream.get_string_member("display_aspect_ratio");
-                    ratio_frac = ((double)width / (double)height);
-
-                    var fps_string = stream.get_string_member("r_frame_rate");
-                    var fps_parts = fps_string.split("/");
-                    frame_rate = double.parse(fps_parts[0]) / double.parse(fps_parts[1]);
+            bool found = false;
+            for(uint i = 0; i < streams.get_length() && !found; i++) {
+                var stream = streams.get_object_element(i);
+                if(stream.get_string_member("codec_type") != "video") {
+                    continue;
                 }
-            });
+                if(is_attached_picture(stream)) {
+                    continue;
+                }
+                width = (int)stream.get_int_member("width");
+                height = (int)stream.get_int_member("height");
+                aspect_ratio = stream.get_string_member("display_aspect_ratio");
+                ratio_frac = ((double)width / (double)height);
+                frame_rate = parse_fps(stream.get_string_member("r_frame_rate"));
+                found = true;
+            }
 
             duration = double.parse(root.get_object_member("format").get_string_member("duration"));
 
         }
 
+        private static bool is_attached_picture(Json.Object stream) {
+            if(!stream.has_member("disposition")) {
+                return false;
+            }
+            var disposition = stream.get_object_member("disposition");
+            if(!disposition.has_member("attached_pic")) {
+                return false;
+            }
+            return disposition.get_int_member("attached_pic") == 1;
+        }
+
+        private static double parse_fps(string value) {
+            var parts = value.split("/");
+            if(parts.length != 2) {
+                return 0.0;
+            }
+            double den = double.parse(parts[1]);
+            if(den == 0) {
+                return 0.0;
+            }
+            return double.parse(parts[0]) / den;
+        }
+
 
     }
 

+ 6 - 6
src/Vp9Profiles.vala

@@ -16,7 +16,7 @@ namespace Webmify {
             return @"1080p $(get_clean_fps(fps))fps";
         }
         public override bool suitable_for (VideoInfo info) {
-            return (info.height >= 1080 || info.width >= 1920) && get_low_framerate (info.frame_rate) != info.frame_rate;
+            return get_low_framerate (info.frame_rate) != info.frame_rate;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";
@@ -77,7 +77,7 @@ namespace Webmify {
             return @"1080p";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 1080 || info.width >= 1920;
+            return true;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";
@@ -128,7 +128,7 @@ namespace Webmify {
             return @"720p";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 720;
+            return info.height <= 720;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";
@@ -180,7 +180,7 @@ namespace Webmify {
             return @"480p";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 480;
+            return info.height <= 480;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";
@@ -232,7 +232,7 @@ namespace Webmify {
             return @"360p";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 360;
+            return info.height <= 360;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";
@@ -284,7 +284,7 @@ namespace Webmify {
             return @"240p";
         }
         public override bool suitable_for (VideoInfo info) {
-            return info.height >= 240;
+            return info.height <= 240;
         }
         public override void setup_for (VideoInfo info) {
             codec_names = "vp9, opus";