Example #1
0
        public AboutBox()
        {
            InitializeComponent();
            Text = String.Format("About {0}", AssemblyTitle);
            labelProductName.Text = AssemblyProduct;
            labelVersion.Text     = String.Format("Version {0}", AssemblyVersion);
            labelCopyright.Text   = AssemblyCopyright;
            StringBuilder sbDesc = new StringBuilder();

            sbDesc.AppendLine(AssemblyDescription);
            sbDesc.AppendLine();
            sbDesc.AppendLine("Running from:");
            sbDesc.AppendLine(Application.StartupPath);
            sbDesc.AppendLine();
            sbDesc.AppendLine("Settings file:");
            sbDesc.AppendLine(App.SettingsFilePath);
            MediaInfoLib.MediaInfo mi = new MediaInfoLib.MediaInfo();
            sbDesc.AppendLine();
            sbDesc.AppendLine("External libraries:");
            sbDesc.AppendLine("ShareX: http://getsharex.com");
            sbDesc.AppendLine(mi.Option("Info_Version") + ": http://sourceforge.net/projects/mediainfo");
            textBoxDescription.Text = sbDesc.ToString();

            UpdateChecker updateChecker = ProgramUI.UpdateManager.CreateUpdateChecker();

            uclUpdate.CheckUpdate(updateChecker);
        }
Example #2
0
        public MediaInfo(string fileName)
        {
            info = new MediaInfoLib.MediaInfo();
            info.Open(fileName);

            var ms = info.Get(MediaInfoLib.StreamKind.General, 0, "Duration");
            Length = TimeSpan.FromMilliseconds(long.Parse(ms));
        }
Example #3
0
        public MediaInfo(Models.FileName file)
        {
            InitializeComponent();
            this.Text = file.Original;

            string result;

            if (IntPtr.Size == 4)
            {
                var MI = new MediaInfoLib.MediaInfo();

                MI.Open(file.FullPath());
                MI.Option("Complete");
                result = MI.Inform();
                MI.Close();
            }
            else
            {
                var MI = new MediaInfoLib.MediaInfo64();

                MI.Open(file.FullPath());
                MI.Option("Complete");
                result = MI.Inform();
                MI.Close();
            }

            var sp = result
                     .TrimEnd(new char[] { '\r', '\n' })
                     .Split(new string[] { "\r\n" }, StringSplitOptions.None);

            TreeNode root = null;

            foreach (var s in sp)
            {
                if (root == null)
                {
                    root = new TreeNode(s);
                    treeViewInfo.Nodes.Add(root);
                }
                else
                {
                    if (s == "")
                    {
                        root = null;
                    }
                    else
                    {
                        root.Nodes.Add(new TreeNode(Regex.Replace(s, "\\s{2,}", "")));
                    }
                }
            }

            treeViewInfo.ExpandAll();
        }
Example #4
0
        public static bool MediaInfoState(ref string errMsg)
        {
            if (!mediaInfoInitFlag)
            {
                mediaInfo = new MediaInfoLib.MediaInfo(
                    ref mediaInfoInitFlag, ref mediaInfoInitErrMsg);
            }

            errMsg = mediaInfoInitErrMsg;
            return(mediaInfoInitFlag);
        }
