Exemplo n.º 1
0
        public Resolution CalculateSize(TranscoderProfile profile, MediaSource source, WebMediaInfo info = null)
        {
            try
            {
                if (!profile.HasVideoStream)
                    return new Resolution(0, 0);

                if (info == null)
                {
                    info = MediaInfoHelper.LoadMediaInfoOrSurrogate(source);
                }

                if (info.VideoStreams.Count > 0)
                {
                    return Resolution.Calculate(info.VideoStreams.First().DisplayAspectRatio, profile.MaxOutputWidth, profile.MaxOutputHeight, 2);
                }
            }
            catch (Exception ex)
            {
                Log.Warn("Failed to calculate size of output stream", ex);
            }

            // default
            return Resolution.Calculate(MediaInfoHelper.DEFAULT_ASPECT_RATIO, profile.MaxOutputWidth, profile.MaxOutputHeight, 2);
        }
Exemplo n.º 2
0
        public static string GetShortQualityName(WebMediaInfo info)
        {
            WebVideoStream vidStream = info.VideoStreams.First();

            if (vidStream.Width >= 1920 || vidStream.Height >= 1080)
                return "1080p";
            if (vidStream.Width >= 1280 || vidStream.Height >= 720)
                return "720p";
            return "SD";
        }
Exemplo n.º 3
0
 private static string GetFullInfoString(WebMediaInfo info, long fileSize)
 {
     int index = 0;
     double realSize = fileSize;
     while(realSize > 1024)
     {
         index++;
         realSize /= 1024;
     }
     return String.Format("{0}, {1:#.#} {2}", GetShortQualityName(info), realSize, units[index]);
 }
Exemplo n.º 4
0
        public static string GetShortQualityName(WebMediaInfo info)
        {
            if (!info.VideoStreams.Any())
                return UIStrings.Unknown;

            WebVideoStream vidStream = info.VideoStreams.First();

            if (vidStream.Width >= 1920 || vidStream.Height >= 1080)
                return vidStream.Interlaced ? "1080i" : "1080p";
            if (vidStream.Width >= 1280 || vidStream.Height >= 720)
                return vidStream.Interlaced ? "720i" : "720p";
            return "SD";
        }
Exemplo n.º 5
0
        public static decimal DEFAULT_ASPECT_RATIO = (decimal)16 / 9; // most new material is 16:9 these days

        #endregion Fields

        #region Methods

        public static WebMediaInfo LoadMediaInfoOrSurrogate(MediaSource source)
        {
            WebMediaInfo info;
            try
            {
                info = MediaInfoWrapper.GetMediaInfo(source);
                if (info != null)
                {
                    return info;
                }
            }
            catch (Exception ex)
            {
                Log.Warn(String.Format("Failed to load MediaInfo for {0}", source.GetDebugName()), ex);
            }

            WebMediaInfo surr = new WebMediaInfo();
            surr.Duration = 0;
            surr.SubtitleStreams = new List<WebSubtitleStream>();
            surr.AudioStreams = new List<WebAudioStream>()
            {
                new WebAudioStream()
                {
                    Channels = 2,
                    Codec = "Unknown",
                    ID = 1,
                    Index = 0,
                    Language = "und", // yes, that's valid ISO 639 (I think)
                    LanguageFull = "Unknown",
                }
            };
            surr.VideoStreams = new List<WebVideoStream>()
            {
                new WebVideoStream()
                {
                    Codec = "Unknown",
                    DisplayAspectRatio = DEFAULT_ASPECT_RATIO,
                    DisplayAspectRatioString = "16:9",
                    ID = 2,
                    Index = 0,
                    Height = 1280, // gives this any problems?
                    Width = 720
                }
            };
            return surr;
        }
