public virtual Int32 GetRunTime(string filename)
        {
            var mediaInfo = new MediaInfo();

            try
            {
                logger.Trace("Getting media info from {0}", filename);

                mediaInfo.Option("ParseSpeed", "0.2");
                int open = mediaInfo.Open(filename);

                if (open != 0)
                {
                    int runTime;
                    Int32.TryParse(mediaInfo.Get(StreamKind.General, 0, "PlayTime"), out runTime);

                    mediaInfo.Close();
                    return(runTime / 1000); //Convert to seconds
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Unable to parse media info from file: " + filename, ex);
                mediaInfo.Close();
            }

            return(0);
        }
Beispiel #2
0
        private void OnPlaybackPlay()
        {
            // Send sound effects
            SoundFxRequest soundFxRequest = new SoundFxRequest();

            soundFxRequest.Effects = _effectsForm.GetEnabledEffects();
            _playerCommunicatorControl.SendRequest(soundFxRequest);

            // Send play request
            PlayRequest request = (PlayRequest)RequestFactory.CreateRequest(MessageType.Play);

            if (_playlistForm.GetCurrent().Count.Equals(0))
            {
                MessageBox.Show("Playlist is empty. Nothing to play", "Information");
                return;
            }
            request.Tracks = _playlistForm.GetCurrent();
            _playerCommunicatorControl.SendRequest(request);

            // TODO set state based on response
            // set controls state
            _mediaInfo.Open(_playlistForm.GetCurrent()[0]);
            _playbackControl.PlaybackStarted(_mediaInfo.GetDuration());
            _mediaInfo.Close();
        }
Beispiel #3
0
        private static Dictionary <string, string> VidGpsQuery(FileSystemInfo file)
        {
            try {
                var mi = new MediaInfo();
                mi.Open(file.FullName);
                string strGps;
                try {
                    strGps = mi.Get(StreamKind.General, 0, "xyz");
                    if (string.IsNullOrEmpty(strGps))
                    {
                        return(null);
                    }
                } catch (Exception) {
                    mi.Close();
                    return(null);
                }
                mi.Close();
                var strGpsSplit = strGps.Split('+', '-');
                var strLat = strGpsSplit[1];
                var strLng = strGpsSplit[2];
                var strRef = strGps.Replace(strLat, "").Replace(strLng, "");
                int intLatRef = 1, intLngRef = 1;
                switch (strRef[0])
                {
                case '+':
                    intLatRef = 1;
                    break;

                case '-':
                    intLatRef = -1;
                    break;
                }
                switch (strRef[1])
                {
                case '+':
                    intLngRef = 1;
                    break;

                case '-':
                    intLngRef = -1;
                    break;
                }
                var dblLat  = intLatRef * double.Parse(strLat);
                var dblLng  = intLngRef * double.Parse(strLng.Replace("/", ""));
                var dictGps = new Dictionary <string, string>
                {
                    { "longitude", dblLng + "" },
                    { "Latitude", dblLat + "" }
                };
                return(dictGps);
            } catch (Exception) {
                return(null);
            }
        }
Beispiel #4
0
        private vMixEvent ParseVideoData(string path)
        {
            vMixEvent new_event = null;
            string    infotext  = path;

            FileInfo.Open(path);

            string result = FileInfo.Get(StreamKind.General, 0, "Video_Format_List");

            if (result != "")
            {
                infotext += "\r\nVideo: " + result;
                result    = FileInfo.Get(StreamKind.General, 0, "Audio_Format_List");
                if (result != "")
                {
                    infotext += "\r\nAudio: " + result;
                }

                double   milliseconds = -1;
                TimeSpan duration     = new TimeSpan(0);
                result = FileInfo.Get(StreamKind.General, 0, "Duration");
                CultureInfo cult = CultureInfo.CreateSpecificCulture("en-GB");
                if (result != "" && double.TryParse(result, NumberStyles.Float | NumberStyles.AllowDecimalPoint, cult, out milliseconds))
                {
                    duration  = new TimeSpan(0, 0, 0, 0, (int)milliseconds);
                    infotext += "\r\nDuration: " + duration.ToString(@"hh\:mm\:ss");
                }
                else
                {
                    MessageBox.Show("I can't decode this files duration!", "No Duration?", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                new_event = new vMixEvent(System.IO.Path.GetFileNameWithoutExtension(path),
                                          path,
                                          vmEventType.video,
                                          dtp_timetable.Value,
                                          new TimeSpan(0),
                                          duration,
                                          duration,
                                          true,
                                          vmTransitionType.cut,
                                          1000,
                                          true);
                new_event.EventInfoText = infotext;
            }
            else
            {
                MessageBox.Show("I can't recognize the video format!", "No Video?", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            FileInfo.Close();
            return(new_event);
        }
Beispiel #5
0
 private void SetAutoBitrate()
 {
     if (InputFileTextBox.Text != "")
     {
         MediaInfo MI = new MediaInfo();
         MI.Open(InputFileTextBox.Text);
         string VidWidthString  = MI.Get(StreamKind.Video, 0, "Width");
         int    VidWidth        = int.Parse(VidWidthString);
         string VidHeightString = MI.Get(StreamKind.Video, 0, "Height");
         int    VidHeight       = int.Parse(VidHeightString);
         MI.Close();
         int AutoBitrate = CalcAutoBitrate(VidWidth, VidHeight);
         if ((string)VidCodecDropDownBox.SelectedItem == "hevc" || (string)VidCodecDropDownBox.SelectedItem == "hevc_nvenc")
         {
             OutputBitrateTextBox.Text = (AutoBitrate / 2).ToString();
         }
         else
         {
             OutputBitrateTextBox.Text = AutoBitrate.ToString();
         }
     }
     else
     {
         OutputBitrateTextBox.Text = "4000";
     }
 }
Beispiel #6
0
        private void OnPlaybackPlay()
        {
            PlayRequest request = (PlayRequest)RequestFactory.CreateRequest(MessageType.Play);

            if (_playlistForm.GetCurrent().Count.Equals(0))
            {
                MessageBox.Show("Playlist is empty. Nothing to play", "Information");
                return;
            }

            request.Tracks = _playlistForm.GetCurrent();

            AResponse response = _playerCommunicatorControl.SendRequest(request);

            try
            {
                // if success
                if (response.ResponseType == ServerResponseType.Success)
                {
                    // set controls state
                    _mediaInfo.Open(_playlistForm.GetCurrent()[0]);
                    _playbackControl.PlaybackStarted(_mediaInfo.GetDuration());
                    _mediaInfo.Close();

                    _addonsForm.PlaybackStarted();

                    // Set volume
                    OnPlaybackVolume(_playbackControl.Volume);
                }
            }
            catch (System.Exception)
            {
            }
        }
Beispiel #7
0
 /*
  * Opens the open file dialog and allows you to select
  * one or multiple songs and have them added to the
  * database and the linked list then diplayed.
  */
 private void btnAddSong_Click(object sender, EventArgs e)
 {
     try
     {
         using (OpenFileDialog openFileDialog = new OpenFileDialog()
         {
             Multiselect = true, ValidateNames = true
         })
         {
             if (openFileDialog.ShowDialog() == DialogResult.OK)
             {
                 foreach (string fileName in openFileDialog.FileNames)
                 {
                     MediaInfo MI = new MediaInfo();
                     MI.Open(fileName);
                     Song song = new Song();
                     song.userID     = session.userID;
                     song.songName   = MI.Get(StreamKind.General, 0, "Title");
                     song.artistName = MI.Get(StreamKind.General, 0, "Performer");
                     song.songPath   = fileName;
                     MI.Close();
                     musicList.AddLast(song);
                     dbc.addSongToDB(song.userID, song.songName, song.artistName, song.songPath);
                 }
             }
         }
         displaySongs();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to add song or songs \n\n Reported Error: " + ex);
     }
 }
Beispiel #8
0
        static void Main()
        {
            string path = "Q:\\XXX\\ZZ\\201014 众\\2020.10.14_104356.mov";

            var directories = ImageMetadataReader.ReadMetadata(path);

            FileSystemInfo file = new FileInfo(path);
            var            mi   = new MediaInfo();

            mi.Open(file.FullName);
            Console.WriteLine(mi.Inform());
            mi.Close();
            mi.Dispose();

            foreach (var directory in directories)
            {
                foreach (var tag in directory.Tags)
                {
                    Console.WriteLine($"[{directory.Name}] {tag.Name} = {tag.Description}");
                }

                if (directory.HasError)
                {
                    foreach (var error in directory.Errors)
                    {
                        Console.WriteLine($"ERROR: {error}");
                    }
                }
            }

            Console.ReadKey();
        }
Beispiel #9
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            //Test if version of DLL is compatible : 3rd argument is "version of DLL tested;Your application name;Your application version"
            String    ToDisplay;
            MediaInfo MI = new MediaInfo();

            ToDisplay = MI.Option("Info_Version", "0.7.0.0;MediaInfoDLL_Example_CS;0.7.0.0");
            if (ToDisplay.Length == 0)
            {
                richTextBox1.Text = "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";
            MI.Open("Example.ogg");

            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(StreamKind.Audio);

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

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

            ToDisplay += "\r\n\r\nClose\r\n";
            MI.Close();

            //Displaying the text
            richTextBox1.Text = ToDisplay;
        }
Beispiel #10
0
        /// ------------------------------------------------------------------------------------
        public static MediaFileInfo GetInfo(string mediaFile)
        {
            var finfo = new FileInfo(mediaFile);

            if (!finfo.Exists || finfo.Length == 0)
            {
                var emptyMediaFileInfo = new MediaFileInfo();
                emptyMediaFileInfo.Audio = new AudioInfo();                 // SP-1007
                return(emptyMediaFileInfo);
            }
            var info = new MediaInfo();

            if (info.Open(mediaFile) == 0)
            {
                return(null);
            }
            info.Option("Inform", s_templateData);
            string output = info.Inform();

            info.Close();
            Exception error;
            var       mediaInfo = XmlSerializationHelper.DeserializeFromString <MediaFileInfo>(output, out error);

            if (mediaInfo == null || mediaInfo.Audio == null)
            {
                return(null);
            }

            mediaInfo.MediaFilePath = mediaFile;
            return(mediaInfo);
        }
Beispiel #11
0
        public void LoadMediaInfo()
        {
            var src = Source;

            if (src == null || src.IsFile == false)
            {
                return;
            }

            BackgroundWorker b = new BackgroundWorker();

            b.DoWork += (sender, args) =>
            {
                var info = new MediaInfo();
                info.Open(src.LocalPath);
                info.Option("Complete", "0");
                args.Result = info.Inform();
                info.Close();
            };
            b.RunWorkerCompleted += (sender, args) =>
            {
                MediaInfo = args.Result as string;
            };
            b.RunWorkerAsync();
        }
Beispiel #12
0
        /// ------------------------------------------------------------------------------------
        public static string GetInfoAsHtml(string mediaFile, bool verbose)
        {
            var info = new MediaInfo();

            info.Open(mediaFile);

            info.Option("Complete", verbose ? "1" : "0");
            info.Option("Inform", "HTML");
            string output = info.Inform();

            info.Close();
            // SP-985: The following makes it easier for end-users to get the 8.3, which may be needed
            // to diagnose MPlayer issues.
            if (verbose)
            {
                var i = output.IndexOf(mediaFile, StringComparison.Ordinal);
                if (i > 0)
                {
                    i = output.IndexOf("</tr>", i, StringComparison.OrdinalIgnoreCase);
                    if (i > 0)
                    {
                        i += "</tr>".Length;
                        var sb = new StringBuilder(output);
                        sb.Insert(i, String.Format("{0}  <tr>{0}    <td><i>MPlayer path :</i></td>{0}    <td colspan=\"3\">{1}</td>{0}</tr>{0}",
                                                   Environment.NewLine,
                                                   FileSystemUtils.GetShortName(mediaFile).Replace('\\', '/')));
                        output = sb.ToString();
                    }
                }
            }
            return(output);
        }
        private void CreateEncoderList()
        {
            var bdVersion = Assembly.GetAssembly(typeof(BDInfoLib.BDROM.TSCodecAC3)).GetName().Version;
            var mi        = new MediaInfo();
            var miVer     = mi.Option("Info_Version");

            mi.Close();
            EncoderList = new Dictionary <string, string>
            {
                { "x264", _configService.Lastx264Ver },
                { "x264 64bit", _configService.Lastx26464Ver },
                { "ffmpeg", _configService.LastffmpegVer },
                { "ffmpeg 64bit", _configService.Lastffmpeg64Ver },
                { "eac3to", _configService.Lasteac3ToVer },
                { "lsdvd", _configService.LastlsdvdVer },
                { "MkvToolnix", _configService.LastMKVMergeVer },
                { "mplayer", _configService.LastMplayerVer },
                { "tsMuxeR", _configService.LastTSMuxerVer },
                { "MJPEG tools", _configService.LastMJPEGToolsVer },
                { "DVDAuthor", _configService.LastDVDAuthorVer },
                { "MP4Box", _configService.LastMp4BoxVer },
                { "HCenc", _configService.LastHcEncVer },
                { "OggEnc2", _configService.LastOggEncVer },
                { "OggEnc2 Lancer Build", _configService.LastOggEncLancerVer },
                { "NeroAacEnc", _configService.LastNeroAacEncVer },
                { "LAME", _configService.LastLameVer },
                { "LAME 64bit", _configService.LastLame64Ver },
                { "vpxEnc", _configService.LastVpxEncVer },
                { "BDSup2Sub", _configService.LastBDSup2SubVer },
                { "BDInfo Library", $"{bdVersion.Major:g}.{bdVersion.Minor:g}.{bdVersion.Build:g}" },
                { "MediaInfo Library", miVer.Replace("MediaInfoLib - v", string.Empty) },
                { "AviSynth", _configService.LastAviSynthVer }
            };
            ReloadButtonEnabled = true;
        }
Beispiel #14
0
        public static bool IsVideo(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(false);
            }

            MediaInfo MI = new MediaInfo();

            MI.Open(filePath);

            //string vid = MI.Get(StreamKind.Video, 0, "ID");
            string video = MI.Get(StreamKind.Video, 0, "Format");

            MI.Close();

            if (string.IsNullOrEmpty(GetVideoFormat(filePath)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public TimeSpan GetVideoDuration()
        {
            mi.Open(path);
            var videoInfo = new VideoInfo(mi);
            var result    = videoInfo.Duration;

            mi.Close();
            return(result);
        }
Beispiel #16
0
        public static string GetVideoInfo(string path, string videoParameter)
        {
            MediaInfo info = new MediaInfo();

            info.Open(path);
            string str = info.Get(StreamKind.Video, 0, videoParameter, InfoKind.Text);

            info.Close();
            return(str);
        }
Beispiel #17
0
        public static string GetAudioInfo(string path, int streamNumber, string audioParameter)
        {
            MediaInfo info = new MediaInfo();

            info.Open(path);
            string str = info.Get(StreamKind.Audio, streamNumber, audioParameter, InfoKind.Text);

            info.Close();
            return(str);
        }
Beispiel #18
0
        private static Dictionary <string, string> VidDtQuery(FileSystemInfo file)
        {
            string strDt;
            var    mi = new MediaInfo();

            mi.Open(file.FullName);
            try {
                strDt = mi.Get(StreamKind.Video, 0, "Encoded_Date");
                if (string.IsNullOrEmpty(strDt))
                {
                    strDt = mi.Get(StreamKind.Video, 0, "Tagged_Date");
                }
                if (string.IsNullOrEmpty(strDt))
                {
                    strDt = mi.Get(StreamKind.General, 0, "Recorded_Date");
                }
                else if (string.IsNullOrEmpty(strDt))
                {
                    return(null);
                }
                mi.Close();
            } catch (Exception) {
                mi.Close();
                return(null);
            }
            mi.Dispose();
            const string strDtFormat = "yyyy.MM.dd_HHmmss";
            var          strTz       = strDt.Substring(0, 3);

            strDt = strDt.Replace(strTz + " ", "");
            var dtDt = DateTime.ParseExact(strDt, "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture);

            dtDt = ConvertTimeFromUtc(dtDt, Local);
            var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
            var timestamp = (dtDt.Ticks - startTime.Ticks) / 10000;
            var dictDt    = new Dictionary <string, string>
            {
                { "datetime", dtDt.ToString(strDtFormat) },
                { "timestamp", timestamp + "" }
            };

            return(dictDt);
        }
Beispiel #19
0
        static Transcoder GenerateOutputFileName(Options opt)
        {
            using (var info = new MediaInfo())
            {
                info.Inputs[0].File = opt.InputFile;

                if (!info.Open())
                {
                    PrintError("MediaInfo open", info.Error);
                    return(null);
                }

                MediaSocket inSocket = MediaSocket.FromMediaInfo(info);

                info.Close();

                Transcoder transcoder = new Transcoder();
                transcoder.AllowDemoMode = true;
                transcoder.Inputs.Add(inSocket);

                bool audio = false;
                bool video = false;

                for (int i = 0; i < inSocket.Pins.Count; ++i)
                {
                    string fileName;
                    if (inSocket.Pins[i].StreamInfo.MediaType == MediaType.Audio && !audio)
                    {
                        audio    = true;
                        fileName = opt.OutputFile + ".aud.mp4";
                    }
                    else if (inSocket.Pins[i].StreamInfo.MediaType == MediaType.Video && !video)
                    {
                        video    = true;
                        fileName = opt.OutputFile + ".vid.mp4";
                    }
                    else
                    {
                        inSocket.Pins[i].Connection = PinConnection.Disabled;
                        continue;
                    }

                    MediaSocket outSocket = new MediaSocket();
                    outSocket.Pins.Add(inSocket.Pins[i]);
                    DeleteFile(fileName);
                    outSocket.File = fileName;

                    transcoder.Outputs.Add(outSocket);

                    Console.WriteLine("Output file: {0}", fileName);
                }

                return(transcoder);
            }
        }
Beispiel #20
0
 private void InitializeProperties(string path)
 {
     if (Path.GetExtension(path).ToLower() == ".avs")
     {
         this.AvisynthInfo(path);
     }
     else
     {
         MediaInfo info = new MediaInfo();
         info.Open(path);
         this._filePath = path;
         if (info.Count_Get(StreamKind.Video) > 0)
         {
             this._hasVideo  = true;
             this._format    = info.Get(StreamKind.Video, 0, "Format");
             this._container = info.Get(StreamKind.General, 0, "Format");
             string str  = info.Get(StreamKind.Audio, 0, "ID");
             string str2 = info.Get(StreamKind.Video, 0, "ID");
             int.TryParse(info.Get(StreamKind.Video, 0, "ID"), out this._mkvmergeId);
             if ((str == "0") || (str2 == "0"))
             {
                 this._ffmpegId = this._mkvmergeId;
             }
             else if ((str == "1") || (str2 == "1"))
             {
                 this._ffmpegId = this._mkvmergeId - 1;
             }
             double.TryParse(info.Get(StreamKind.Video, 0, "Duration"), out this._length);
             this._length /= (double)0x3e8;
             int.TryParse(info.Get(StreamKind.Video, 0, "Width", InfoKind.Text), out this._width);
             int.TryParse(info.Get(StreamKind.Video, 0, "Height", InfoKind.Text), out this._height);
             double.TryParse(info.Get(StreamKind.Video, 0, "FrameRate", InfoKind.Text), out this._frameRate);
             int.TryParse(info.Get(StreamKind.Video, 0, "FrameCount", InfoKind.Text), out this._frameCount);
             string str3 = info.Get(StreamKind.Video, 0, "DisplayAspectRatio/String", InfoKind.Text);
             if (str3.IndexOf(":") != -1)
             {
                 char[] separator = new char[] { ':' };
                 char[] chArray2  = new char[] { ':' };
                 this._displayAspectRatio = double.Parse(str3.Split(separator)[0]) / double.Parse(str3.Split(chArray2)[1]);
             }
             if ((this._width != 0) && (this._displayAspectRatio == 0))
             {
                 this._displayAspectRatio = ((double)this._width) / ((double)this._height);
             }
         }
         else
         {
             this._hasVideo = false;
         }
         this._audioStreamsCount = info.Count_Get(StreamKind.Audio);
         info.Close();
     }
 }
Beispiel #21
0
        private static void Main(string[] args)
        {
            MediaInfo info = new MediaInfo();

            info.Open(@"E:\Songs Collection\Video's\Hindi Song's\Ajab.Si.By.HFZ.avi");
            var   movie_lenstr = info.Get(StreamKind.General, 0, "Duration");
            Int32 movie_len;

            if (Int32.TryParse(movie_lenstr, out movie_len))
            {
                Console.WriteLine("Length of movie in milli-second : {0}", movie_len);
            }
            info.Close();
        }
Beispiel #22
0
        private void getMediaInfo()
        {
            int VidTracks;
            int AudTracks;
            int SubTracks;

            MediaInfo MI = new MediaInfo();

            MI.Open(InputFileTextBox.Text);

            VidTracks = MI.Count_Get(StreamKind.Video);
            AudTracks = MI.Count_Get(StreamKind.Audio);
            SubTracks = MI.Count_Get(StreamKind.Text);

            VidTrackComboBox.Items.Clear();
            AudioTrackComboBox.Items.Clear();
            SubTrackComboBox.Items.Clear();
            AddVideoTracksToSelect(VidTracks);
            AddAudioTracksToSelect(AudTracks);
            if (SubTracks > 0)
            {
                AddSubTracksToSelect(SubTracks);
            }
            VidTrackComboBox.Visible   = true;
            AudioTrackComboBox.Visible = true;
            SubTrackComboBox.Visible   = true;

            MIVideoCodecSetLabel.Text = MI.Get(StreamKind.Video, 0, "Format");
            VidWidth  = int.Parse(MI.Get(StreamKind.Video, 0, "Width"));
            VidHeight = int.Parse(MI.Get(StreamKind.Video, 0, "Height"));
            MIVideoResSetLabel.Text   = VidWidth + "x" + VidHeight;
            MIVidBitrateSetLabel.Text = MI.Get(StreamKind.Video, 0, "BitRate/String");

            MIAudioCodecSetLabel.Text   = MI.Get(StreamKind.Audio, 0, "Format");
            MIAudioChanSetLabel.Text    = MI.Get(StreamKind.Audio, 0, "Channel(s)/String");
            MIAudioBitrateSetLabel.Text = MI.Get(StreamKind.Audio, 0, "BitRate/String");

            videoDuration     = int.Parse(MI.Get(StreamKind.General, 0, "Duration"));
            VideoRuntime.Text = MI.Get(StreamKind.General, 0, "Duration/String3");

            VidTrackCountSetLabel.Text    = VidTracks.ToString();
            AudioTracksCountSetLabel.Text = AudTracks.ToString();
            MISubTrackCountSetLabel.Text  = SubTracks.ToString();

            int AutoBitrate = CalcAutoBitrate(VidWidth, VidHeight);

            OutputBitrateTextBox.Text = AutoBitrate.ToString();

            MI.Close();
        }
Beispiel #23
0
        public static double GetDurationMilliseconds(string filePath)
        {
            double _result = 0;

            try
            {
                MediaInfo _mi = new MediaInfo();
                _mi.Open(filePath);
                _result = GetDuration(_mi);
                _mi.Close();
            }
            catch { }

            return(_result);
        }
Beispiel #24
0
        private void AddSubTracksToSelect(int NumSubTracks)
        {
            MediaInfo MI = new MediaInfo();

            MI.Open(InputFileTextBox.Text);

            for (int i = 1; i <= NumSubTracks; i++)
            {
                string subLang  = MI.Get(StreamKind.Text, i - 1, "Language");
                string subTitle = MI.Get(StreamKind.Text, i - 1, "Title");
                SubTrackComboBox.Items.Add(i + " (" + subLang + ")" + " " + subTitle);
            }
            SubTrackComboBox.SelectedIndex = 0;

            MI.Close();
        }
Beispiel #25
0
        private void AddAudioTracksToSelect(int NumAudioTracks)
        {
            MediaInfo MI = new MediaInfo();

            MI.Open(InputFileTextBox.Text);

            for (int i = 1; i <= NumAudioTracks; i++)
            {
                string audLang  = (MI.Get(StreamKind.Audio, i - 1, "Language"));
                string audTitle = MI.Get(StreamKind.Audio, i - 1, "Title");
                AudioTrackComboBox.Items.Add(i + " (" + audLang + ")" + " " + audTitle);
            }
            AudioTrackComboBox.SelectedIndex = 0;

            MI.Close();
        }
Beispiel #26
0
        public static string GetContainer(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(filePath, "filePath");
            }

            MediaInfo MI = new MediaInfo();

            MI.Open(filePath);

            string container = MI.Get(StreamKind.General, 0, "Format");

            MI.Close();

            return(container);
        }
Beispiel #27
0
        public static string GetVideoBitrate(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(filePath, "filePath");
            }

            MediaInfo MI = new MediaInfo();

            MI.Open(filePath);

            string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String");

            MI.Close();

            return(vBitRate);
        }
Beispiel #28
0
        public static string GetAudioFormat(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            MediaInfo MI = new MediaInfo();

            MI.Open(filePath);

            //string aid = MI.Get(StreamKind.Audio, 0, "ID");
            string audio = MI.Get(StreamKind.Audio, 0, "Format");

            MI.Close();

            return(audio);
        }
Beispiel #29
0
        public static Size GetVideoResolution(string filePath)
        {
            Size _result = new Size(0, 0);

            try
            {
                MediaInfo _mi = new MediaInfo();
                _mi.Open(filePath);
                string _height = _mi.Get(StreamKind.Video, 0, "Height");
                string _width  = _mi.Get(StreamKind.Video, 0, "Width");
                _result.Width  = Int32.Parse(_width);
                _result.Height = Int32.Parse(_height);
                _mi.Close();
            }
            catch { }

            return(_result);
        }
Beispiel #30
0
        public static void GetDurationAndVideoResolution(string filePath, out double duration, out Size resolution)
        {
            duration   = 0d;
            resolution = new Size(0, 0);
            try
            {
                MediaInfo _mi = new MediaInfo();
                _mi.Open(filePath);
                duration = GetDuration(_mi);

                string _height = _mi.Get(StreamKind.Video, 0, "Height");
                string _width  = _mi.Get(StreamKind.Video, 0, "Width");
                resolution.Width  = Int32.Parse(_width);
                resolution.Height = Int32.Parse(_height);

                _mi.Close();
            }
            catch { }
        }
Beispiel #31
0
        public static Media Convert(string filename)
        {
            int ex = 0;
            MediaInfo mi = new MediaInfo();
            if (mi == null)
                return null;
            try
            {
                if (!File.Exists(filename))
                    return null;
            }
            catch (Exception)
            {
                return null;
            }
            try
            {
                mi.Open(filename);
                ex = 1;
                Media m = new Media();
                Part p = new Part();
                Stream VideoStream = null;
                int video_count = mi.GetInt(StreamKind.General, 0, "VideoCount");
                int audio_count = mi.GetInt(StreamKind.General, 0, "AudioCount");
                int text_count = mi.GetInt(StreamKind.General, 0, "TextCount");
                m.Duration = p.Duration = mi.Get(StreamKind.General, 0, "Duration");
                m.Container = p.Container = TranslateContainer(mi.Get(StreamKind.General, 0, "Format"));
                string codid = mi.Get(StreamKind.General, 0, "CodecID");
                if ((!string.IsNullOrEmpty(codid)) && (codid.Trim().ToLower() == "qt"))
                    m.Container = p.Container= "mov";

                int brate = mi.GetInt(StreamKind.General, 0, "BitRate");
                if (brate != 0)
                    m.Bitrate = Math.Round(brate / 1000F).ToString(CultureInfo.InvariantCulture);
                p.Size = mi.Get(StreamKind.General, 0, "FileSize");
                //m.Id = p.Id = mi.Get(StreamKind.General, 0, "UniqueID");

                ex = 2;
                List<Stream> streams = new List<Stream>();
                int iidx = 0;
                if (video_count > 0)
                {
                    for (int x = 0; x < video_count; x++)
                    {
                        Stream s = TranslateVideoStream(mi, x);
                        if (x == 0)
                        {
                            VideoStream = s;
                            m.Width = s.Width;
                            m.Height = s.Height;
                            if (!string.IsNullOrEmpty(m.Height))
                            {
                                
                                if (!string.IsNullOrEmpty(m.Width))
                                {
                                    m.VideoResolution = GetResolution(int.Parse(m.Width),int.Parse(m.Height));
                                    m.AspectRatio = GetAspectRatio(float.Parse(m.Width), float.Parse(m.Height), s.PA);

                                }
                            }
                            if (!string.IsNullOrEmpty(s.FrameRate))
                            {
                                float fr = System.Convert.ToSingle(s.FrameRate);
                                m.VideoFrameRate = ((int)Math.Round(fr)).ToString(CultureInfo.InvariantCulture);
                                if (!string.IsNullOrEmpty(s.ScanType))
                                {
                                    if (s.ScanType.ToLower().Contains("int"))
                                        m.VideoFrameRate += "i";
                                    else
                                        m.VideoFrameRate += "p";
                                }
                                else
                                    m.VideoFrameRate += "p";
                                if ((m.VideoFrameRate == "25p") || (m.VideoFrameRate == "25i"))
                                    m.VideoFrameRate = "PAL";
                                else if ((m.VideoFrameRate == "30p") || (m.VideoFrameRate == "30i"))
                                    m.VideoFrameRate = "NTSC";
                            }
                            m.VideoCodec = s.Codec;
                            if (!string.IsNullOrEmpty(m.Duration) && !string.IsNullOrEmpty(s.Duration))
                            {
                                if (int.Parse(s.Duration) > int.Parse(m.Duration))
                                    m.Duration = p.Duration = s.Duration;
                            }
                            if (video_count == 1)
                            {
                                s.Default = null;
                                s.Forced = null;
                            }
                        }

                        if (m.Container != "mkv")
                        {
                            s.Index = iidx.ToString(CultureInfo.InvariantCulture);
                            iidx++;
                        }
                        streams.Add(s);
                    }
                }
                ex = 3;
                int totalsoundrate = 0;
                if (audio_count > 0)
                {
                    for (int x = 0; x < audio_count; x++)
                    {
                        Stream s = TranslateAudioStream(mi, x);
                        if ((s.Codec == "adpcm") && (p.Container == "flv"))
                            s.Codec = "adpcm_swf";
                        if (x == 0)
                        {
                            m.AudioCodec = s.Codec;
                            m.AudioChannels = s.Channels;
                            if (!string.IsNullOrEmpty(m.Duration) && !string.IsNullOrEmpty(s.Duration))
                            {
                                if (int.Parse(s.Duration) > int.Parse(m.Duration))
                                    m.Duration = p.Duration = s.Duration;
                            }
                            if (audio_count == 1)
                            {
                                s.Default = null;
                                s.Forced = null;
                            }
                        }
                        if (!string.IsNullOrEmpty(s.Bitrate))
                        {
                            totalsoundrate += int.Parse(s.Bitrate);
                        }
                            if (m.Container != "mkv")
                        {
                            s.Index = iidx.ToString(CultureInfo.InvariantCulture);
                            iidx++;
                        }
                        streams.Add(s);
                    }
                }
                if ((VideoStream!=null) && (string.IsNullOrEmpty(VideoStream.Bitrate) && (!string.IsNullOrEmpty(m.Bitrate))))
                {
                    VideoStream.Bitrate = (int.Parse(m.Bitrate) - totalsoundrate).ToString(CultureInfo.InvariantCulture);
                }


                ex = 4;
                if (text_count > 0)
                {
                    for (int x = 0; x < audio_count; x++)
                    {
                        Stream s = TranslateTextStream(mi, x);
                        streams.Add(s);
                        if (text_count == 1)
                        {
                            s.Default = null;
                            s.Forced = null;
                        }
                        if (m.Container != "mkv")
                        {
                            s.Index = iidx.ToString(CultureInfo.InvariantCulture);
                            iidx++;
                        }
                    }
                }

                ex = 5;
                m.Parts = new List<Part>();
                m.Parts.Add(p);
                bool over = false;
                if (m.Container == "mkv")
                {
                    int val = int.MaxValue;
                    foreach (Stream s in streams)
                    {
                        if (string.IsNullOrEmpty(s.Index))
                        {
                            over = true;
                            break;
                        }
                        s.idx = int.Parse(s.Index);
                        if (s.idx < val)
                            val = s.idx;
                    }
                    if ((val != 0) && (!over))
                    {
                        foreach (Stream s in streams)
                        {
                            s.idx = s.idx - val;
                            s.Index = s.idx.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    else if (over)
                    {
                        int xx = 0;
                        foreach (Stream s in streams)
                        {
                            s.idx = xx++;
                            s.Index = s.idx.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    streams = streams.OrderBy(a => a.idx).ToList();
                }
                ex = 6;
                p.Streams = streams;
                if ((p.Container == "mp4") || (p.Container=="mov"))
                {
                    p.Has64bitOffsets = "0";
                    p.OptimizedForStreaming = "0";
                    m.OptimizedForStreaming = "0";
                    byte[] buffer = new byte[8];
                    FileStream fs = File.OpenRead(filename);
                    fs.Read(buffer, 0, 4);
                    int siz = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3];
                    fs.Seek(siz, SeekOrigin.Begin);
                    fs.Read(buffer, 0, 8);
                    if ((buffer[4] == 'f') && (buffer[5] == 'r') && (buffer[6] == 'e') && (buffer[7] == 'e'))
                    {
                        siz = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]-8;
                        fs.Seek(siz, SeekOrigin.Current);
                        fs.Read(buffer, 0, 8);
                    }
                    if ((buffer[4] == 'm') && (buffer[5] == 'o') && (buffer[6] == 'o') && (buffer[7] == 'v'))
                    {
                        p.OptimizedForStreaming = "1";
                        m.OptimizedForStreaming = "1";
                        siz = (buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]) - 8;

                        buffer = new byte[siz];
                        fs.Read(buffer, 0, siz);
                        int opos ;
                        int oposmax ;
                        if (FindInBuffer("trak", 0, siz, buffer, out opos, out oposmax))
                        {
                            if (FindInBuffer("mdia", opos, oposmax, buffer, out opos, out oposmax))
                            {
                                if (FindInBuffer("minf", opos, oposmax, buffer, out opos, out oposmax))
                                {

                                    if (FindInBuffer("stbl", opos, oposmax, buffer, out opos, out oposmax))
                                    {
                                        if (FindInBuffer("co64", opos, oposmax, buffer, out opos, out oposmax))
                                        {
                                            p.Has64bitOffsets = "1";
                                        }

                                    }
                                }

                            }
                        }
                    }
                }
                ex = 7;
                return m;
            }
            catch (Exception e)
            {
                throw new Exception(ex+":"+e.Message,e);
                
            }
            finally
            {
                mi.Close();
                GC.Collect();
            }
        }