/// <summary> /// Starts a new video/audio file immediatly. Requires that Play has been called. /// </summary> /// <param name="filePath">string</param> public void LoadFile(string filePath) { this.currentFilePath = filePath; _mpv.SetOption("wid", MpvFormat.MPV_FORMAT_INT64, _wid); _mpv.DoMpvCommand("loadfile", filePath); // HACK: wait for video to load System.Threading.Thread.Sleep(1000); this.LoadCurrentPlayingFileLength(); }
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); } } }