Exemplo n.º 6
0
        public Resolution CalculateSize(TranscoderProfile profile, MediaSource source, WebMediaInfo info = null)
        {
            if (!profile.HasVideoStream)
                return new Resolution(0, 0);

            decimal aspect = (decimal)16 / 9; // the default aspect ratio
            if (source.MediaType != WebStreamMediaType.TV && profile != null)
            {
                if (info == null)
                {
                    info = MediaInfoWrapper.GetMediaInfo(source);
                }

                if (info.VideoStreams.Count > 0)
                {
                    aspect = info.VideoStreams.First().DisplayAspectRatio;
                }
            }

            return Resolution.Calculate(aspect, profile.MaxOutputWidth, profile.MaxOutputHeight, 2);
        }
Exemplo n.º 7
0
        public static WebMediaInfo LoadMediaInfoOrSurrogate(MediaSource source)
        {
            WebMediaInfo info = MediaInfoWrapper.GetMediaInfo(source);
            if (info != null)
            {
                return info;
            }

            WebMediaInfo surr = new WebMediaInfo();
            surr.Duration = 0;
            surr.SubtitleStreams = new List<WebSubtitleStream>();
            surr.AudioStreams = new List<WebAudioStream>()
            {
                new WebAudioStream()
                {
                    Channels = 2,
                    Codec = "Unknown",
                    ID = 1,
                    Index = 0,
                    Language = "und", // yes, that's valid ISO 639 (I think)
                    LanguageFull = "Unknown",
                }
            };
            surr.VideoStreams = new List<WebVideoStream>()
            {
                new WebVideoStream()
                {
                    Codec = "Unknown",
                    DisplayAspectRatio = 16 / 9, // this class is primarily used for TV data and that's mostly 16:9 these days afaik
                    DisplayAspectRatioString = "16:9",
                    ID = 2,
                    Index = 0,
                    Height = 1280, // gives this any problems?
                    Width = 720
                }
            };
            return surr;
        }
Exemplo n.º 8
0
 public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebRecordingFileInfo fileInfo)
 {
     return accessible ? GetFullInfoString(info, fileInfo) : UIStrings.FileInaccessible;
 }