Example #5
0
        private void TrySetMediaInfo(string filePath)
        {
            try
            {
                MI = new MediaInfoLib.MediaInfo();

                #region Media Info Init
                FileStream From = new FileStream(filePath, FileMode.Open, FileAccess.Read);

                //From: preparing a memory buffer for reading
                byte[] From_Buffer = new byte[64 * 1024];
                int    From_Buffer_Size; //The size of the read file buffer

                //Preparing to fill MediaInfo with a buffer
                MI.Open_Buffer_Init(From.Length, 0);

                //The parsing loop
                do
                {
                    //Reading data somewhere, do what you want for this.
                    From_Buffer_Size = From.Read(From_Buffer, 0, 64 * 1024);

                    //Sending the buffer to MediaInfo
                    System.Runtime.InteropServices.GCHandle GC = System.Runtime.InteropServices.GCHandle.Alloc(From_Buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
                    IntPtr From_Buffer_IntPtr = GC.AddrOfPinnedObject();
                    Status Result             = (Status)MI.Open_Buffer_Continue(From_Buffer_IntPtr, (IntPtr)From_Buffer_Size);
                    GC.Free();
                    if ((Result & Status.Finalized) == Status.Finalized)
                    {
                        break;
                    }

                    //Testing if MediaInfo request to go elsewhere
                    if (MI.Open_Buffer_Continue_GoTo_Get() != -1)
                    {
                        Int64 Position = From.Seek(MI.Open_Buffer_Continue_GoTo_Get(), SeekOrigin.Begin); //Position the file
                        MI.Open_Buffer_Init(From.Length, Position);                                       //Informing MediaInfo we have seek
                    }
                }while (From_Buffer_Size > 0);

                //Finalizing
                MI.Open_Buffer_Finalize(); //This is the end of the stream, MediaInfo must finnish some work
                #endregion
            }
            catch (Exception ex)
            {
                var c = ex.Message;
            }
        }
Example #6
0
 public string of_GetTxtStr(string lsFile)
 {
     try
     {
         MediaInfoLib.MediaInfo m = new MediaInfoLib.MediaInfo();
         int k = m.Open(lsFile);
         if (k != 1)
         {
             return("Not Media File!");
         }
         return(m.Inform());
     }
     catch (Exception ex)
     { return(ex.Message + ex.StackTrace); }
 }
Example #7
0
        private static string ReadMediaInfo()
        {
            //Initilaizing MediaInfo
            MediaInfoLib.MediaInfo MI = new MediaInfoLib.MediaInfo();

            //From: preparing an example file for reading
            FileStream From = new FileStream(@"d:\temp\test.mp4", FileMode.Open, FileAccess.Read);

            //From: preparing a memory buffer for reading
            byte[] From_Buffer = new byte[64 * 1024];
            int    From_Buffer_Size; //The size of the read file buffer

            //Preparing to fill MediaInfo with a buffer
            MI.Open_Buffer_Init(From.Length, 0);

            //The parsing loop
            do
            {
                //Reading data somewhere, do what you want for this.
                From_Buffer_Size = From.Read(From_Buffer, 0, 64 * 1024);

                //Sending the buffer to MediaInfo
                System.Runtime.InteropServices.GCHandle GC = System.Runtime.InteropServices.GCHandle.Alloc(From_Buffer, System.Runtime.InteropServices.GCHandleType.Pinned);
                IntPtr From_Buffer_IntPtr = GC.AddrOfPinnedObject();
                Status Result             = (Status)MI.Open_Buffer_Continue(From_Buffer_IntPtr, (IntPtr)From_Buffer_Size);
                GC.Free();
                if ((Result & Status.Finalized) == Status.Finalized)
                {
                    break;
                }

                //Testing if MediaInfo request to go elsewhere
                if (MI.Open_Buffer_Continue_GoTo_Get() != -1)
                {
                    Int64 Position = From.Seek(MI.Open_Buffer_Continue_GoTo_Get(), SeekOrigin.Begin); //Position the file
                    MI.Open_Buffer_Init(From.Length, Position);                                       //Informing MediaInfo we have seek
                }
            }while (From_Buffer_Size > 0);

            //Finalizing
            MI.Open_Buffer_Finalize(); //This is the end of the stream, MediaInfo must finnish some work

            //Get() example
            return("Container format is " + MI.Get(MediaInfoLib.StreamKind.General, 0, "Format"));
        }
Example #8
0
        public ThreadScanDisk(string diskPath, string diskDescribe,
                              bool scanMediaInfo, int setScanLayer,
                              ThreadSacnDiskCallback threadCallback,
                              SqlData sqlData)
        {
            this.diskPath        = diskPath;
            this.diskDescribe    = diskDescribe;
            this.scanMediaInfo   = scanMediaInfo;
            this.setMaxScanLayer = setScanLayer;
            this.threadCallback  = threadCallback;
            this.sqlData         = sqlData;

            if (!mediaInfoInitFlag)
            {
                mediaInfo = new MediaInfoLib.MediaInfo(
                    ref mediaInfoInitFlag, ref mediaInfoInitErrMsg);
            }
        }
Example #9
0
 private void showMediaInformation(string filePath)
 {
     richTextBox_ImageProperties.AppendLine(filePath);
     try
     {
         MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo();
         if (mediaInfo.Open(filePath) == 1)
         {
             mediaInfo.Option("Complete", "1");
             richTextBox_ImageProperties.AppendLine(CultureStrings.ColonMediaInformation);
             richTextBox_ImageProperties.AppendLine(mediaInfo.Inform());
         }
         mediaInfo.Close();
     }
     catch (System.Exception ex)
     {
         logException(ex);
     }
 }
Example #10
0
        private string buildUniqueDestinationFilePath(ThreadParameters parameters, string sourcePath)
        {
            MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo();
            string taggedDate = null;

            if (mediaInfo.Open(sourcePath) == 1)
            {
                taggedDate = mediaInfo.Get(MediaInfoLib.StreamKind.General, 0, CultureStrings.TextTaggedDate);
            }
            mediaInfo.Close();
            string uniqueDestinationFilePath = null;

            if (taggedDate != null && taggedDate.Length > 0)
            {
                try
                {
                    System.DateTime dateTime = parseTaggedDate(taggedDate);
                    uniqueDestinationFilePath = normalizeDirectoryPath(parameters.DestinationRootDirectory) + normalizeDirectoryPath(System.IO.Path.GetExtension(sourcePath).ToUpper().Substring(1)) + normalizeDirectoryPath(dateTime.ToString("yyyy")) + normalizeDirectoryPath(dateTime.ToString("MMMM")) + getCollectPhotoOriginalFileName(sourcePath);
                }
                catch (System.Exception ex)
                {
                    logException(ex);
                }
            }
            if (uniqueDestinationFilePath == null)
            {
                uniqueDestinationFilePath = normalizeDirectoryPath(parameters.DestinationRootDirectory) + normalizeDirectoryPath(System.IO.Path.GetExtension(sourcePath).ToUpper().Substring(1)) + getCollectPhotoOriginalFileName(sourcePath);
            }
            if (getDuplicateAutoRenamedFile(sourcePath, uniqueDestinationFilePath) != null)
            {
                return(getDuplicateAutoRenamedFile(sourcePath, uniqueDestinationFilePath));
            }
            else
            {
                return(getUnusedFilePath(uniqueDestinationFilePath));
            }
        }
Example #11
0
        public AboutBox()
        {
            InitializeComponent();
            Text = String.Format("About {0}", AssemblyTitle);
            labelProductName.Text = AssemblyProduct;
            labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
            labelCopyright.Text = AssemblyCopyright;
            StringBuilder sbDesc = new StringBuilder();
            sbDesc.AppendLine(AssemblyDescription);
            sbDesc.AppendLine();
            sbDesc.AppendLine("Running from:");
            sbDesc.AppendLine(Application.StartupPath);
            sbDesc.AppendLine();
            sbDesc.AppendLine("Settings file:");
            sbDesc.AppendLine(App.SettingsFilePath);
            MediaInfoLib.MediaInfo mi = new MediaInfoLib.MediaInfo();
            sbDesc.AppendLine();
            sbDesc.AppendLine("External libraries:");
            sbDesc.AppendLine("ShareX: http://getsharex.com");
            sbDesc.AppendLine(mi.Option("Info_Version") + ": http://sourceforge.net/projects/mediainfo");
            textBoxDescription.Text = sbDesc.ToString();

            uclUpdate.CheckUpdate(CheckUpdate);
        }
Example #12
0
 private void GetScrin()
 {
     Progress(1);
     ProgressVisibl(true);
     this.files_a_scrinTableAdapter.Fill(this.anime_ArchiveDataSet.files_a_scrin);
     DataTable dt = files_a_scrinTableAdapter.GetData();
     int count = dt.Rows.Count * 15 + 3;
     int p = 0;
     for (int j = 0; j < dt.Rows.Count; j++)
     {
         try
         {
             FFMpegConverter ffMpeg = new FFMpegConverter();
             MediaInfoLib.MediaInfo mi = new MediaInfoLib.MediaInfo();
             MediaInfoDotNet.MediaFile m = new MediaFile(dt.Rows[j]["Path_s"].ToString());
             List<Image> images = new List<Image>();
             TimeSpan ts = TimeSpan.FromMilliseconds(m.duration);
             int col = 15;
             int period = Convert.ToInt32(ts.TotalSeconds) / col;
             int w = 0, h = 0, column = 3;
             for (int i = 1; i <= col; i++)
             {
                 p++;
                 Progress((p * 100) / count);
                 MemoryStream ms = new MemoryStream();
                 Image image;
                 ffMpeg.GetVideoThumbnail(dt.Rows[j]["Path_s"].ToString(), ms, i * period);
                 if (ms.Length == 0)
                     continue;
                 image = Image.FromStream(ms);
                 w = image.Width;
                 h = image.Height;
                 //pictureBox1.Image = image;
                 images.Add(image);
             }
             Image mm = Draw(images, w, h, column);
             mm = ResizeImg(mm, 30);
             MemoryStream mem = new MemoryStream();
             mm.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
             files_a_scrinTableAdapter.Update(ReadBytesFromImage(mem), Convert.ToInt32(dt.Rows[j]["kod_files"]));
         }
         catch (Exception ex)
         {
             continue;
         }
     }
     Progress(100);
     ProgressVisibl(false);
 }
Example #13
0
        internal static void Check(Media media)
        {
            if (media.MediaType == TMediaType.Movie || media.MediaType == TMediaType.Unknown)
            {
                TimeSpan videoDuration;
                TimeSpan audioDuration;
                int startTickCunt = Environment.TickCount;
                using (FFMpegWrapper ffmpeg = new FFMpegWrapper(media.FullPath))
                {
                    videoDuration = ffmpeg.GetFrameCount().SMPTEFramesToTimeSpan();
                    audioDuration = (TimeSpan)ffmpeg.GetAudioDuration();
                    if (videoDuration == TimeSpan.Zero)
                    {
                        MediaInfoLib.MediaInfo mi = new MediaInfoLib.MediaInfo();
                        try
                        {
                            mi.Open(media.FullPath);
                            long frameCount;
                            if (long.TryParse(mi.Get(MediaInfoLib.StreamKind.Video, 0, "FrameCount"), out frameCount))
                                videoDuration = frameCount.SMPTEFramesToTimeSpan();
                            long audioMilliseconds;
                            if (long.TryParse(mi.Get(MediaInfoLib.StreamKind.Audio, 0, "Duration"), out audioMilliseconds))
                                audioDuration = TimeSpan.FromMilliseconds(audioMilliseconds);
                            //mi.Option("Complete");
                            //Debug.WriteLine(mi.Inform());
                        }
                        finally
                        {
                            mi.Close();
                        }
                    }

                    media.Duration = videoDuration;
                    if (media.DurationPlay == TimeSpan.Zero || media.DurationPlay > videoDuration)
                        media.DurationPlay = videoDuration;
                    int w = ffmpeg.GetWidth();
                    int h = ffmpeg.GetHeight();
                    FieldOrder order = ffmpeg.GetFieldOrder();
                    Rational frameRate = ffmpeg.GetFrameRate();
                    Rational sar = ffmpeg.GetSAR();
                    if (h == 608 && w == 720)
                    {
                        media.HasExtraLines = true;
                        h = 576;
                    }
                    else
                        media.HasExtraLines = false;

                    RationalNumber sAR = ((sar.Num == 608 && sar.Den == 405) || (sar.Num == 1 && sar.Den == 1)) ? VideoFormatDescription.Descriptions[TVideoFormat.PAL_FHA].SAR
                        : (sar.Num == 152 && sar.Den == 135) ? VideoFormatDescription.Descriptions[TVideoFormat.PAL].SAR
                        : new RationalNumber(sar.Num, sar.Den);

                    var vfd = VideoFormatDescription.Match(new System.Drawing.Size(w, h), new RationalNumber(frameRate.Num, frameRate.Den), sAR, order != FieldOrder.PROGRESSIVE);
                    media.VideoFormat = vfd.Format;
                    media.VideoFormatDescription = vfd;

                    if (videoDuration > TimeSpan.Zero)
                    {
                        media.MediaType = TMediaType.Movie;
                        if (Math.Abs(videoDuration.Ticks - audioDuration.Ticks) >= TimeSpan.TicksPerSecond / 2
                            && audioDuration != TimeSpan.Zero)
                            // when more than 0.5 sec difference
                            media.MediaStatus = TMediaStatus.ValidationError;
                        else
                            media.MediaStatus = TMediaStatus.Available;
                    }
                    else
                        media.MediaStatus = TMediaStatus.ValidationError;
                }
                Debug.WriteLine("Check of {0} finished with status {1}. It took {2} milliseconds", media.FullPath, media.MediaStatus, Environment.TickCount - startTickCunt);
            }
            else
                media.MediaStatus = TMediaStatus.Available;
        }
Example #14
0
        public static XDocument Inform(FileInf[] files)
        {
            var xdoc = new XDocument(new XElement("Files"));

            foreach (FileInf file in files)
            {
                try
                {
                    if (xdoc.Root != null)
                    {
                        XElement xfile = new XElement("File",
                                                      new XAttribute("path", file.Path),
                                                      new XAttribute("name", file.FileName));

                        MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo();
                        mediaInfo.Open(file.Path);
                        mediaInfo.Option("Complete", "1");
                        string   info  = mediaInfo.Inform();
                        string[] infos = info.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                        XElement xgeneral = null;
                        XElement xaudio   = null;
                        XElement xvideo   = null;

                        // Build xgeneral
                        foreach (var line in infos)
                        {
                            if (line == "General")
                            {
                                xgeneral = new XElement("General");
                                continue;
                            }

                            if (line == "Audio" || line == "Video")
                            {
                                break;
                            }

                            string[] tag = line.Split(':');
                            xgeneral.Add(new XElement("Tag",
                                                      new XAttribute("name", tag[0].Trim()),
                                                      new XAttribute("value", tag[1].Trim())));
                        }

                        // Build xvideo
                        var xvideoFound = false;
                        foreach (var line in infos)
                        {
                            if (line == "Video")
                            {
                                xvideoFound = true;
                                xvideo      = new XElement("Video");
                                continue;
                            }

                            if (xvideoFound)
                            {
                                if (line == "Audio")
                                {
                                    break;
                                }

                                string[] tag = line.Split(':');
                                xvideo.Add(new XElement("Tag",
                                                        new XAttribute("name", tag[0].Trim()),
                                                        new XAttribute("value", tag[1].Trim())));
                            }
                        }

                        // Build xaudio
                        var xaudioFound = false;
                        foreach (var line in infos)
                        {
                            if (line == "Audio")
                            {
                                xaudioFound = true;
                                xaudio      = new XElement("Audio");
                                continue;
                            }

                            if (xaudioFound)
                            {
                                if (line == "Video")
                                {
                                    break;
                                }

                                string[] tag = line.Split(':');
                                xaudio.Add(new XElement("Tag",
                                                        new XAttribute("name", tag[0].Trim()),
                                                        new XAttribute("value", tag[1].Trim())));
                            }
                        }

                        if (xgeneral != null)
                        {
                            xfile.Add(xgeneral);
                        }

                        if (xvideo != null)
                        {
                            xfile.Add(xvideo);
                        }

                        if (xaudio != null)
                        {
                            xfile.Add(xaudio);
                        }

                        xdoc.Root.Add(xfile);
                    }
                    Logger.InfoFormat("MediaInfo of the file {0} generated.", file.Path);

                    if (!_atLeastOneSucceed)
                    {
                        _atLeastOneSucceed = true;
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    Logger.ErrorFormat("An error occured while generating the mediaInfo of the file {0}", e, file.Path);
                    _success = false;
                }
            }
            return(xdoc);
        }
Example #15
0
        public string of_GetXmlStr(string lsFile)
        {
            try
            {
                string parameter = "";//存放所有参数
                string tempstr;
                int    i          = 0;
                int    VideoCount = 0;
                int    AudioCount = 0;

                MediaInfoLib.MediaInfo m = new MediaInfoLib.MediaInfo();
                int k = m.Open(lsFile);
                if (k != 1)
                {
                    return("Not Media File!");
                }

                parameter = "<Root>";
                //General
                parameter += "\r\n" + "<General>";
                i          = 0;
                while (true)
                {
                    tempstr = m.Get(StreamKind.General, 0, i++, InfoKind.Name);//.Replace("/", "_");
                    if (tempstr == "")
                    {
                        break;
                    }
                    //获得值
                    string V = m.Get(MediaInfoLib.StreamKind.General, 0, tempstr);
                    if (V == "")
                    {
                        continue;
                    }
                    if (tempstr.Contains("/"))
                    {
                        continue;
                    }
                    //获得视频和音频数据
                    if (tempstr == "VideoCount")
                    {
                        VideoCount = int.Parse(V);
                    }
                    if (tempstr == "AudioCount")
                    {
                        AudioCount = int.Parse(V);
                    }
                    parameter += "\r\n" + "<item Name=\"" + tempstr + "\">" + V + "</item>";
                }
                parameter += "\r\n" + "</General>";
                //Video
                parameter += "\r\n" + "<Video>";
                for (int j = 0; j < VideoCount; j++)
                {
                    parameter += "\r\n" + "<Row>";
                    i          = 0;
                    while (true)
                    {
                        tempstr = m.Get(StreamKind.Video, j, i++, InfoKind.Name);//.Replace("/", "_");
                        if (tempstr == "")
                        {
                            break;
                        }
                        //获得值
                        string V = m.Get(MediaInfoLib.StreamKind.Video, j, tempstr);
                        if (V == "")
                        {
                            continue;
                        }
                        //if (V.Contains("AMBA")) continue;
                        if (tempstr.Contains("/"))
                        {
                            continue;
                        }
                        //if (tempstr.Contains("AMBA")) continue;

                        parameter += "\r\n" + "<item Name=\"" + tempstr + "\">" + V + "</item>";
                    }
                    parameter += "\r\n" + "</Row>";
                }
                parameter += "\r\n" + "</Video>";
                //Audio
                parameter += "\r\n" + "<Audio>";
                for (int j = 0; j < AudioCount; j++)
                {
                    parameter += "\r\n" + "<Row>";
                    i          = 0;
                    while (true)
                    {
                        tempstr = m.Get(StreamKind.Audio, j, i++, InfoKind.Name);//.Replace("/", "_");
                        if (tempstr == "")
                        {
                            break;
                        }
                        //获得值
                        string V = m.Get(MediaInfoLib.StreamKind.Audio, j, tempstr);
                        if (V == "")
                        {
                            continue;
                        }
                        if (tempstr.Contains("/"))
                        {
                            continue;
                        }
                        parameter += "\r\n" + "<item Name=\"" + tempstr + "\">" + V + "</item>";
                    }
                    parameter += "\r\n" + "</Row>";
                }
                parameter += "\r\n" + "</Audio>";
                parameter += "\r\n" + "</Root>";
                m.Close();
                return(parameter);
            }
            catch (Exception ex)
            { return("error:" + ex.Message + ex.StackTrace); }
        }
Example #16
0
        private static void DisplayMediaInfo()
        {
            String ToDisplay;

            MediaInfoLib.MediaInfo MI = new MediaInfoLib.MediaInfo();

            ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0");
            if (ToDisplay.Length == 0)
            {
                Console.Write("MediaInfo.Dll: this version of the DLL is not compatible");
                return;
            }

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

            ToDisplay += "\r\n\r\nInfo_Capacities\r\n";
            ToDisplay += MI.Option("Info_Capacities");

            ToDisplay += "\r\n\r\nInfo_Codecs\r\n";
            ToDisplay += MI.Option("Info_Codecs");

            //An example of how to use the library
            ToDisplay += "\r\n\r\nOpen\r\n";
            ToDisplay += "\r\n\r\nClose\r\n==========================";
            ToDisplay += "\r\n\r\nClose\r\n==========================";
            MI.Open("d:\temp\test.mp4");

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

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

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

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n";
            ToDisplay += MI.Get(0, 0, "FileSize");

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
            ToDisplay += MI.Get(0, 0, 46);

            ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
            ToDisplay += MI.Count_Get(MediaInfoLib.StreamKind.Audio);

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
            ToDisplay += MI.Get(MediaInfoLib.StreamKind.General, 0, "AudioCount");

            ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
            ToDisplay += MI.Get(MediaInfoLib.StreamKind.Audio, 0, "StreamCount");

            ToDisplay += "\r\n\r\nClose\r\n";
            MI.Close();
            ToDisplay += "\r\n\r\nClose\r\n==========================";
            //Example with a stream
            ToDisplay += "\r\n" + ReadMediaInfo() + "\r\n";

            //Displaying the text
            Console.Write(ToDisplay);
        }
Example #17
0
        private void QueryMediaFile(string path)
        {
            MediaInfoLib.MediaInfo MI = new MediaInfoLib.MediaInfo();

            MI.Open(path);
            int i;

            DIFeature difeature = new DIFeature();

            difeature.Filesize = (int)(ToInt64(MI.Get(0, 0, "FileSize")) / 1024 / 1024);  // MB
            try
            {
                difeature.Duration = TimeSpan.FromMilliseconds(Convert.ToDouble(MI.Get(0, 0, "Duration"))); // Minutes
            }
            catch
            {
            }
            difeature.OverallBitRate = ToInt32(MI.Get(0, 0, "OverallBitRate")) / 1000; // kbps
            difeature.Format         = MI.Get(0, 0, "Format");
            difeature.Name           = path;

            int videostreamscount = ToInt32(MI.Get(MediaInfoLib.StreamKind.Video, 0, "StreamCount"));

            Console.WriteLine("\nVideo Stream Count : " + videostreamscount.ToString());

            try
            {
                for (i = 0; i < videostreamscount; i++)
                {
                    DIVideoStream divideostream = new DIVideoStream();
                    divideostream.FrameRate  = (float)Convert.ToDouble(MI.Get(MediaInfoLib.StreamKind.Video, i, "FrameRate"));
                    divideostream.Bitrate    = ToInt32(MI.Get(MediaInfoLib.StreamKind.Video, i, "BitRate")) / 1000;
                    divideostream.Resolution = new Size(
                        ToInt32(MI.Get(MediaInfoLib.StreamKind.Video, i, "Width")),
                        ToInt32(MI.Get(MediaInfoLib.StreamKind.Video, i, "Height")));
                    divideostream.Format      = MI.Get(MediaInfoLib.StreamKind.Video, i, "Format");
                    divideostream.AspectRatio = MI.Get(MediaInfoLib.StreamKind.Video, i, "DisplayAspectRatio/String");
                    divideostream.ScanType    = MI.Get(MediaInfoLib.StreamKind.Video, i, "ScanType");
                    divideostream.TitleID     = ToInt32(MI.Get(MediaInfoLib.StreamKind.Video, i, "ID"));
                    divideostream.Name        = MI.Get(MediaInfoLib.StreamKind.Video, i, "Title");

                    difeature.VideoStreams.Add(divideostream);
                }
            }
            catch (Exception ex)
            {
                Utilities.DebugLine("[DiskInfo:QueryMediaFile] An error occured during file scan: {0}", ex.Message);
            }

            try
            {
                int audiostreamscount = ToInt32(MI.Get(MediaInfoLib.StreamKind.Audio, 0, "StreamCount"));
                Console.WriteLine("\nAudio Stream Count : " + audiostreamscount.ToString());

                for (i = 0; i < audiostreamscount; i++)
                {
                    DIAudioStream diaudiostream = new DIAudioStream();
                    diaudiostream.LanguageID  = MI.Get(MediaInfoLib.StreamKind.Audio, i, "Language");
                    diaudiostream.BitrateMode = MI.Get(MediaInfoLib.StreamKind.Audio, i, "BitRate_Mode");
                    diaudiostream.Bitrate     = ToInt32(MI.Get(MediaInfoLib.StreamKind.Audio, i, "BitRate")) / 1000;
                    diaudiostream.Channels    = ToInt32(MI.Get(MediaInfoLib.StreamKind.Audio, i, "Channels"));
                    diaudiostream.AudioID     = ToInt32(MI.Get(MediaInfoLib.StreamKind.Audio, i, "ID"));
                    diaudiostream.Name        = diaudiostream.Language;
                    if (diaudiostream.Channels > 0)
                    {
                        diaudiostream.Name = diaudiostream.Name + " " + diaudiostream.Channels.ToString() + "ch";
                    }

                    // Initialise fields
                    diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                    diaudiostream.SubFormat       = "";

                    switch (MI.Get(MediaInfoLib.StreamKind.Audio, i, "Format"))
                    {
                    case "AC-3":
                        diaudiostream.Encoding        = DIAudioEncoding.AC3;
                        diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                        break;

                    case "DTS":
                        diaudiostream.Encoding        = DIAudioEncoding.DTS;
                        diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                        break;

                    case "AAC":
                        diaudiostream.Encoding        = DIAudioEncoding.AAC;
                        diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                        break;

                    case "Vorbis":
                        diaudiostream.Encoding        = DIAudioEncoding.VORBIS;
                        diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                        break;

                    case "MPEG Audio":
                        switch (MI.Get(MediaInfoLib.StreamKind.Audio, i, "Format_Version"))
                        {
                        case "Version 1": diaudiostream.Encoding = DIAudioEncoding.MPEG1; break;

                        case "Version 2": diaudiostream.Encoding = DIAudioEncoding.MPEG2; break;

                        default: diaudiostream.Encoding = DIAudioEncoding.Undefined; break;
                        }
                        switch (MI.Get(MediaInfoLib.StreamKind.Audio, i, "Format_Profile"))
                        {
                        case "Layer 2": diaudiostream.EncodingProfile = DIAudioEncodingProfile.Layer2; break;

                        case "Layer 3": diaudiostream.EncodingProfile = DIAudioEncodingProfile.Layer3; break;

                        default: diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined; break;
                        }
                        break;

                    case "WMA2":
                        diaudiostream.Encoding = DIAudioEncoding.WMA2;
                        switch (MI.Get(MediaInfoLib.StreamKind.Audio, i, "Format_Profile"))
                        {
                        case "L1": diaudiostream.EncodingProfile = DIAudioEncodingProfile.L1; break;

                        case "L2": diaudiostream.EncodingProfile = DIAudioEncodingProfile.L2; break;

                        default: diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined; break;
                        }
                        break;

                    default:
                        diaudiostream.Encoding        = DIAudioEncoding.Undefined;
                        diaudiostream.EncodingProfile = DIAudioEncodingProfile.Undefined;
                        break;
                    }

                    difeature.AudioStreams.Add(diaudiostream);
                }
            }
            catch (Exception ex)
            {
                Utilities.DebugLine("[DiskInfo:QueryMediaFile] An error occured during file scan: {0}", ex.Message);
            }

            Console.WriteLine(MI.Count_Get(MediaInfoLib.StreamKind.Audio));

            Console.WriteLine(MI.Get(MediaInfoLib.StreamKind.General, 0, "AudioCount"));

            Console.WriteLine(MI.Get(MediaInfoLib.StreamKind.Audio, 0, "StreamCount"));

            DiskFeatures.Add(difeature);

            MI.Close();
        }
Example #18
0
        public override TaskStatus Run()
        {
            Info("Generating MediaInfo informations...");

            bool success           = true;
            bool atLeastOneSucceed = false;

            var files = SelectFiles();

            if (files.Length > 0)
            {
                var mediaInfoPath = Path.Combine(Workflow.WorkflowTempFolder,
                                                 string.Format("MediaInfo_{0:yyyy-MM-dd-HH-mm-ss-fff}.xml", DateTime.Now));

                var xdoc = new XDocument(new XElement("Files"));
                foreach (FileInf file in files)
                {
                    try
                    {
                        if (xdoc.Root != null)
                        {
                            XElement xfile = new XElement("File",
                                                          new XAttribute("path", file.Path),
                                                          new XAttribute("name", file.FileName));

                            MediaInfoLib.MediaInfo mediaInfo = new MediaInfoLib.MediaInfo();
                            mediaInfo.Open(file.Path);
                            mediaInfo.Option("Complete", "1");
                            string   info  = mediaInfo.Inform();
                            string[] infos = info.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                            XElement xgeneral = null;
                            XElement xaudio   = null;
                            XElement xvideo   = null;

                            // Build xgeneral
                            foreach (var line in infos)
                            {
                                if (line == "General")
                                {
                                    xgeneral = new XElement("General");
                                    continue;
                                }

                                if (line == "Audio" || line == "Video")
                                {
                                    break;
                                }

                                string[] tag = line.Split(':');
                                xgeneral.Add(new XElement("Tag",
                                                          new XAttribute("name", tag[0].Trim()),
                                                          new XAttribute("value", tag[1].Trim())));
                            }

                            // Build xvideo
                            var xvideoFound = false;
                            foreach (var line in infos)
                            {
                                if (line == "Video")
                                {
                                    xvideoFound = true;
                                    xvideo      = new XElement("Video");
                                    continue;
                                }

                                if (line == "Audio")
                                {
                                    break;
                                }

                                if (xvideoFound)
                                {
                                    string[] tag = line.Split(':');
                                    xvideo.Add(new XElement("Tag",
                                                            new XAttribute("name", tag[0].Trim()),
                                                            new XAttribute("value", tag[1].Trim())));
                                }
                            }

                            // Build xaudio
                            var xaudioFound = false;
                            foreach (var line in infos)
                            {
                                if (line == "Audio")
                                {
                                    xaudioFound = true;
                                    xaudio      = new XElement("Audio");
                                    continue;
                                }

                                if (xaudioFound)
                                {
                                    string[] tag = line.Split(':');
                                    xaudio.Add(new XElement("Tag",
                                                            new XAttribute("name", tag[0].Trim()),
                                                            new XAttribute("value", tag[1].Trim())));
                                }
                            }

                            if (xgeneral != null)
                            {
                                xfile.Add(xgeneral);
                            }

                            if (xvideo != null)
                            {
                                xfile.Add(xvideo);
                            }

                            if (xaudio != null)
                            {
                                xfile.Add(xaudio);
                            }

                            xdoc.Root.Add(xfile);
                        }
                        InfoFormat("MediaInfo of the file {0} generated.", file.Path);

                        if (!atLeastOneSucceed)
                        {
                            atLeastOneSucceed = true;
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        ErrorFormat("An error occured while generating the mediaInfo of the file {0}", e, file.Path);
                        success = false;
                    }
                }
                xdoc.Save(mediaInfoPath);
                Files.Add(new FileInf(mediaInfoPath, Id));
            }

            var status = Status.Success;

            if (!success && atLeastOneSucceed)
            {
                status = Status.Warning;
            }
            else if (!success)
            {
                status = Status.Error;
            }

            Info("Task finished.");
            return(new TaskStatus(status, false));
        }
Example #19
-1
        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                FFMpegConverter ffMpeg = new FFMpegConverter();
                MediaInfoLib.MediaInfo mi = new MediaInfoLib.MediaInfo();
                MediaInfoDotNet.MediaFile m = new MediaFile(openFileDialog1.FileName);
                List<Image> images = new List<Image>();
                TimeSpan ts = TimeSpan.FromMilliseconds(m.duration);
                int col = 15;
                int period = Convert.ToInt32(ts.TotalSeconds) / col;
                int w=0, h=0, column = 3;
                for (int i = 1; i <= col; i++)
                {
                    MemoryStream ms = new MemoryStream();
                    Image image;
                    ffMpeg.GetVideoThumbnail(openFileDialog1.FileName, ms, i * period);
                    image = Image.FromStream(ms);
                    w = image.Width;
                    h = image.Height;
                    //pictureBox1.Image = image;
                    images.Add(image);
                }
                Image mm = Draw(images, w, h, column);
                mm = ResizeImg(mm, 28);
                pictureBox1.Image = mm;

            }
        }