Пример #1
0
            public static VideoQuality ClassifyVideo(MediaInfo video)
            {
                if (CompareVideo(video, p1080))
                    return VideoQuality.p1080;
                if (CompareVideo(video, p720))
                    return VideoQuality.p720;
                if (CompareVideo(video, p480))
                    return VideoQuality.p480;

                return VideoQuality.p360;
            }
Пример #2
0
 /// <summary>
 /// Returns: 
 /// true: m1 better or equal m2,
 /// false: m1 worse than m2
 /// </summary>
 /// <param name="m1"></param>
 /// <param name="m2"></param>
 /// <returns></returns>
 public static bool CompareVideo(MediaInfo m1, MediaInfo m2)
 {
     if (m1.Video.Bitrate < m2.Video.Bitrate || m1.Video.Resolution.Heigth < m2.Video.Resolution.Heigth)
         return false;
     else
         return true;
 }
Пример #3
0
        //todo: test - func may not finish when converting is in progress
        public MediaInfo GetMediaInfo(string path)
        {
            var param = String.Format(" -show_streams -print_format json \"{0}\" ", path);
            var mediaInfo = new MediaInfo();

            try
            {
                var info = RunCommand(param);
                dynamic data = Json.Decode(info);

                foreach (var stream in data.streams)
                {

                    if (stream.codec_type == "audio")
                        mediaInfo.Audio.HasAudio = true;

                    if (stream.codec_type == "video")
                    {
                        mediaInfo.Video.HasVideo = true;
                        mediaInfo.Video.Bitrate = int.Parse(stream.bit_rate)/1000;
                        mediaInfo.Video.Duration = Convert.ToDouble((string) stream.duration,
                            CultureInfo.InvariantCulture);
                        mediaInfo.Video.Resolution.Width = stream.width;
                        mediaInfo.Video.Resolution.Heigth = stream.height;

                    }
                }
            }
            catch (Exception)
            {
                return mediaInfo;
            }
            return mediaInfo;
        }