Exemplo n.º 9
0
        private static WebMediaInfo DoLoadMediaInfo(string source, bool ignoreCache)
        {
            try
            {
                if (source == null || !File.Exists(source))
                {
                    Log.Warn("GetMediaInfo: File " + source + " doesn't exist or is not accessible");
                    return null;
                }

                // check cache
                if (!ignoreCache && Cache.ContainsKey(source))
                    return Cache[source];

                /* Loosely based upon MediaInfoWrapper.cs (mediaportal/Core/Player) from MediaPortal trunk r27491 as of 15 June 2011
                 *
                 * Using the whole wrapper from MediaPortal is quite much porting work as it's cluttered with calls to other MP code. Referencing
                 * MediaPortal.Core.dll also isn't an option as that pulls in a big tree of dependencies.
                 *
                 * TODO: Needs error handling
                 * TODO: No support for DVDs yet
                 * TODO: Aspect ratio doesn't work properly yet
                 */
                MediaInfo info = new MediaInfo();
                info.Option("ParseSpeed", "0.3");
                info.Open(source);
                WebMediaInfo retinfo = new WebMediaInfo();
                retinfo.Container = info.Get(StreamKind.General, 0, "Format");

                // video
                retinfo.VideoStreams = new List<WebVideoStream>();
                int videoStreams = info.Count_Get(StreamKind.Video);
                for (int i = 0; i < videoStreams; i++)
                {
                    retinfo.Duration = retinfo.Duration == 0 ? (long)StringToInt(info.Get(StreamKind.Video, i, "Duration")) : retinfo.Duration;

                    string val = info.Get(StreamKind.Video, i, "DisplayAspectRatio");
                    retinfo.VideoStreams.Add(new WebVideoStream()
                    {
                        Codec = info.Get(StreamKind.Video, i, "Codec/String"),
                        DisplayAspectRatio = StringToDecimal(info.Get(StreamKind.Video, i, "DisplayAspectRatio")),
                        DisplayAspectRatioString = info.Get(StreamKind.Video, i, "DisplayAspectRatio/String"),
                        Width = StringToInt(info.Get(StreamKind.Video, i, "Width")),
                        Height = StringToInt(info.Get(StreamKind.Video, i, "Height")),
                        ID = StringToInt(info.Get(StreamKind.Video, i, "ID")),
                        Index = i
                    });
                }

                // audio codecs
                retinfo.AudioStreams = new List<WebAudioStream>();
                int audioStreams = info.Count_Get(StreamKind.Audio);
                for (int i = 0; i < audioStreams; i++)
                {
                    retinfo.Duration = retinfo.Duration == 0 ? (long)StringToInt(info.Get(StreamKind.Audio, i, "Duration")) : retinfo.Duration;
                    retinfo.AudioStreams.Add(new WebAudioStream()
                    {
                        Channels = StringToInt(info.Get(StreamKind.Audio, i, "Channels")),
                        Codec = info.Get(StreamKind.Audio, i, "Codec/String"),
                        ID = StringToInt(info.Get(StreamKind.Audio, i, "ID")),
                        Language = info.Get(StreamKind.Audio, i, "Language"),
                        LanguageFull = info.Get(StreamKind.Audio, i, "Language/String"),
                        Title = info.Get(StreamKind.Audio, i, "Title"),
                        Index = i
                    });
                }

                // subtitle codecs
                retinfo.SubtitleStreams = new List<WebSubtitleStream>();
                int subtitleStreams = info.Count_Get(StreamKind.Text);
                int scodecnr = 0;
                for (scodecnr = 0; scodecnr < subtitleStreams; scodecnr++)
                {
                    retinfo.SubtitleStreams.Add(new WebSubtitleStream()
                    {
                        Language = info.Get(StreamKind.Text, scodecnr, "Language"),
                        LanguageFull = info.Get(StreamKind.Text, scodecnr, "Language/String"),
                        ID = StringToInt(info.Get(StreamKind.Text, scodecnr, "ID")),
                        Index = scodecnr,
                        Filename = null
                    });
                }

                // get max subtitle id
                var list = retinfo.SubtitleStreams.Select(x => x.ID);
                int lastId = list.Count() == 0 ? 0 : list.Max();

                // standard name of external subtitle files
                string subfile = Path.Combine(Path.GetDirectoryName(source), Path.GetFileNameWithoutExtension(source) + ".srt");
                if (File.Exists(subfile))
                {
                    retinfo.SubtitleStreams.Add(new WebSubtitleStream()
                    {
                        Language = "ext",
                        LanguageFull = "External subtitle file",
                        ID = ++lastId, // a file with so many streams seems quite unlikely to me
                        Index = ++scodecnr,
                        Filename = subfile
                    });
                }

                // language in subtitle filename
                var files = Directory.GetFiles(Path.GetDirectoryName(source), Path.GetFileNameWithoutExtension(source) + ".*.srt");
                foreach (var file in files)
                {
                    string basename = Path.GetFileName(file).Substring(Path.GetFileNameWithoutExtension(source).Length);
                    string tag = basename.Substring(1, basename.Length - 5);
                    retinfo.SubtitleStreams.Add(new WebSubtitleStream()
                    {
                        Language = LookupCountryCode(tag),
                        LanguageFull = tag,
                        ID = ++lastId,
                        Index = ++scodecnr,
                        Filename = file
                    });
                }

                // return
                info.Close();

                if (!Cache.ContainsKey(source))
                {
                    Cache.Add(source, retinfo);
                }
                else
                {
                    Cache[source] = retinfo;
                }

                return retinfo;
            }
            catch (Exception ex)
            {
                Log.Error("Error parsing MediaInfo for " + source, ex);
                return null;
            }
        }
