Fix #263, #308: mediainfo and video rotation

This commit is contained in:
Paddy Xu
2018-08-04 17:15:57 +03:00
parent 302c1b57f8
commit 6b72f388f6
8 changed files with 3690 additions and 35 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,10 +18,10 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using MediaInfo;
using QuickLook.Common.Plugin;
using TagLib;
using File = TagLib.File;
namespace QuickLook.Plugin.VideoViewer
{
@@ -39,7 +39,7 @@ namespace QuickLook.Plugin.VideoViewer
};
private ContextObject _context;
private File _det;
private MediaInfo.MediaInfo _mediaInfo;
private ViewerPanel _vp;
@@ -61,22 +61,38 @@ namespace QuickLook.Plugin.VideoViewer
try
{
_det = File.Create(path);
_mediaInfo = new MediaInfo.MediaInfo(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
_mediaInfo.Option("Cover_Data", "base64");
_mediaInfo.Open(path);
}
catch (Exception)
{
// ignored
_mediaInfo?.Dispose();
_mediaInfo = null;
}
context.TitlebarOverlap = true;
if ((_det?.Properties.MediaTypes ?? MediaTypes.Video).HasFlag(MediaTypes.Video)) // video
if (_mediaInfo == null ||
!string.IsNullOrEmpty(_mediaInfo.Get(StreamKind.General, 0, "VideoCount"))) // video
{
int.TryParse(_mediaInfo?.Get(StreamKind.Audio, 0, "Width"), out var width);
int.TryParse(_mediaInfo?.Get(StreamKind.Audio, 0, "Height"), out var height);
double.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
var windowSize = new Size
{
Width = Math.Max(1366, _det?.Properties.VideoWidth ?? 1366),
Height = Math.Max(768, _det?.Properties.VideoHeight ?? 768)
Width = Math.Max(1366, width == 0 ? 1366 : width),
Height = Math.Max(768, height == 0 ? 768 : height)
};
if (rotation % 180 != 0)
windowSize = new Size(windowSize.Height, windowSize.Width);
context.SetPreferredSizeFit(windowSize, 0.8);
context.TitlebarAutoHide = true;
@@ -102,7 +118,7 @@ namespace QuickLook.Plugin.VideoViewer
context.Title = $"{Path.GetFileName(path)}";
_vp.LoadAndPlay(path, _det);
_vp.LoadAndPlay(path, _mediaInfo);
}
public void Cleanup()
@@ -110,8 +126,8 @@ namespace QuickLook.Plugin.VideoViewer
_vp?.Dispose();
_vp = null;
_det?.Dispose();
_det = null;
_mediaInfo?.Dispose();
_mediaInfo = null;
_context = null;
}

View File

@@ -60,8 +60,8 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath>
<Reference Include="MediaInfo.Wrapper">
<HintPath>.\MediaInfo.Wrapper.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -70,9 +70,6 @@
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<HintPath>..\..\packages\taglib.2.1.0.0\lib\taglib-sharp.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
@@ -148,6 +145,12 @@
<Content Include="LAVFilters-0.72-x64\avutil-lav-56.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MediaInfo-x64\MediaInfo.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="MediaInfo-x86\MediaInfo.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Resource Include="LAVFilters-0.72-x64\CHANGELOG.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
@@ -247,7 +250,6 @@
<None Include="LAVFilters-0.72-x86\LAVVideo.ax.bak">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Resources\QLV.reg" />
</ItemGroup>
<ItemGroup>

View File

@@ -25,15 +25,15 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using MediaInfo;
using QuickLook.Common.Annotations;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using TagLib;
using WPFMediaKit.DirectShow.Controls;
using WPFMediaKit.DirectShow.MediaPlayers;
using File = TagLib.File;
namespace QuickLook.Plugin.VideoViewer
{
@@ -204,24 +204,27 @@ namespace QuickLook.Plugin.VideoViewer
}
}
private void UpdateMeta(string path, File det)
private void UpdateMeta(string path, MediaInfo.MediaInfo info)
{
if (HasVideo)
return;
try
{
if (det == null)
if (info == null)
throw new NullReferenceException();
metaTitle.Text = !string.IsNullOrWhiteSpace(det.Tag.Title) ? det.Tag.Title : Path.GetFileName(path);
metaArtists.Text = det.Tag.FirstPerformer;
metaAlbum.Text = det.Tag.Album;
var title = info.Get(StreamKind.General, 0, "Title");
var artist = info.Get(StreamKind.General, 0, "Performer");
var album = info.Get(StreamKind.General, 0, "Album");
//var cs = h.Tag.Pictures.FirstOrDefault(p => p.Type == TagLib.PictureType.FrontCover);
var cs = det.Tag.Pictures.FirstOrDefault();
if (cs != default(IPicture))
using (var ms = new MemoryStream(cs.Data.Data))
metaTitle.Text = !string.IsNullOrWhiteSpace(title) ? title : Path.GetFileName(path);
metaArtists.Text = artist;
metaAlbum.Text = album;
var cs = info.Get(StreamKind.General, 0, "Cover_Data");
if (!string.IsNullOrEmpty(cs))
using (var ms = new MemoryStream(Convert.FromBase64String(cs)))
{
CoverArt = BitmapFrame.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
@@ -257,9 +260,14 @@ namespace QuickLook.Plugin.VideoViewer
mediaElement.Play();
}
public void LoadAndPlay(string path, File det)
public void LoadAndPlay(string path, MediaInfo.MediaInfo info)
{
UpdateMeta(path, det);
UpdateMeta(path, info);
// detect rotation
double.TryParse(info?.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
if (Math.Abs(rotation) > 0.1)
mediaElement.LayoutTransform = new RotateTransform(rotation, 0.5, 0.5);
mediaElement.Source = new Uri(path);
mediaElement.Volume = SettingHelper.Get("VolumeDouble", 0.7);

View File

@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="taglib" version="2.1.0.0" targetFramework="net462" />
</packages>