Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions QuickLook.Plugin/QuickLook.Plugin.VideoViewer/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using QuickLook.MediaInfo;
using QuickLook.MediaInfo.Core;
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows;
Expand Down Expand Up @@ -83,18 +84,18 @@ public bool CanHandle(string path)
return false;
}

/// <summary>
/// Configures the preview window, accounting for video dimensions and rotation.
/// </summary>
public void Prepare(string path, ContextObject context)
{
string videoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
if (!string.IsNullOrWhiteSpace(videoCodec)) // video
{
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Width"), out var width);
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Height"), out var height);
double.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Rotation"), out var rotation);

// Correct rotation: on some machine the value "90" becomes "90000" by some reason
if (rotation > 360)
rotation /= 1e3;
// Parse "90.000" as 90 in every culture, avoiding 90000 (de-DE) or 0 (ru-RU).
double.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Rotation"), NumberStyles.Float, CultureInfo.InvariantCulture, out var rotation);

var windowSize = new Size
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -455,6 +456,9 @@ private void HardwareAccelerationModeChanged(bool enable)
}
}

/// <summary>
/// Loads media for playback and applies video rotation from its metadata.
/// </summary>
public void LoadAndPlay(string path, MediaInfoNative info)
{
// Detect whether it is other playback formats
Expand All @@ -473,10 +477,7 @@ public void LoadAndPlay(string path, MediaInfoNative info)
UpdateMeta(path, info);

// detect rotation
_ = double.TryParse(info?.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
// Correct rotation: on some machine the value "90" becomes "90000" by some reason
if (rotation > 360d)
rotation /= 1e3;
_ = double.TryParse(info?.Get(StreamKind.Video, 0, "Rotation"), NumberStyles.Float, CultureInfo.InvariantCulture, out var rotation);
if (Math.Abs(rotation) > 0.1d)
mediaElement.LayoutTransform = new RotateTransform(rotation, 0.5d, 0.5d);

Expand Down