Exemplo n.º 10
0
 public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebRecordingFileInfo fileInfo)
 {
     return GetFullInfoString(accessible, info, fileInfo.Size);
 }
Exemplo n.º 11
0
 public void Save(MediaSource src, WebMediaInfo info)
 {
     lock (cache)
     {
         cache[src.GetUniqueIdentifier()] = info;
     }
     isDirty = true;
 }
Exemplo n.º 12
0
 public static string GetFullInfoString(WebMediaInfo info, WebRecordingFileInfo fileInfo)
 {
     return GetFullInfoString(info, fileInfo.Size);
 }
Exemplo n.º 13
0
 public static string GetShortQualityName(bool accessible, WebMediaInfo info)
 {
     return accessible ? GetShortQualityName(info) : UIStrings.FileInaccessible;
 }
Exemplo n.º 14
0
 public static string GetFullInfoString(WebMediaInfo info, WebFileInfo fileInfo)
 {
     return GetFullInfoString(fileInfo.Exists, info, fileInfo.Size);
 }
Exemplo n.º 15
0
        private void LoadMediaInfo(WebMediaInfo info)
        {
            if (info == null)
            {
                Log("No MediaInfo available");
                return;
            }

            mInfo = info;
            Log(String.Format("MediaInfo: streams: {0} video, {1} audio, {2} subtitle",
                info.VideoStreams.Count, info.AudioStreams.Count, info.SubtitleStreams.Count));
            if (info.VideoStreams.Count() > 0)
            {
                WebVideoStream vid = info.VideoStreams.First();
                Log(String.Format("MediaInfo: video {0}x{1}; {2}; {3}", vid.Width, vid.Height, vid.DisplayAspectRatioString, vid.Codec));
            }

            // audio
            cbLanguage.Items.Clear();
            int i = 1;
            foreach (WebAudioStream audio in info.AudioStreams)
            {
                string name = "Audio stream #" + i++;
                if(!String.IsNullOrEmpty(audio.Language))
                    name += ": " + audio.Language;
                if(!String.IsNullOrEmpty(audio.Title))
                    name += ": " + audio.Title;
                cbLanguage.Items.Add(name);
            }

            // subtitle
            cbSubtitle.Items.Clear();
            i = 1;
            foreach (WebSubtitleStream stream in info.SubtitleStreams)
            {
                string name = "Subtitle stream #" + i++ + " (" + stream.ID + ")";
                if(!String.IsNullOrEmpty(stream.Language))
                    name += ": " + stream.Language;
                cbSubtitle.Items.Add(name);
            }
        }
