Example #1
0
        private static void MuxM3U8(string OutFileName)
        {
            PrepareDirectory(new[] { "output" });
            Logger.Info("Using MKVMERGE to mux single TS file, chapters and subtitles to final MKV file");
            if (RunEXE("mkvmerge/mkvmerge.exe", "--output \"" + Path.Combine(EXEDirectory, "output", OutFileName.Replace("/", "-") + ".mkv") + "\" \"" + Path.Combine(EXEDirectory, "temp", ".ts") + "\" --default-track 0:false " + (File.Exists("temp/.chapters") ? "--chapters \"" + Path.Combine(EXEDirectory, "temp", ".chapters") + "\"" : string.Empty) + " " + (File.Exists("temp/.srt") ? "--sub-charset 0:UTF-8 \"" + Path.Combine(EXEDirectory, "temp", ".srt") + "\"" : string.Empty)) != 0)
            {
                return;
            }
            string mediaInfo = string.Empty;

            using (MediaInfo.DotNetWrapper.MediaInfo mi = new MediaInfo.DotNetWrapper.MediaInfo()) {
                mi.Open("output/" + OutFileName + ".mkv");
                mi.Option("Complete", "0");
                mediaInfo = mi.Inform().Replace("\r", string.Empty).TrimEnd();
            }
            Dictionary <string, string>[] mediaInfoBlocksSplit = mediaInfo.Split(new string[] { "\n\n" }, StringSplitOptions.RemoveEmptyEntries).Select(
                block => {
                return(block.Split('\n').Where(l => !l.StartsWith("Complete name ")).Select(
                           line => {
                    Match mc = Regex.Match(line, "^(((?!\\s{2}).)*)[^:]*: (.*)");
                    return new KeyValuePair <string, string>(mc.Groups[1].Value.Trim(), mc.Groups[3].Value.Trim());
                }
                           ).ToDictionary(x => x.Key, x => x.Value));
            }
                ).ToArray();
            Dictionary <string, string> mediaInfo_GENERAL = mediaInfoBlocksSplit[0];
            Dictionary <string, string> mediaInfo_VIDEO   = mediaInfoBlocksSplit[1];

            Dictionary <string, string>[] mediaInfo_AUDIOS = mediaInfoBlocksSplit.Where(block => block.Any(x => x.Key == "Channel(s)")).ToArray();
            Dictionary <string, string>[] mediaInfo_OTHER  = mediaInfoBlocksSplit.Skip(3).ToArray();
            File.Move("output/" + OutFileName + ".mkv", "output/" + OutFileName.Replace("[QUALITY]", string.Join(string.Empty, mediaInfo_VIDEO["Height"].Select(x => char.IsDigit(x) ? x.ToString() : string.Empty))).Replace("[CODEC]", mediaInfo_VIDEO.ContainsKey("Writing library") && mediaInfo_VIDEO["Writing library"].StartsWith("x264") ? "x264" : mediaInfo_VIDEO["Format"].Replace("AVC", "H.264")) + "-PRAGMA.mkv");

            // Cleanup files no longer needed
            // todo: setup files in such a way to be multi-threaded supported and not conflict with other downloads at same time
            File.Delete("temp/.ts");
            File.Delete("temp/.srt");
            File.Delete("temp/.chapters");
        }
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);
        }