Example #1
0
        public void StartInfo()
        {
            try
            {
                using (var mediaInfo = new MediaInfo.DotNetWrapper.MediaInfo())
                {
                    var text = "\r\n已检测到安装的MediaInfo \r\n";
                    text += mediaInfo.Option("Info_Version");

                    //Information about MediaInfo
                    //text += "\r\n\r\nInfo_Parameters\r\n";
                    //text += mediaInfo.Option("Info_Parameters");

                    //text += "\r\n\r\nInfo_Capacities\r\n";
                    //text += mediaInfo.Option("Info_Capacities");

                    //text += "\r\n\r\nInfo_Codecs\r\n";
                    //text += mediaInfo.Option("Info_Codecs");

                    SetrichTextBox1(text);
                }
            }
            catch (Exception ex)
            {
                m_ready = false;
                string msg = "请安装MediaInfo 64位";
                SetrichTextBox1(msg);
                MessageBox.Show(msg);
            }
        }
Example #2
0
        public void GetInfo(string file)
        {
            string mainbasefile = basepath + "MB\\1.txt";
            string mbstring     = System.IO.File.ReadAllText(mainbasefile, Encoding.UTF8);

            if (!m_ready)
            {
                string msg = "程序没有正确初始化 err 001";
                SetrichTextBox1(msg);
                MessageBox.Show(msg);
                return;
            }
            string name = System.IO.Path.GetFileNameWithoutExtension(file);
            string type = System.IO.Path.GetExtension(file);

            type = type.ToLower();
            switch (type)
            {
            case ".mkv":
            case ".mp4":
            case ".flv":
                try
                {
                    using (var mediaInfo = new MediaInfo.DotNetWrapper.MediaInfo())
                    {
                        string text = "";
                        text += "\r\n\r\nOpen\r\n";
                        mediaInfo.Open(file);

                        //text += "\r\n\r\nInform with Complete=false\r\n";
                        //mediaInfo.Option("Complete");
                        //text += mediaInfo.Inform();

                        string sss = mediaInfo.Inform();

                        var fistinfp = GetKeyValues(sss);
                        //编码时间
                        string reeeeddd     = fistinfp.FirstOrDefault(T => T.key == "Encoded date").value;
                        var    RELEASE_DATE = reeeeddd.Split(' ')[1];
                        mbstring = mbstring.Replace("{RELEASE DATE}", RELEASE_DATE);

                        //文件大小
                        var RELEASE_SiZE = fistinfp.FirstOrDefault(T => T.key == "File size").value;
                        mbstring = mbstring = mbstring.Replace("{RELEASE SiZE}", RELEASE_SiZE);

                        //播放时间
                        //var RUNTiME = fistinfp.FirstOrDefault(T => T.key == "Duration").value;
                        //mbstring = mbstring.Replace("{RUNTiME}", RUNTiME);

                        //色深
                        var Bit_depth = fistinfp.FirstOrDefault(T => T.key == "Bit depth").value;
                        mbstring = mbstring.Replace("{BIT DEPTH}", Bit_depth);

                        //编码
                        var ViDEO_CODEC = fistinfp.FirstOrDefault(T => T.key == "Format profile").value;

                        var Bit_rate = fistinfp.FirstOrDefault(T => T.key == "Bit rate").value;

                        Bit_rate = Bit_rate.Replace("kb/s", "Kbps");
                        Bit_rate = Bit_rate.Replace("mb/s", "Mbps");
                        mbstring = mbstring.Replace("{Bit_rate}", Bit_rate);


                        //高宽
                        var Width = fistinfp.FirstOrDefault(T => T.key == "Width").value.Replace(" pixels", "");
                        Width = Width.Replace(" ", "");
                        var Height = fistinfp.FirstOrDefault(T => T.key == "Height").value.Replace(" pixels", "");
                        Height = Height.Replace(" ", "");
                        //像素比
                        var RESOLUTiON = Width + " x " + Height;
                        mbstring = mbstring.Replace("{RESOLUTiON}", RESOLUTiON);

                        //高宽比
                        var DiSPLAY_ASPECT_RATiO = fistinfp.FirstOrDefault(T => T.key == "Display aspect ratio").value;
                        mbstring = mbstring.Replace("{DiSPLAY ASPECT RATiO}", DiSPLAY_ASPECT_RATiO);

                        //fps
                        var FRAME_RATE = fistinfp.FirstOrDefault(T => T.key == "Frame rate").value;
                        mbstring = mbstring.Replace("{FRAME RATE}", FRAME_RATE);



                        mediaInfo.Option("Complete", "1");
                        var s2        = mediaInfo.Inform();
                        var fistinfp2 = GetKeyValues(s2);


                        var Encoded_Library_Name = fistinfp2.FirstOrDefault(T => T.key == "Encoded_Library_Name").value;
                        var Format_profile       = fistinfp2.FirstOrDefault(T => T.key == "Format profile").value;
                        Format_profile += "";


                        //string Encoded_Library_Name = mediaInfo.Get(StreamKind.Video,0, "Encoded_Library_Name");

                        //string Format_profile = mediaInfo.Get(StreamKind.Video, 0, "Format profile",InfoKind.Name);
                        //Format_profile += " Tier";

                        //string Frame_rate = mediaInfo.Get(StreamKind.Video, 0, "Frame rate", InfoKind.Name);
                        //text += "\r\n\r\nInform with Complete=true\r\n";
                        //mediaInfo.Option("Complete", "1");
                        //text += mediaInfo.Inform();

                        //text += "\r\n\r\nCustom Inform\r\n";
                        //mediaInfo.Option("Inform", "General;File size is %FileSize% bytes");
                        //text += mediaInfo.Inform();

                        //foreach (string param in new[] { "BitRate", "BitRate/String", "BitRate_Mode" })
                        //{
                        //    text += "\r\n\r\nGet with Stream=Audio and Parameter='" + param + "'\r\n";
                        //    text += mediaInfo.Get(StreamKind.Audio, 0, param);
                        //}

                        //text += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
                        //text += mediaInfo.Get(StreamKind.General, 0, 46);

                        //text += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
                        //text += mediaInfo.CountGet(StreamKind.Audio);

                        //text += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
                        //text += mediaInfo.Get(StreamKind.General, 0, "AudioCount");

                        //text += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
                        //text += mediaInfo.Get(StreamKind.Audio, 0, "StreamCount");
                        SetrichTextBox1(text);
                    }



                    //ffmpeg部分
                    var ffProbe   = new NReco.VideoInfo.FFProbe();
                    var videoInfo = ffProbe.GetMediaInfo(file);



                    //播放时间
                    string sj = ToReadableString(videoInfo.Duration);
                    mbstring = mbstring.Replace("{RUNTiME}", sj);



                    richTextBox2.Text = "";
                    richTextBox2.Text = mbstring;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误 请将输出提供给开发人员");
                    SetrichTextBox1(ex.ToString());
                }
                break;

            default:
                string msg = "不支持文件格式";
                SetrichTextBox1(msg);
                MessageBox.Show(msg);
                break;
            }
        }
        // ================ Пробная программа - не используется ==================
        static void DocumentInputMain(string[] args)
        {
            string path = @"D:\Home\data\";

            Console.WriteLine("Start DocumentInput");
            //string fname = path + "WP_20170528_006.jpg";
            string fname  = path + "pharris1.tiff";
            Stream stream = File.OpenRead(fname);

            //ExifInfo(stream);

            using (var original = FreeImageBitmap.FromStream(stream))
            {
                Console.WriteLine($"Width={original.Width} Height={original.Height} ImageFormat={original.ImageFormat} {original.ToString()}");
                foreach (var m in original.Metadata)
                {
                    Console.WriteLine($"{m}");
                }
                int    x = original.Width, y = original.Height;
                double factor  = 150.0 / (x > y ? (double)x : (double)y);
                int    width   = (int)(factor * x);
                int    height  = (int)(factor * y);
                var    resized = new FreeImageBitmap(original, width, height);
                // JPEG_QUALITYGOOD is 75 JPEG.
                // JPEG_BASELINE strips metadata (EXIF, etc.)
                resized.Save(path + "out.jpg", FREE_IMAGE_FORMAT.FIF_JPEG,
                             FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD |
                             FREE_IMAGE_SAVE_FLAGS.JPEG_BASELINE);
            }
            //stream.Position = 0L;
            //Console.WriteLine($"ExifDate={ExifDate(stream)}");
            //Console.WriteLine($"ExifDate={ExifDate(fname)}");
            using (var image = new Bitmap(fname))
            {
                Console.WriteLine($"Width={image.Width} Height={image.Height}");
                foreach (var prop in image.PropertyItems)
                {
                    Console.WriteLine($"{prop.Id} {prop.Len} {prop.Type} {prop.Value} ");
                }
            }

            string text = "";

            // Используем пакет MesiaInfo.DotNetWrapper
            using (MediaInfo.DotNetWrapper.MediaInfo mediaInfo = new MediaInfo.DotNetWrapper.MediaInfo())
            {
                text += "\r\n\r\nOpen\r\n";
                mediaInfo.Open(fname);

                text += "\r\n\r\nInform with Complete=false\r\n";
                mediaInfo.Option("Complete");
                text += mediaInfo.Inform();

                text += "\r\n\r\nInform with Complete=true\r\n";
                mediaInfo.Option("Complete", "1");
                text += mediaInfo.Inform();

                text += "\r\n\r\nCustom Inform\r\n";
                mediaInfo.Option("Inform", "General;File size is %FileSize% bytes");
                text += mediaInfo.Inform();

                //foreach (string param in new[] { "BitRate", "BitRate/String", "BitRate_Mode" })
                //{
                //    text += "\r\n\r\nGet with Stream=Audio and Parameter='" + param + "'\r\n";
                //    text += mediaInfo.Get(StreamKind.Audio, 0, param);
                //}

                //text += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
                //text += mediaInfo.Get(StreamKind.General, 0, 46);

                //text += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
                //text += mediaInfo.CountGet(StreamKind.Audio);

                //text += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
                //text += mediaInfo.Get(StreamKind.General, 0, "AudioCount");

                //text += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
                //text += mediaInfo.Get(StreamKind.Audio, 0, "StreamCount");
            }

            Console.WriteLine(text);
        }