Exemplo n.º 16
0
        public static WebMediaInfo GetMediaInfo(string source, bool ignoreCache)
        {
            try
            {
                if (source == null || !File.Exists(source))
                {
                    Log.Warn("GetMediaInfo: File " + source + " doesn't exist or is not accessible");
                    return null;
                }

                // check cache
                if (!ignoreCache && Cache.ContainsKey(source))
                    return Cache[source];

                /* Loosely based upon MediaInfoWrapper.cs (mediaportal/Core/Player) from MediaPortal trunk r27491 as of 15 June 2011
                 *
                 * Using the whole wrapper from MediaPortal is quite much porting work as it's cluttered with calls to other MP code. Referencing
                 * MediaPortal.Core.dll also isn't an option as that pulls in a big tree of dependencies.
                 *
                 * TODO: Needs error handling
                 * TODO: No support for DVDs yet
                 * TODO: Aspect ratio doesn't work properly yet
                 */
                MediaInfo info = new MediaInfo();
                info.Option("ParseSpeed", "0.3");
                info.Open(source);
                WebMediaInfo retinfo = new WebMediaInfo();

                // video
                retinfo.VideoStreams = new List<WebVideoStream>();
                int videoStreams = info.Count_Get(StreamKind.Video);
                for (int i = 0; i < videoStreams; i++)
                {
                    retinfo.Duration = retinfo.Duration == 0 ? (long)StringToInt(info.Get(StreamKind.Video, i, "Duration")) : retinfo.Duration;
                    retinfo.VideoStreams.Add(new WebVideoStream()
                    {
                        Codec = info.Get(StreamKind.Video, i, "Codec/String"),
                        DisplayAspectRatio = Decimal.Parse(info.Get(StreamKind.Video, i, "DisplayAspectRatio"), System.Globalization.CultureInfo.InvariantCulture),
                        DisplayAspectRatioString = info.Get(StreamKind.Video, i, "DisplayAspectRatio/String"),
                        Width = StringToInt(info.Get(StreamKind.Video, i, "Width")),
                        Height = StringToInt(info.Get(StreamKind.Video, i, "Height")),
                        ID = StringToInt(info.Get(StreamKind.Video, i, "ID")),
                        Index = i
                    });
                }

                // audio codecs
                retinfo.AudioStreams = new List<WebAudioStream>();
                int audioStreams = info.Count_Get(StreamKind.Audio);
                for (int i = 0; i < audioStreams; i++)
                {
                    retinfo.Duration = retinfo.Duration == 0 ? (long)StringToInt(info.Get(StreamKind.Audio, i, "Duration")) : retinfo.Duration;
                    retinfo.AudioStreams.Add(new WebAudioStream()
                    {
                        Channels = StringToInt(info.Get(StreamKind.Audio, i, "Channels")),
                        Codec = info.Get(StreamKind.Audio, i, "Codec/String"),
                        ID = StringToInt(info.Get(StreamKind.Audio, i, "ID")),
                        Language = info.Get(StreamKind.Audio, i, "Language"),
                        LanguageFull = info.Get(StreamKind.Audio, i, "Language/String"),
                        Title = info.Get(StreamKind.Audio, i, "Title"),
                        Index = i
                    });
                }

                // subtitle codecs
                retinfo.SubtitleStreams = new List<WebSubtitleStream>();
                int subtitleStreams = info.Count_Get(StreamKind.Text);
                int scodecnr = 0;
                for (scodecnr = 0; scodecnr < subtitleStreams; scodecnr++)
                {
                    retinfo.SubtitleStreams.Add(new WebSubtitleStream()
                    {
                        Language = info.Get(StreamKind.Text, scodecnr, "Language"),
                        LanguageFull = info.Get(StreamKind.Text, scodecnr, "Language/String"),
                        ID = StringToInt(info.Get(StreamKind.Text, scodecnr, "ID")),
                        Index = scodecnr,
                        Filename = null
                    });
                }

                // only support usual naming convention for external files for now
                string subfile = Path.Combine(Path.GetDirectoryName(source), Path.GetFileNameWithoutExtension(source) + ".srt");
                if (File.Exists(subfile))
                {
                    retinfo.SubtitleStreams.Add(new WebSubtitleStream()
                    {
                        Language = "ext",
                        LanguageFull = "External subtitle file",
                        ID = 500, // a file with so many streams seems quite unlikely to me
                        Index = ++scodecnr,
                        Filename = subfile
                    });
                }

                // return
                info.Close();

                if (!Cache.ContainsKey(source))
                {
                    Cache.Add(source, retinfo);
                }
                else
                {
                    Cache[source] = retinfo;
                }

                return retinfo;
            }
            catch (Exception ex)
            {
                Log.Error("Error parsing MediaInfo for " + source, ex);
                return null;
            }
        }
Exemplo n.º 17
0
 public VLCWrapperParsingUnit(Reference<WebTranscodingInfo> save, WebMediaInfo info, int position)
 {
     data = save;
     this.info = info;
     this.position = position;
 }
Exemplo n.º 18
0
 public CachedInfoWrapper(WebMediaInfo mediaInfo, WebFileInfo fileInfo)
 {
     CachedDate = DateTime.Now;
     Size = fileInfo.Size;
     Info = mediaInfo;
 }