Exemplo n.º 1
0
        /// <summary>
        /// Create a new instance of mplayer class.
        /// </summary>
        /// <param name="wid">Window ID that mplayer should attach itself</param>
        /// <param name="libMpvPath">The full filepath to libmpv. </param>
        /// <param name="loadMplayer">If true mplayer will immediately be loaded and you should not attempt to
        /// play any files until MplayerRunning is true.</param>
        /// <param name="positionUpdateInterval">Interval of periodical position updates</param>
        public MpvPlayer(long wid, string libMpvPath, bool loadMplayer, TimeSpan positionUpdateInterval)
        {
            this._wid           = wid;
            this._fullscreen    = false;
            this.MplayerRunning = false;

            _mpv = new Mpv(libMpvPath);
            _mpv.Initialize();

            this.CurrentStatus = MediaStatus.Stopped;

            // This timer will send an event every second with the current video postion when video
            // is in play mode.
            this._currentPostionTimer          = new System.Timers.Timer(positionUpdateInterval.TotalMilliseconds);
            this._currentPostionTimer.Elapsed += new ElapsedEventHandler(_currentPostionTimer_Elapsed);
            this._currentPostionTimer.Enabled  = false;

            if (loadMplayer)
            {
                Action caller = new Action(InitializeMplayer);
                caller.BeginInvoke(null, null);
            }
        }
Exemplo n.º 2
0
        public void Execute()
        {
            // As work around can run mpv commandline and parse output
            // mpv video_name.mp4 --vo null -ao null --frames 1 -v



            /*
             * Reads the values of the video (width, heigth, fps...) and stores them
             * into file_values.
             *
             * Returns (False,AUDIO) if the file is not a video (with AUDIO the number
             * of audio tracks)
             *
             * Returns (True,0) if the file is a right video file
             */
            _mpv = new Mpv(libmpvPath);

            // Must be set before initializeation
            _mpv.SetOption("frames", MpvFormat.MPV_FORMAT_INT64, 148);

            _mpv.Initialize();

            _mpv.SetOption("wid", MpvFormat.MPV_FORMAT_INT64, -1);
            _mpv.SetOption("vo", MpvFormat.MPV_FORMAT_STRING, "null");
            _mpv.SetOption("ao", MpvFormat.MPV_FORMAT_STRING, "null");

            _mpv.DoMpvCommand("loadfile", filePath);

            // HACK: wait for video to load
            System.Threading.Thread.Sleep(1000);
            //_mpv.SetProperty ("pause", MpvFormat.MPV_FORMAT_STRING, "yes");

            _Width       = _mpv.GetPropertyInt("width");
            _Height      = _mpv.GetPropertyInt("height");
            _AspectRatio = _mpv.GetPropertyFloat("video-aspect");

            int bits = _mpv.GetPropertyInt("audio-bitrate");

            //int bytes = Bits2Bytes (bits);
            //int kb = Bytes2Kilobytes (bytes);
            //_AudioBitrate = (int)Math.Round (bits / 1024m, 0);
            _AudioBitrate = bits;
            _AudioRate    = _mpv.GetPropertyInt("audio-params/samplerate");
            _Length       = _mpv.GetPropertyInt("duration");

            //_fps = _mpv.GetPropertyInt ("container-fps");
            _fps = _mpv.GetPropertyInt("fps");
            _mpv.TryGetPropertyInt("video-bitrate", out _VideoBitrate);

            string videoFormat = _mpv.GetProperty("video-format");

            if (!string.IsNullOrWhiteSpace(videoFormat))
            {
                _Video = true;
            }


            _AudioList    = new List <int> ();
            _AudioTracks  = new List <AudioTrackInfo> ();
            _SubtitleList = new List <SubtitlesInfo> ();

            int trackCount = _mpv.GetPropertyInt("track-list/count");

            foreach (int i in Enumerable.Range(0, trackCount))
            {
                string trackType = _mpv.GetProperty($"track-list/{i}/type");
                int    trackId   = _mpv.GetPropertyInt($"track-list/{i}/id");
                string name;

                _mpv.TryGetProperty($"track-list/{i}/title", out name);
                string language;
                _mpv.TryGetProperty($"track-list/{i}/lang", out language);

                if (trackType == "audio")
                {
                    _AudioList.Add(trackId);

                    var info = new AudioTrackInfo()
                    {
                        ID       = trackId,
                        Name     = name,
                        Language = language
                    };

                    _AudioTracks.Add(info);
                }
                else if (trackType == "sub")
                {
                    var info = new SubtitlesInfo()
                    {
                        ID       = trackId,
                        Name     = name,
                        Language = language
                    };

                    _SubtitleList.Add(info);
                }
            }


            if (_AspectRatio == 0.0)
            {
                _AspectRatio = ((float)_Width / (float)_Height);
                if (_AspectRatio <= 1.5)
                {
                    _AspectRatio = (ScreenAspectRatio.FourThree);
                }
            }
        }