浏览代码

PlayerComponent: add a mode to force 16:9 aspect ratio for 4:3 video

Still missing:
- "video.aspect.force169if43" in web-client
- deps bump for "video-dec-params" libmpv property

On old deps, it will assume the video is never 4:3.
Vincent Lang 7 年之前
父节点
当前提交
73d95f6f75
共有 2 个文件被更改,包括 15 次插入0 次删除
  1. 1 0
      resources/settings/settings_description.json
  2. 14 0
      src/player/PlayerComponent.cpp

+ 1 - 0
resources/settings/settings_description.json

@@ -289,6 +289,7 @@
           [ "zoom", "video.aspect.zoom" ],
           [ "force_4_3", "video.aspect.force43" ],
           [ "force_16_9", "video.aspect.force169" ],
+          [ "force_16_9_if_4_3", "video.aspect.force169if43" ],
           [ "stretch", "video.aspect.stretch" ],
           [ "noscaling", "video.aspect.noscale" ],
           [ "custom", "video.aspect.custom" ]

+ 14 - 0
src/player/PlayerComponent.cpp

@@ -135,6 +135,7 @@ bool PlayerComponent::componentInitialize()
   mpv_observe_property(m_mpv, 0, "vo-configured", MPV_FORMAT_FLAG);
   mpv_observe_property(m_mpv, 0, "duration", MPV_FORMAT_DOUBLE);
   mpv_observe_property(m_mpv, 0, "audio-device-list", MPV_FORMAT_NODE);
+  mpv_observe_property(m_mpv, 0, "video-dec-params", MPV_FORMAT_NODE);
 
   connect(this, &PlayerComponent::onMpvEvents, this, &PlayerComponent::handleMpvEvents, Qt::QueuedConnection);
 
@@ -482,6 +483,12 @@ void PlayerComponent::handleMpvEvent(mpv_event *event)
       {
         updateAudioDeviceList();
       }
+      else if (strcmp(prop->name, "video-dec-params") == 0)
+      {
+        // Aspect might be known now (or it changed during playback), so update settings
+        // dependent on the aspect ratio.
+        updateVideoAspectSettings();
+      }
       break;
     }
     case MPV_EVENT_LOG_MESSAGE:
@@ -1003,6 +1010,13 @@ void PlayerComponent::updateVideoAspectSettings()
   {
     forceAspect = "16:9";
   }
+  else if (mode == "force_16_9_if_4_3")
+  {
+    auto params = mpv::qt::get_property_variant(m_mpv, "video-dec-params").toMap();
+    auto aspect = params["aspect"].toFloat();
+    if (fabs(aspect - 4.0/3.0) < 0.1)
+      forceAspect = "16:9";
+  }
   else if (mode == "stretch")
   {
     keepAspect = false;