Bladeren bron

fix: don't do empty hwupload for VT (#11235)

gnattu 1 jaar geleden
bovenliggende
commit
fe88a484d1
1 gewijzigde bestanden met toevoegingen van 15 en 5 verwijderingen
  1. 15 5
      MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

+ 15 - 5
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs

@@ -5119,11 +5119,6 @@ namespace MediaBrowser.Controller.MediaEncoding
             /* Make main filters for video stream */
             var mainFilters = new List<string>();
 
-            // INPUT videotoolbox/memory surface(vram/uma)
-            // this will pass-through automatically if in/out format matches.
-            mainFilters.Add("format=nv12|p010le|videotoolbox_vld");
-            mainFilters.Add("hwupload=derive_device=videotoolbox");
-
             // hw deint
             if (doDeintH2645)
             {
@@ -5179,6 +5174,21 @@ namespace MediaBrowser.Controller.MediaEncoding
                 overlayFilters.Add("overlay_videotoolbox=eof_action=pass:repeatlast=0");
             }
 
+            var needFiltering = mainFilters.Any(f => !string.IsNullOrEmpty(f)) ||
+                                subFilters.Any(f => !string.IsNullOrEmpty(f)) ||
+                                overlayFilters.Any(f => !string.IsNullOrEmpty(f));
+
+            // This is a workaround for ffmpeg's hwupload implementation
+            // For VideoToolbox encoders, a hwupload without a valid filter actually consuming its frame
+            // will cause the encoder to produce incorrect frames.
+            if (needFiltering)
+            {
+                // INPUT videotoolbox/memory surface(vram/uma)
+                // this will pass-through automatically if in/out format matches.
+                mainFilters.Insert(0, "format=nv12|p010le|videotoolbox_vld");
+                mainFilters.Insert(0, "hwupload=derive_device=videotoolbox");
+            }
+
             return (mainFilters, subFilters, overlayFilters);
         }