From 60ac2e87129a1911ed518ea21977b1f689da015d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 Oct 2015 10:02:30 -0400 Subject: rework shutdown --- MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 7e9fa151b..56ce6b6d6 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -130,13 +130,18 @@ namespace MediaBrowser.MediaEncoding.Probing var stream = new MediaStream { Codec = streamInfo.codec_name, - CodecTag = streamInfo.codec_tag_string, Profile = streamInfo.profile, Level = streamInfo.level, Index = streamInfo.index, PixelFormat = streamInfo.pix_fmt }; + // Filter out junk + if (!string.IsNullOrWhiteSpace(streamInfo.codec_tag_string) && streamInfo.codec_tag_string.IndexOf("[0]", StringComparison.OrdinalIgnoreCase) == -1) + { + stream.CodecTag = streamInfo.codec_tag_string; + } + if (streamInfo.tags != null) { stream.Language = GetDictionaryValue(streamInfo.tags, "language"); -- cgit v1.2.3 From b5f0cc5ad7fd5976b20673e631cf155e432b7230 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Nov 2015 23:11:14 -0500 Subject: use int tryparse --- MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index ddcd48b8b..d4df19af2 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -49,7 +49,11 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrEmpty(data.format.bit_rate)) { - info.Bitrate = int.Parse(data.format.bit_rate, _usCulture); + int value; + if (int.TryParse(data.format.bit_rate, NumberStyles.Any, _usCulture, out value)) + { + info.Bitrate = value; + } } } -- cgit v1.2.3 From 5963affec5b492d4859017cfd9352dfd683b3795 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Dec 2015 10:56:07 -0500 Subject: fix merge conflict --- .../MediaBrowser.MediaEncoding.csproj | 4 - .../Probing/ProbeResultNormalizer.cs | 34 +-- .../MediaBrowser.MediaInfo.csproj | 58 ----- MediaBrowser.MediaInfo/MediaInfoLib.cs | 65 ----- MediaBrowser.MediaInfo/Native.cs | 275 --------------------- MediaBrowser.MediaInfo/Properties/AssemblyInfo.cs | 31 --- .../MediaBrowser.Server.Mono.csproj | 4 - MediaBrowser.sln | 23 -- 8 files changed, 11 insertions(+), 483 deletions(-) delete mode 100644 MediaBrowser.MediaInfo/MediaBrowser.MediaInfo.csproj delete mode 100644 MediaBrowser.MediaInfo/MediaInfoLib.cs delete mode 100644 MediaBrowser.MediaInfo/Native.cs delete mode 100644 MediaBrowser.MediaInfo/Properties/AssemblyInfo.cs (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index 1f74994e5..df5ab4651 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -99,10 +99,6 @@ {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller - - {6e4145e4-c6d4-4e4d-94f2-87188db6e239} - MediaBrowser.MediaInfo - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} MediaBrowser.Model diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index d4df19af2..55b3398bb 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.IO; -using MediaBrowser.MediaInfo; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; @@ -26,7 +25,7 @@ namespace MediaBrowser.MediaEncoding.Probing _fileSystem = fileSystem; } - public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) + public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new Model.MediaInfo.MediaInfo { @@ -109,7 +108,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (videoStream != null && videoType == VideoType.VideoFile) { - UpdateFromMediaInfo(info, videoStream); + DetectInterlaced(info, videoStream); } } @@ -934,29 +933,18 @@ namespace MediaBrowser.MediaEncoding.Probing return TransportStreamTimestamp.None; } - private void UpdateFromMediaInfo(MediaSourceInfo video, MediaStream videoStream) + private void DetectInterlaced(MediaSourceInfo video, MediaStream videoStream) { - if (video.Protocol == MediaProtocol.File && videoStream != null) + if (video.Protocol != MediaProtocol.File || videoStream == null) { - try - { - _logger.Debug("Running MediaInfo against {0}", video.Path); - - var result = new MediaInfoLib().GetVideoInfo(video.Path); + return; + } - videoStream.IsCabac = result.IsCabac ?? videoStream.IsCabac; - videoStream.IsInterlaced = result.IsInterlaced ?? videoStream.IsInterlaced; - videoStream.BitDepth = result.BitDepth ?? videoStream.BitDepth; - videoStream.RefFrames = result.RefFrames ?? videoStream.RefFrames; - } - catch (TypeLoadException) - { - // This is non-essential. Don't spam the log - } - catch (Exception ex) - { - _logger.ErrorException("Error running MediaInfo on {0}", ex, video.Path); - } + // Take a shortcut and limit this to containers that are likely to have interlaced content + if (!string.Equals(video.Container, "ts", StringComparison.OrdinalIgnoreCase) && + !string.Equals(video.Container, "wtv", StringComparison.OrdinalIgnoreCase)) + { + return; } } } diff --git a/MediaBrowser.MediaInfo/MediaBrowser.MediaInfo.csproj b/MediaBrowser.MediaInfo/MediaBrowser.MediaInfo.csproj deleted file mode 100644 index 024098cb9..000000000 --- a/MediaBrowser.MediaInfo/MediaBrowser.MediaInfo.csproj +++ /dev/null @@ -1,58 +0,0 @@ - - - - - Debug - AnyCPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239} - Library - Properties - MediaBrowser.MediaInfo - MediaBrowser.MediaInfo - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - none - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - Properties\SharedVersion.cs - - - - - - - - - \ No newline at end of file diff --git a/MediaBrowser.MediaInfo/MediaInfoLib.cs b/MediaBrowser.MediaInfo/MediaInfoLib.cs deleted file mode 100644 index fa644aee0..000000000 --- a/MediaBrowser.MediaInfo/MediaInfoLib.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; - -namespace MediaBrowser.MediaInfo -{ - public class MediaInfoLib - { - public MediaInfoResult GetVideoInfo(string path) - { - var lib = new MediaInfo(); - - lib.Open(path); - - var result = new MediaInfoResult(); - - // TODO: Don't hardcode - var videoStreamIndex = 0; - - var text = GetValue(lib, videoStreamIndex, new[] { "ScanType", "Scan type", "ScanType/String" }); - if (!string.IsNullOrWhiteSpace(text)) - { - result.IsInterlaced = text.IndexOf("interlac", StringComparison.OrdinalIgnoreCase) != -1; - } - - text = GetValue(lib, videoStreamIndex, new[] { "Format_Settings_CABAC", "Format_Settings_CABAC/String" }); - if (!string.IsNullOrWhiteSpace(text)) - { - result.IsCabac = string.Equals(text, "yes", StringComparison.OrdinalIgnoreCase); - } - - int bitDepth; - text = GetValue(lib, videoStreamIndex, new[] { "BitDepth", "BitDepth/String" }); - - if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out bitDepth)) - { - result.BitDepth = bitDepth; - } - - int refFrames; - text = GetValue(lib, videoStreamIndex, new[] { "Format_Settings_RefFrames", "Format_Settings_RefFrames/String" }); - - if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text.Split(' ').First(), NumberStyles.Any, CultureInfo.InvariantCulture, out refFrames)) - { - result.RefFrames = refFrames; - } - - return result; - } - - private string GetValue(MediaInfo lib, int index, IEnumerable names) - { - return names.Select(i => lib.Get(StreamKind.Video, index, i)).FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); - } - } - - public class MediaInfoResult - { - public bool? IsCabac { get; set; } - public bool? IsInterlaced { get; set; } - public int? BitDepth { get; set; } - public int? RefFrames { get; set; } - } -} diff --git a/MediaBrowser.MediaInfo/Native.cs b/MediaBrowser.MediaInfo/Native.cs deleted file mode 100644 index 5bc7ae368..000000000 --- a/MediaBrowser.MediaInfo/Native.cs +++ /dev/null @@ -1,275 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace MediaBrowser.MediaInfo -{ - public enum StreamKind - { - General, - Video, - Audio, - Text, - Other, - Image, - Menu, - } - - public enum InfoKind - { - Name, - Text, - Measure, - Options, - NameText, - MeasureText, - Info, - HowTo - } - - public enum InfoOptions - { - ShowInInform, - Support, - ShowInSupported, - TypeOfValue - } - - public enum InfoFileOptions - { - FileOption_Nothing = 0x00, - FileOption_NoRecursive = 0x01, - FileOption_CloseAll = 0x02, - FileOption_Max = 0x04 - }; - - public enum Status - { - None = 0x00, - Accepted = 0x01, - Filled = 0x02, - Updated = 0x04, - Finalized = 0x08, - } - - public class MediaInfo - { - //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory) - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_New(); - [DllImport("MediaInfo")] - private static extern void MediaInfo_Delete(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Open(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string FileName); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Open(IntPtr Handle, IntPtr FileName); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Open_Buffer_Init(IntPtr Handle, Int64 File_Size, Int64 File_Offset); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Open(IntPtr Handle, Int64 File_Size, Int64 File_Offset); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Open_Buffer_Continue(IntPtr Handle, IntPtr Buffer, IntPtr Buffer_Size); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Open_Buffer_Continue(IntPtr Handle, Int64 File_Size, byte[] Buffer, IntPtr Buffer_Size); - [DllImport("MediaInfo")] - private static extern Int64 MediaInfo_Open_Buffer_Continue_GoTo_Get(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern Int64 MediaInfoA_Open_Buffer_Continue_GoTo_Get(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Open_Buffer_Finalize(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Open_Buffer_Finalize(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern void MediaInfo_Close(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Inform(IntPtr Handle, IntPtr Reserved); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Inform(IntPtr Handle, IntPtr Reserved); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_GetI(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_GetI(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, [MarshalAs(UnmanagedType.LPWStr)] string Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Option(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string Option, [MarshalAs(UnmanagedType.LPWStr)] string Value); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoA_Option(IntPtr Handle, IntPtr Option, IntPtr Value); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_State_Get(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfo_Count_Get(IntPtr Handle, IntPtr StreamKind, IntPtr StreamNumber); - - //MediaInfo class - public MediaInfo() - { - try - { - Handle = MediaInfo_New(); - } - catch - { - Handle = (IntPtr)0; - } - if (Environment.OSVersion.ToString().IndexOf("Windows") == -1) - MustUseAnsi = true; - else - MustUseAnsi = false; - } - ~MediaInfo() { if (Handle == (IntPtr)0) return; MediaInfo_Delete(Handle); } - public int Open(String FileName) - { - if (Handle == (IntPtr)0) - return 0; - if (MustUseAnsi) - { - IntPtr FileName_Ptr = Marshal.StringToHGlobalAnsi(FileName); - int ToReturn = (int)MediaInfoA_Open(Handle, FileName_Ptr); - Marshal.FreeHGlobal(FileName_Ptr); - return ToReturn; - } - else - return (int)MediaInfo_Open(Handle, FileName); - } - public int Open_Buffer_Init(Int64 File_Size, Int64 File_Offset) - { - if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Open_Buffer_Init(Handle, File_Size, File_Offset); - } - public int Open_Buffer_Continue(IntPtr Buffer, IntPtr Buffer_Size) - { - if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Open_Buffer_Continue(Handle, Buffer, Buffer_Size); - } - public Int64 Open_Buffer_Continue_GoTo_Get() - { - if (Handle == (IntPtr)0) return 0; return (Int64)MediaInfo_Open_Buffer_Continue_GoTo_Get(Handle); - } - public int Open_Buffer_Finalize() - { - if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Open_Buffer_Finalize(Handle); - } - public void Close() { if (Handle == (IntPtr)0) return; MediaInfo_Close(Handle); } - public String Inform() - { - if (Handle == (IntPtr)0) - return "Unable to load MediaInfo library"; - if (MustUseAnsi) - return Marshal.PtrToStringAnsi(MediaInfoA_Inform(Handle, (IntPtr)0)); - else - return Marshal.PtrToStringUni(MediaInfo_Inform(Handle, (IntPtr)0)); - } - public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch) - { - if (Handle == (IntPtr)0) - return "Unable to load MediaInfo library"; - if (MustUseAnsi) - { - IntPtr Parameter_Ptr = Marshal.StringToHGlobalAnsi(Parameter); - String ToReturn = Marshal.PtrToStringAnsi(MediaInfoA_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter_Ptr, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)); - Marshal.FreeHGlobal(Parameter_Ptr); - return ToReturn; - } - else - return Marshal.PtrToStringUni(MediaInfo_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)); - } - public String Get(StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo) - { - if (Handle == (IntPtr)0) - return "Unable to load MediaInfo library"; - if (MustUseAnsi) - return Marshal.PtrToStringAnsi(MediaInfoA_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)); - else - return Marshal.PtrToStringUni(MediaInfo_GetI(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)); - } - public String Option(String Option, String Value) - { - if (Handle == (IntPtr)0) - return "Unable to load MediaInfo library"; - if (MustUseAnsi) - { - IntPtr Option_Ptr = Marshal.StringToHGlobalAnsi(Option); - IntPtr Value_Ptr = Marshal.StringToHGlobalAnsi(Value); - String ToReturn = Marshal.PtrToStringAnsi(MediaInfoA_Option(Handle, Option_Ptr, Value_Ptr)); - Marshal.FreeHGlobal(Option_Ptr); - Marshal.FreeHGlobal(Value_Ptr); - return ToReturn; - } - else - return Marshal.PtrToStringUni(MediaInfo_Option(Handle, Option, Value)); - } - public int State_Get() { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_State_Get(Handle); } - public int Count_Get(StreamKind StreamKind, int StreamNumber) { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber); } - private IntPtr Handle; - private bool MustUseAnsi; - - //Default values, if you know how to set default values in C#, say me - public String Get(StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo) { return Get(StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); } - public String Get(StreamKind StreamKind, int StreamNumber, String Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); } - public String Get(StreamKind StreamKind, int StreamNumber, int Parameter) { return Get(StreamKind, StreamNumber, Parameter, InfoKind.Text); } - public String Option(String Option_) { return Option(Option_, ""); } - public int Count_Get(StreamKind StreamKind) { return Count_Get(StreamKind, -1); } - } - - - - - - - - - - - - - - - - - - public class MediaInfoList - { - //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory) - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_New(); - [DllImport("MediaInfo")] - private static extern void MediaInfoList_Delete(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_Open(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string FileName, IntPtr Options); - [DllImport("MediaInfo")] - private static extern void MediaInfoList_Close(IntPtr Handle, IntPtr FilePos); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_Inform(IntPtr Handle, IntPtr FilePos, IntPtr Reserved); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_GetI(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber, IntPtr Parameter, IntPtr KindOfInfo); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber, [MarshalAs(UnmanagedType.LPWStr)] string Parameter, IntPtr KindOfInfo, IntPtr KindOfSearch); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_Option(IntPtr Handle, [MarshalAs(UnmanagedType.LPWStr)] string Option, [MarshalAs(UnmanagedType.LPWStr)] string Value); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_State_Get(IntPtr Handle); - [DllImport("MediaInfo")] - private static extern IntPtr MediaInfoList_Count_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber); - - //MediaInfo class - public MediaInfoList() { Handle = MediaInfoList_New(); } - ~MediaInfoList() { MediaInfoList_Delete(Handle); } - public int Open(String FileName, InfoFileOptions Options) { return (int)MediaInfoList_Open(Handle, FileName, (IntPtr)Options); } - public void Close(int FilePos) { MediaInfoList_Close(Handle, (IntPtr)FilePos); } - public String Inform(int FilePos) { return Marshal.PtrToStringUni(MediaInfoList_Inform(Handle, (IntPtr)FilePos, (IntPtr)0)); } - public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo, InfoKind KindOfSearch) { return Marshal.PtrToStringUni(MediaInfoList_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, Parameter, (IntPtr)KindOfInfo, (IntPtr)KindOfSearch)); } - public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, int Parameter, InfoKind KindOfInfo) { return Marshal.PtrToStringUni(MediaInfoList_GetI(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber, (IntPtr)Parameter, (IntPtr)KindOfInfo)); } - public String Option(String Option, String Value) { return Marshal.PtrToStringUni(MediaInfoList_Option(Handle, Option, Value)); } - public int State_Get() { return (int)MediaInfoList_State_Get(Handle); } - public int Count_Get(int FilePos, StreamKind StreamKind, int StreamNumber) { return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber); } - private IntPtr Handle; - - //Default values, if you know how to set default values in C#, say me - public void Open(String FileName) { Open(FileName, 0); } - public void Close() { Close(-1); } - public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter, InfoKind KindOfInfo) { return Get(FilePos, StreamKind, StreamNumber, Parameter, KindOfInfo, InfoKind.Name); } - public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, String Parameter) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text, InfoKind.Name); } - public String Get(int FilePos, StreamKind StreamKind, int StreamNumber, int Parameter) { return Get(FilePos, StreamKind, StreamNumber, Parameter, InfoKind.Text); } - public String Option(String Option_) { return Option(Option_, ""); } - public int Count_Get(int FilePos, StreamKind StreamKind) { return Count_Get(FilePos, StreamKind, -1); } - } -} diff --git a/MediaBrowser.MediaInfo/Properties/AssemblyInfo.cs b/MediaBrowser.MediaInfo/Properties/AssemblyInfo.cs deleted file mode 100644 index 8249bd33c..000000000 --- a/MediaBrowser.MediaInfo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.MediaInfo")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.MediaInfo")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("8ef5ed2a-0460-4fb4-ba3f-fc2ba057f009")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// \ No newline at end of file diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index 8b2b19c58..e9f631bf3 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -144,10 +144,6 @@ - - MediaInfo\osx\libmediainfo.dylib - PreserveNewest - libsqlite3.0.dylib PreserveNewest diff --git a/MediaBrowser.sln b/MediaBrowser.sln index 0dadf9136..a9b5020ec 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -56,8 +56,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.XbmcMetadata", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.LocalMetadata", "MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj", "{7EF9F3E0-697D-42F3-A08F-19DEB5F84392}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.MediaInfo", "MediaBrowser.MediaInfo\MediaBrowser.MediaInfo.csproj", "{6E4145E4-C6D4-4E4D-94F2-87188DB6E239}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Server.Mono", "MediaBrowser.Server.Mono\MediaBrowser.Server.Mono.csproj", "{175A9388-F352-4586-A6B4-070DED62B644}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Server.Startup.Common", "MediaBrowser.Server.Startup.Common\MediaBrowser.Server.Startup.Common.csproj", "{B90AB8F2-1BFF-4568-A3FD-2A338A435A75}" @@ -451,27 +449,6 @@ Global {7EF9F3E0-697D-42F3-A08F-19DEB5F84392}.Release|Win32.ActiveCfg = Release|Any CPU {7EF9F3E0-697D-42F3-A08F-19DEB5F84392}.Release|x64.ActiveCfg = Release|Any CPU {7EF9F3E0-697D-42F3-A08F-19DEB5F84392}.Release|x86.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|Win32.ActiveCfg = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|x64.ActiveCfg = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Debug|x86.ActiveCfg = Debug|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|Any CPU.Build.0 = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|Mixed Platforms.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|Mixed Platforms.Build.0 = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|Win32.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|x64.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release Mono|x86.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|Any CPU.Build.0 = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|Win32.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|x64.ActiveCfg = Release|Any CPU - {6E4145E4-C6D4-4E4D-94F2-87188DB6E239}.Release|x86.ActiveCfg = Release|Any CPU {175A9388-F352-4586-A6B4-070DED62B644}.Debug|Any CPU.ActiveCfg = Debug|x86 {175A9388-F352-4586-A6B4-070DED62B644}.Debug|Any CPU.Build.0 = Debug|x86 {175A9388-F352-4586-A6B4-070DED62B644}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 -- cgit v1.2.3 From fae4079a69eb253dd1f89b6925ca26f48be69eda Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Dec 2015 23:37:59 -0500 Subject: restore changes --- MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 2 +- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index d9fda220d..c297a425d 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -876,7 +876,7 @@ namespace MediaBrowser.MediaEncoding.Probing } } - private void ExtractTimestamp(Model.MediaInfo.MediaInfo video) + private void ExtractTimestamp(MediaInfo video) { if (video.VideoType == VideoType.VideoFile) { diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 7c0929be6..ef62365c6 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -356,12 +356,6 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - PreserveNewest -- cgit v1.2.3 From c68a03b3abecc20977e948a749d3d6d37836aa21 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 26 Dec 2015 21:39:11 -0500 Subject: capture bit depth with ffprobe --- .../Probing/ProbeResultNormalizer.cs | 38 +++++----------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index c297a425d..7c3293b89 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -159,6 +159,11 @@ namespace MediaBrowser.MediaEncoding.Probing } stream.ChannelLayout = ParseChannelLayout(streamInfo.channel_layout); + + if (streamInfo.bits_per_sample > 0) + { + stream.BitDepth = streamInfo.bits_per_sample; + } } else if (string.Equals(streamInfo.codec_type, "subtitle", StringComparison.OrdinalIgnoreCase)) { @@ -177,7 +182,10 @@ namespace MediaBrowser.MediaEncoding.Probing stream.AverageFrameRate = GetFrameRate(streamInfo.avg_frame_rate); stream.RealFrameRate = GetFrameRate(streamInfo.r_frame_rate); - stream.BitDepth = GetBitDepth(stream.PixelFormat); + if (streamInfo.bits_per_sample > 0) + { + stream.BitDepth = streamInfo.bits_per_sample; + } //stream.IsAnamorphic = string.Equals(streamInfo.sample_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase) || // string.Equals(stream.AspectRatio, "2.35:1", StringComparison.OrdinalIgnoreCase) || @@ -236,34 +244,6 @@ namespace MediaBrowser.MediaEncoding.Probing return stream; } - private int? GetBitDepth(string pixelFormat) - { - var eightBit = new List - { - "yuv420p", - "yuv411p", - "yuvj420p", - "uyyvyy411", - "nv12", - "nv21", - "rgb444le", - "rgb444be", - "bgr444le", - "bgr444be", - "yuvj411p" - }; - - if (!string.IsNullOrEmpty(pixelFormat)) - { - if (eightBit.Contains(pixelFormat, StringComparer.OrdinalIgnoreCase)) - { - return 8; - } - } - - return null; - } - /// /// Gets a string from an FFProbeResult tags dictionary /// -- cgit v1.2.3 From d59e4ff3577c95c372173cd68005abcc2baf217e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 27 Dec 2015 01:05:37 -0500 Subject: update bit depth probe --- MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs | 6 ++++++ MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 8 ++++++++ 2 files changed, 14 insertions(+) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs b/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs index 3e4bfe1a7..f32dd178f 100644 --- a/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs +++ b/MediaBrowser.MediaEncoding/Probing/InternalMediaInfoResult.cs @@ -144,6 +144,12 @@ namespace MediaBrowser.MediaEncoding.Probing /// The bits_per_sample. public int bits_per_sample { get; set; } + /// + /// Gets or sets the bits_per_raw_sample. + /// + /// The bits_per_raw_sample. + public int bits_per_raw_sample { get; set; } + /// /// Gets or sets the r_frame_rate. /// diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 7c3293b89..791dc0cf1 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -164,6 +164,10 @@ namespace MediaBrowser.MediaEncoding.Probing { stream.BitDepth = streamInfo.bits_per_sample; } + else if (streamInfo.bits_per_raw_sample > 0) + { + stream.BitDepth = streamInfo.bits_per_raw_sample; + } } else if (string.Equals(streamInfo.codec_type, "subtitle", StringComparison.OrdinalIgnoreCase)) { @@ -186,6 +190,10 @@ namespace MediaBrowser.MediaEncoding.Probing { stream.BitDepth = streamInfo.bits_per_sample; } + else if (streamInfo.bits_per_raw_sample > 0) + { + stream.BitDepth = streamInfo.bits_per_raw_sample; + } //stream.IsAnamorphic = string.Equals(streamInfo.sample_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase) || // string.Equals(stream.AspectRatio, "2.35:1", StringComparison.OrdinalIgnoreCase) || -- cgit v1.2.3 From ce59f19bc07eb73af133bfc2e8ee7e549d6d7566 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 5 Jan 2016 12:05:30 -0500 Subject: separate artists with semi-colon --- MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 791dc0cf1..d98efffe7 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -455,7 +455,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (!string.IsNullOrWhiteSpace(artists)) { - audio.Artists = SplitArtists(artists, new[] { '/' }, false) + audio.Artists = SplitArtists(artists, new[] { '/', ';' }, false) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } -- cgit v1.2.3 From 81fb823c024a6652d967bb818cb4fe83417132c4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 11 Jan 2016 11:52:22 -0500 Subject: record mediastream comment --- .../MediaEncoding/IMediaEncoder.cs | 3 +- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 14 +++++----- .../Probing/ProbeResultNormalizer.cs | 1 + MediaBrowser.Model/Entities/MediaStream.cs | 6 ++++ .../MediaInfo/AudioImageProvider.cs | 29 ++++++++++++++------ .../Persistence/MediaStreamColumns.cs | 32 ++++++++++++++++++++++ .../Persistence/SqliteItemRepository.cs | 11 ++++++-- 7 files changed, 78 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs') diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 427af6f6d..76ef054de 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -35,9 +35,10 @@ namespace MediaBrowser.Controller.MediaEncoding /// Extracts the audio image. /// /// The path. + /// Index of the image stream. /// The cancellation token. /// Task{Stream}. - Task ExtractAudioImage(string path, CancellationToken cancellationToken); + Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken); /// /// Extracts the video image. diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index f436ca3a0..3c6a99c65 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -472,18 +472,18 @@ namespace MediaBrowser.MediaEncoding.Encoder /// protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - public Task ExtractAudioImage(string path, CancellationToken cancellationToken) + public Task ExtractAudioImage(string path, int? imageStreamIndex, CancellationToken cancellationToken) { - return ExtractImage(new[] { path }, MediaProtocol.File, true, null, null, cancellationToken); + return ExtractImage(new[] { path }, imageStreamIndex, MediaProtocol.File, true, null, null, cancellationToken); } public Task ExtractVideoImage(string[] inputFiles, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { - return ExtractImage(inputFiles, protocol, false, threedFormat, offset, cancellationToken); + return ExtractImage(inputFiles, null, protocol, false, threedFormat, offset, cancellationToken); } - private async Task ExtractImage(string[] inputFiles, MediaProtocol protocol, bool isAudio, + private async Task ExtractImage(string[] inputFiles, int? imageStreamIndex, MediaProtocol protocol, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, CancellationToken cancellationToken) { var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool; @@ -494,7 +494,7 @@ namespace MediaBrowser.MediaEncoding.Encoder { try { - return await ExtractImageInternal(inputArgument, protocol, threedFormat, offset, true, resourcePool, cancellationToken).ConfigureAwait(false); + return await ExtractImageInternal(inputArgument, imageStreamIndex, protocol, threedFormat, offset, true, resourcePool, cancellationToken).ConfigureAwait(false); } catch (ArgumentException) { @@ -506,10 +506,10 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - return await ExtractImageInternal(inputArgument, protocol, threedFormat, offset, false, resourcePool, cancellationToken).ConfigureAwait(false); + return await ExtractImageInternal(inputArgument, imageStreamIndex, protocol, threedFormat, offset, false, resourcePool, cancellationToken).ConfigureAwait(false); } - private async Task ExtractImageInternal(string inputPath, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, SemaphoreSlim resourcePool, CancellationToken cancellationToken) + private async Task ExtractImageInternal(string inputPath, int? imageStreamIndex, MediaProtocol protocol, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, SemaphoreSlim resourcePool, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(inputPath)) { diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index d98efffe7..1df8896d5 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -141,6 +141,7 @@ namespace MediaBrowser.MediaEncoding.Probing if (streamInfo.tags != null) { stream.Language = GetDictionaryValue(streamInfo.tags, "language"); + stream.Comment = GetDictionaryValue(streamInfo.tags, "comment"); } if (string.Equals(streamInfo.codec_type, "audio", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index d089f0aa9..7f4cc2f84 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -30,6 +30,12 @@ namespace MediaBrowser.Model.Entities /// The language. public string Language { get; set; } + /// + /// Gets or sets the comment. + /// + /// The comment. + public string Comment { get; set; } + /// /// Gets or sets a value indicating whether this instance is interlaced. /// diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index 8884412d2..c98a67bbd 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using System; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -43,20 +44,27 @@ namespace MediaBrowser.Providers.MediaInfo { var audio = (Audio)item; + var imageStreams = + audio.GetMediaSources(false) + .Take(1) + .SelectMany(i => i.MediaStreams) + .Where(i => i.Type == MediaStreamType.EmbeddedImage) + .ToList(); + // Can't extract if we didn't find a video stream in the file - if (!audio.GetMediaSources(false).Take(1).SelectMany(i => i.MediaStreams).Any(i => i.Type == MediaStreamType.EmbeddedImage)) + if (imageStreams.Count == 0) { return Task.FromResult(new DynamicImageResponse { HasImage = false }); } - return GetImage((Audio)item, cancellationToken); + return GetImage((Audio)item, imageStreams, cancellationToken); } - public async Task GetImage(Audio item, CancellationToken cancellationToken) + public async Task GetImage(Audio item, List imageStreams, CancellationToken cancellationToken) { var path = GetAudioImagePath(item); - if (!_fileSystem.FileExists(path)) + if (!_fileSystem.FileExists(path)) { var semaphore = GetLock(path); @@ -66,11 +74,16 @@ namespace MediaBrowser.Providers.MediaInfo try { // Check again in case it was saved while waiting for the lock - if (!_fileSystem.FileExists(path)) + if (!_fileSystem.FileExists(path)) { - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + + var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1); + + var imageStreamIndex = imageStream == null ? (int?)null : imageStream.Index; - using (var stream = await _mediaEncoder.ExtractAudioImage(item.Path, cancellationToken).ConfigureAwait(false)) + using (var stream = await _mediaEncoder.ExtractAudioImage(item.Path, imageStreamIndex, cancellationToken).ConfigureAwait(false)) { using (var fileStream = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, true)) { diff --git a/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs b/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs index c983dd547..7e46db5a7 100644 --- a/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs +++ b/MediaBrowser.Server.Implementations/Persistence/MediaStreamColumns.cs @@ -28,6 +28,38 @@ namespace MediaBrowser.Server.Implementations.Persistence AddKeyFramesColumn(); AddRefFramesCommand(); AddCodecTagColumn(); + AddCommentColumn(); + } + + private void AddCommentColumn() + { + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "PRAGMA table_info(mediastreams)"; + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) + { + while (reader.Read()) + { + if (!reader.IsDBNull(1)) + { + var name = reader.GetString(1); + + if (string.Equals(name, "Comment", StringComparison.OrdinalIgnoreCase)) + { + return; + } + } + } + } + } + + var builder = new StringBuilder(); + + builder.AppendLine("alter table mediastreams"); + builder.AppendLine("add column Comment TEXT"); + + _connection.RunQueries(new[] { builder.ToString() }, _logger); } private void AddCodecTagColumn() diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 1d3ac293e..3d5ddcf49 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -127,7 +127,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false); var createMediaStreamsTableCommand - = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; + = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, Comment TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))"; string[] queries = { @@ -385,7 +385,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsAnamorphic", "RefFrames", "IsCabac", - "CodecTag" + "CodecTag", + "Comment" }; /// @@ -2683,6 +2684,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveStreamCommand.GetParameter(index++).Value = stream.IsCabac; _saveStreamCommand.GetParameter(index++).Value = stream.CodecTag; + _saveStreamCommand.GetParameter(index++).Value = stream.Comment; _saveStreamCommand.Transaction = transaction; _saveStreamCommand.ExecuteNonQuery(); @@ -2841,6 +2843,11 @@ namespace MediaBrowser.Server.Implementations.Persistence item.CodecTag = reader.GetString(26); } + if (!reader.IsDBNull(27)) + { + item.Comment = reader.GetString(27); + } + return item; } -- cgit v1.2.3