public MediaProperties GetProperties(string videoPath) { var videoProperties = new MediaProperties(); ProbeModel.Stream[] streams = GetStream(videoPath); ProbeModel.Stream videoStream = streams[0]; ProbeModel.Stream audioStream = streams[1]; FormatModel.Format format = GetFormat(videoPath); videoProperties.Size = long.Parse(format.size); if (videoStream != null) { videoProperties.VideoFormat = videoStream.codec_name; videoProperties.VideoDuration = GetVideoDuration(format, videoStream); videoProperties.Width = videoStream.width; videoProperties.Height = videoStream.height; videoProperties.FrameRate = GetVideoFramerate(videoStream); videoProperties.Ratio = GetVideoAspectRatio(videoProperties.Width, videoProperties.Height); } if (audioStream != null) { videoProperties.AudioFormat = audioStream.codec_name; videoProperties.AudioDuration = GetAudioDuration(audioStream); } videoProperties.Duration = TimeSpan.FromSeconds(Math.Max(videoProperties.VideoDuration.TotalSeconds, videoProperties.AudioDuration.TotalSeconds)); return(videoProperties); }
public static async Task <VideoItem> GetVideoItem(Media media, string name, string path) { // get basic media properties var mP = new MediaProperties(); mP = await Locator.VLCService.GetVideoProperties(mP, media); // use title decrapifier if (string.IsNullOrEmpty(mP?.ShowTitle)) { mP = TitleDecrapifier.tvShowEpisodeInfoFromString(mP, name); } var video = new VideoItem( name, path, mP.Duration, mP.Width, mP.Height, mP.ShowTitle, mP.Season, mP.Episode ); video.IsAvailable = true; return(video); }
public static MediaInfo FromMediaProperties(MediaProperties props) { MediaInfo info = new MediaInfo(); info.AlbumArtist = props.AlbumArtist; info.AlbumTitle = props.AlbumTitle; info.AlbumTrackCount = props.AlbumTrackCount; info.Artist = props.Artist; info.Genres = props.Genres; info.PlaybackType = props.PlaybackType; info.Subtitle = props.Subtitle; IRandomAccessStreamReference tmbStrmRef; if ((tmbStrmRef = props?.Thumbnail) != null) { using (Stream imgStrm = tmbStrmRef.OpenReadAsync().AsTask().GetAwaiter().GetResult().AsStreamForRead()) { info.Thumbnail = Image.FromStream(imgStrm); } } info.Title = props.Title; info.TrackNumber = props.TrackNumber; return(info); }
public void FFMediaScanner_StatusCallbackTest() { MediaProperties ma = new MediaProperties(Settings.Default.HDRMP4); FFMediaScanner ffsMedia = new FFMediaScanner(); var result = ffsMedia.ExecuteFFMpeg_LogProgress($" -i {ma.MediaFile} -t 2 -y -an -vf cropdetect -f rawvideo NUL ", ma.MediaDuration); Assert.IsFalse(String.IsNullOrEmpty(result.StdErr)); }
public void FFMediaScanner_MEDIA_DETECT_LETTERBOX_NOISE() { var ma = new MediaProperties(Settings.Default.Artifacts_Letterbox_Noise); var scanner = new FFMediaScanner(); scanner.DetectLetterbox(ma); Assert.IsTrue(ma.HasLetterbox); }
public void FFMediaScanner_MEDIA_DETECT_LETTERBOX() { var ma = new MediaProperties("D:\\lbox.mkv"); var scanner = new FFMediaScanner(); scanner.DetectLetterbox(ma); Assert.IsTrue(ma.HasLetterbox); }
public void FFMediaScanner_MEDIA_DETECT_COMBING() { var ma = new MediaProperties(Settings.Default.Artifacts_CleanTelecine); var scanner = new FFMediaScanner(); scanner.DetectCombing(ma); Assert.IsTrue(ma.IsPureFilm); }
private static DomainMedia.MediaProperties MediaPropertiesToModel(MediaProperties mediaProps) { return(new DomainMedia.MediaProperties { Score = mediaProps.Score, Value = mediaProps.Value, Type = (DomainMedia.MediaPropertyType)(int) mediaProps.Type, }); }
private void ConfigureMediaWriter(int width, int height, Guid mediaSubType, short bitCount) { AMMediaType mediaType = new AMMediaType(); VideoInfoHeader videoInfo = new VideoInfoHeader(); // Create the VideoInfoHeader using info from the bitmap videoInfo.BmiHeader.Size = Marshal.SizeOf(typeof(BitmapInfoHeader)); videoInfo.BmiHeader.Width = width; videoInfo.BmiHeader.Height = height; videoInfo.BmiHeader.Planes = 1; // compression thru clrimportant don't seem to be used. Init them anyway videoInfo.BmiHeader.Compression = 0; videoInfo.BmiHeader.ImageSize = 0; videoInfo.BmiHeader.XPelsPerMeter = 0; videoInfo.BmiHeader.YPelsPerMeter = 0; videoInfo.BmiHeader.ClrUsed = 0; videoInfo.BmiHeader.ClrImportant = 0; mediaType.subType = mediaSubType; videoInfo.BmiHeader.BitCount = bitCount; videoInfo.SrcRect = new Rectangle(0, 0, width, height); videoInfo.TargetRect = videoInfo.SrcRect; videoInfo.BmiHeader.ImageSize = width * height * (videoInfo.BmiHeader.BitCount / 8); videoInfo.BitRate = videoInfo.BmiHeader.ImageSize * Constants.VideoFrameRate; videoInfo.BitErrorRate = 0; videoInfo.AvgTimePerFrame = 10000 * 1000 / Constants.VideoFrameRate; mediaType.majorType = MediaType.Video; mediaType.fixedSizeSamples = true; mediaType.temporalCompression = false; mediaType.sampleSize = videoInfo.BmiHeader.ImageSize; mediaType.formatType = FormatType.VideoInfo; mediaType.unkPtr = IntPtr.Zero; mediaType.formatSize = Marshal.SizeOf(typeof(VideoInfoHeader)); // Lock the videoInfo structure, and put the pointer // into the mediatype structure GCHandle handle = GCHandle.Alloc(videoInfo, GCHandleType.Pinned); try { // Set the inputprops using the structures mediaType.formatPtr = handle.AddrOfPinnedObject(); MediaProperties.SetMediaType(mediaType); } finally { handle.Free(); mediaType.formatPtr = IntPtr.Zero; } // Now take the inputprops, and set them on the file writer MediaWriter.SetInputProps(VideoChannelIndex, MediaProperties); }
public MediaInfo GetCurrentMediaInfo() { mediaProperties = CurrentMediaProperties(); if (mediaProperties == null) { return(new MediaInfo()); } return(MediaInfo.FromMediaProperties(mediaProperties)); }
private async Task PlayMediaAsync(MediaProperties item) { if (item == null) { return; } this.CurrentVlcMedia = new Media(this.libVLC, new Uri(item.Path)); this.player.Play(this.CurrentVlcMedia); }
private async void Button_Clicked_1(object sender, EventArgs e) { var mediaProperties = new MediaProperties() { Path = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" }; await this.playback.PlaySingleMediaItemAsync(mediaProperties).ConfigureAwait(false); await this.Navigation.PushAsync(App.Container.Resolve <VideoPlayerPage>()).ConfigureAwait(false); }
public void MediaAttributes_MEDIA_VIDEO_ATTRIBUTES() { MediaProperties ma = new MediaProperties(Settings.Default.Mov6Ch); foreach (MediaStream ms in ma.Streams) { if (ms.StreamType == StreamType.Video) { Assert.IsTrue(ms.CodecFormat.ToLower().Contains("prores")); } } }
/// <summary> /// Plays a single media item. /// Clears the existing playlist. /// </summary> /// <param name="item">Media Item.</param> /// <returns>Task.</returns> public async Task PlaySingleMediaItemAsync(MediaProperties item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } await MainThread.InvokeOnMainThreadAsync(async() => { this.MediaPlaylist.Clear(); this.MediaPlaylist.Add(item); this.CurrentMedia = item; }).ConfigureAwait(false); }
public MediaProperties GetVideoProperties(Media media) { if (media == null) { return(null); } if (!media.isParsed()) { media.parse(); } if (!media.isParsed()) { return(null); } var mP = new MediaProperties(); mP.Title = media.meta(MediaMeta.Title); var showName = media.meta(MediaMeta.ShowName); if (string.IsNullOrEmpty(showName)) { showName = media.meta(MediaMeta.Artist); } if (!string.IsNullOrEmpty(showName)) { mP.ShowTitle = showName; } var episodeString = media.meta(MediaMeta.Episode); if (string.IsNullOrEmpty(episodeString)) { episodeString = media.meta(MediaMeta.TrackNumber); } var episode = 0; if (!string.IsNullOrEmpty(episodeString) && int.TryParse(episodeString, out episode)) { mP.Episode = episode; } var episodesTotal = 0; var episodesTotalString = media.meta(MediaMeta.TrackTotal); if (!string.IsNullOrEmpty(episodesTotalString) && int.TryParse(episodesTotalString, out episodesTotal)) { mP.Episodes = episodesTotal; } return(mP); }
private async void Button_Clicked(object sender, EventArgs e) { var mediaProperties = new MediaProperties() { Path = "https://cdn.discordapp.com/attachments/117839290796343297/816321893912936488/01_Educated_Idiot.mp3", AlbumArt = "https://cdn.discordapp.com/attachments/117839290796343297/824332516872814673/Allroy_Saves.jpg", Artist = "ALL", Title = "Educated Idiot", Album = "Allroy Saves", }; await this.playback.PlaySingleMediaItemAsync(mediaProperties).ConfigureAwait(false); await this.Navigation.PushAsync(App.Container.Resolve <MusicPlayerPage>()).ConfigureAwait(false); }
public MediaProperties GetMusicProperties(Media media) { if (media == null) { return(null); } if (!media.isParsed()) { media.parse(); } if (!media.isParsed()) { return(null); } var mP = new MediaProperties(); mP.AlbumArtist = media.meta(MediaMeta.AlbumArtist); mP.Artist = media.meta(MediaMeta.Artist); mP.Album = media.meta(MediaMeta.Album); mP.Title = media.meta(MediaMeta.Title); var yearString = media.meta(MediaMeta.Date); var year = 0; if (int.TryParse(yearString, out year)) { mP.Year = year; } var durationLong = media.duration(); TimeSpan duration = TimeSpan.FromMilliseconds(durationLong); mP.Duration = duration; var trackNbString = media.meta(MediaMeta.TrackNumber); uint trackNbInt = 0; uint.TryParse(trackNbString, out trackNbInt); mP.Tracknumber = trackNbInt; var discNb = media.meta(MediaMeta.DiscNumber); int discNbInt = 1; int.TryParse(discNb, out discNbInt); mP.DiscNumber = discNbInt; return(mP); }
/// <summary> /// Concat multiple inputVideos. /// </summary> /// <param name="output">Concatenated inputVideos</param> /// <param name="inputVideos">Videos to add</param> /// <returns>Conversion result</returns> public static async Task <bool> Concatenate(string output, params string[] inputVideos) { if (inputVideos.Length <= 1) { throw new ArgumentException("You must provide at least 2 files for the concatenation to work", "inputVideos"); } var mediaInfos = new List <MediaInfo>(); var conversion = new Conversion(); foreach (string inputVideo in inputVideos) { mediaInfos.Add(new MediaInfo(inputVideo)); conversion.AddParameter($"-i \"{inputVideo}\" "); } conversion.AddParameter($"-t 1 -f lavfi -i anullsrc=r=48000:cl=stereo"); conversion.AddParameter($"-filter_complex \""); MediaProperties maxResolutionMedia = mediaInfos.OrderByDescending(x => x.Properties.Width) .First().Properties; for (var i = 0; i < mediaInfos.Count; i++) { conversion.AddParameter( $"[{i}:v]scale={maxResolutionMedia.Width}:{maxResolutionMedia.Height},setdar=dar={maxResolutionMedia.Ratio},setpts=PTS-STARTPTS[v{i}]; "); } for (var i = 0; i < mediaInfos.Count; i++) { if (string.IsNullOrEmpty(mediaInfos[i].Properties.AudioFormat)) { conversion.AddParameter($"[v{i}][{mediaInfos.Count}:a]"); } else { conversion.AddParameter($"[v{i}][{i}:a]"); } } conversion.AddParameter($"concat=n={inputVideos.Length}:v=1:a=1 [v] [a]\" -map \"[v]\" -map \"[a]\""); conversion.SetOutput(output); return(await conversion.Start()); }
static void FormatBinaryInfo(TitleBuilder title, string content, MediaProperties media, long length) { if (media.Dimensions.Width > 0 && media.Dimensions.Height > 0) { title.SetFormat("[ {0}: {1}x{2} ]", content, media.Dimensions.Width, media.Dimensions.Height); title.AppendTime(media.Duration); if (media.HasAudio) { title.Append('♫'); } title.AppendSize(length); } else { title.SetFormat("[ {0} ]", content).AppendSize(length); } }
/// <summary> /// Adds an item to the playlist. /// If it's the first item in the list, autoplay. /// </summary> /// <param name="item">Media Item.</param> /// <returns>Task.</returns> public async Task AddItemToPlaylistAsync(MediaProperties item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } await MainThread.InvokeOnMainThreadAsync(async() => { this.MediaPlaylist.Add(item); // If first item in the list, autoplay it. if (this.MediaPlaylist.Count == 1) { this.CurrentMedia = item; } this.OnPropertyChanged(nameof(this.CanGoBack)); this.OnPropertyChanged(nameof(this.CanGoForward)); }).ConfigureAwait(false); }
/// <summary> /// Loading properties asynchronously. /// </summary> /// <returns>Task represents metadata retrieval operation.</returns> public async Task LoadDataAsync() { if (m_fileProperties == null) { // Get file properties. m_fileProperties = await m_file.GetBasicPropertiesAsync(); } // Read file. using (var stream = await m_file.OpenReadAsync()) { await Task.Run(() => NativeMethods.GetMediaInfoFromStream(stream, out m_info)); // Dictionary used to prevent duplicate property pairs // One case: TSO2 w/ SORTED-ARTIST var metadataDict = new Dictionary <string, string>(); // Get properties. if (MediaProperties.Count < 1 && m_info?.AllProperties != null) { foreach (var property in m_info.AllProperties) { var metadataKey = PropertyNameMap.TryGetValue(property.Key.ToLower(), out string value) ? value : string.Format(UnknownPropertyStringTemplate, property.Key); if (!metadataDict.ContainsKey(metadataKey)) { metadataDict.Add(metadataKey, property.Value); } } var properties = metadataDict.Select(i => new MediaPropertyItem(i.Key, i.Value, Copy)); foreach (var property in properties) { MediaProperties.Add(property); } } } }
/// <summary> /// Method executes when m_Properties.OnMetadataChanged fires. /// /// <para> /// The implementation calls the base class implementation of /// <see cref="Sink_OnMediaPropertiesChanged"/> and then /// fires the <see cref="OnObjectChanged"/> event, followed /// by a call to <see cref="NotifyRootOfChange"/>. /// </para> /// </summary> /// <param name="sender"></param> /// <param name="stateNumber"></param> protected override void Sink_OnMediaPropertiesChanged(MediaProperties sender, int stateNumber) { base.Sink_OnMediaPropertiesChanged(sender, stateNumber); this.NotifyRootOfChange(); }
public async Task <MediaProperties> GetMusicProperties(Media media) { if (Instance == null) { await Initialize(); } await PlayerInstanceReady.Task; if (media == null) { return(null); } if (media.parsedStatus() != ParsedStatus.Done) { var res = await media.parseWithOptionsAsync(ParseFlags.FetchLocal | ParseFlags.Local | ParseFlags.Network, 5000); if (res != ParsedStatus.Done) { return(null); } } var mP = new MediaProperties(); mP.AlbumArtist = media.meta(MediaMeta.AlbumArtist); mP.Artist = media.meta(MediaMeta.Artist); mP.Album = media.meta(MediaMeta.Album); mP.Title = media.meta(MediaMeta.Title); mP.AlbumArt = media.meta(MediaMeta.ArtworkURL); var yearString = media.meta(MediaMeta.Date); var year = 0; if (int.TryParse(yearString, out year)) { mP.Year = year; } var durationLong = media.duration(); TimeSpan duration = TimeSpan.FromMilliseconds(durationLong); mP.Duration = duration; var trackNbString = media.meta(MediaMeta.TrackNumber); uint trackNbInt = 0; uint.TryParse(trackNbString, out trackNbInt); mP.Tracknumber = trackNbInt; var discNb = media.meta(MediaMeta.DiscNumber); if (discNb.Contains("/")) { // if discNb = "1/2" var discNumDen = discNb.Split('/'); if (discNumDen.Any()) { discNb = discNumDen[0]; } } int discNbInt = 1; int.TryParse(discNb, out discNbInt); mP.DiscNumber = discNbInt; var genre = media.meta(MediaMeta.Genre); mP.Genre = genre; return(mP); }
public async Task <MediaProperties> GetVideoProperties(MediaProperties mP, Media media) { if (Instance == null) { await Initialize(); } await PlayerInstanceReady.Task; if (media == null) { return(mP); } if (media.parsedStatus() != ParsedStatus.Done) { var res = await media.parseWithOptionsAsync(ParseFlags.FetchLocal | ParseFlags.Local | ParseFlags.Network, 5000); if (res != ParsedStatus.Done) { return(mP); } } mP.Title = media.meta(MediaMeta.Title); var showName = media.meta(MediaMeta.ShowName); if (string.IsNullOrEmpty(showName)) { showName = media.meta(MediaMeta.Artist); } if (!string.IsNullOrEmpty(showName)) { mP.ShowTitle = showName; } var episodeString = media.meta(MediaMeta.Episode); if (string.IsNullOrEmpty(episodeString)) { episodeString = media.meta(MediaMeta.TrackNumber); } var episode = 0; if (!string.IsNullOrEmpty(episodeString) && int.TryParse(episodeString, out episode)) { mP.Episode = episode; } var episodesTotal = 0; var episodesTotalString = media.meta(MediaMeta.TrackTotal); if (!string.IsNullOrEmpty(episodesTotalString) && int.TryParse(episodesTotalString, out episodesTotal)) { mP.Episodes = episodesTotal; } var videoTrack = media.tracks().FirstOrDefault(x => x.type() == TrackType.Video); if (videoTrack != null) { mP.Width = videoTrack.width(); mP.Height = videoTrack.height(); } var durationLong = media.duration(); var duration = TimeSpan.FromMilliseconds(durationLong); mP.Duration = duration; return(mP); }
public static MediaProperties tvShowEpisodeInfoFromString(string title) { if (string.IsNullOrEmpty(title)) { return(null); } title = title.ToLower(); bool successfulSearch = false; var mP = new MediaProperties(); int stringLength = title.Length; if (stringLength < 6) { return(null); } try { // Search for s01e10. for (int i = 0; i < stringLength - 5; i++) { if (title.ElementAt(i) != 's' || !isDigit(title.ElementAt(i + 1)) || !isDigit(title.ElementAt(i + 2)) || title.ElementAt(i + 3) != 'e' || !isDigit(title.ElementAt(i + 4)) || !isDigit(title.ElementAt(i + 5))) { // Inverted "if" statement to reduce nesting. continue; } string seasonString = title.ElementAt(i + 1).ToString() + title.ElementAt(i + 2).ToString(); string episodeString; if (title.Length > i + 6 && isDigit(title.ElementAt(i + 6))) { episodeString = title.ElementAt(i + 4).ToString() + title.ElementAt(i + 5).ToString() + title.ElementAt(i + 6).ToString(); } else { episodeString = title.ElementAt(i + 4).ToString() + title.ElementAt(i + 5).ToString(); } string tvShowName = i > 0 ? title.Substring(0, i) : Strings.UnknownShow; if (tvShowName != null) { tvShowName = CapitalizedString(Decrapify(tvShowName)); } string episodeName = stringLength > i + 4 ? title.Substring(0, i + 6) : null; if (episodeName != null) { episodeName = Decrapify(episodeName); } // Fill the MediaProperties object var season = 0; if (int.TryParse(seasonString, out season)) { mP.Season = season; } var episode = 0; if (int.TryParse(episodeString, out episode)) { mP.Episode = episode; } if (!string.IsNullOrEmpty(tvShowName)) { mP.ShowTitle = tvShowName; } if (!string.IsNullOrEmpty(episodeName)) { mP.Title = CapitalizedString(episodeName); } successfulSearch = true; } // search for 0x00 if (!successfulSearch) { for (int i = 0; i < stringLength - 4; i++) { if (!isDigit(title.ElementAt(i)) || title.ElementAt(i + 1) != 'x' || !isDigit(title.ElementAt(i + 2)) || !isDigit(title.ElementAt(i + 3))) { // Inverted "if" statement to reduce nesting. continue; } string seasonString = title.ElementAt(i).ToString(); string episodeString = title.ElementAt(i + 2).ToString() + title.ElementAt(i + 3).ToString(); string tvShowName = i > 0 ? title.Substring(0, i) : Strings.UnknownShow; ; if (tvShowName != null) { tvShowName = CapitalizedString(Decrapify(tvShowName)); } string episodeName = stringLength > i + 4 ? title.Substring(0, i + 4) : null; if (episodeName != null) { episodeName = Decrapify(episodeName); } var season = 0; if (int.TryParse(seasonString, out season)) { mP.Season = season; } // 'episode' will never be null according to conditions above, so checking for it is not needed. var episode = 0; if (int.TryParse(episodeString, out episode)) { mP.Episode = episode; } if (!string.IsNullOrEmpty(tvShowName)) { mP.ShowTitle = tvShowName; } if (!string.IsNullOrEmpty(episodeName)) { mP.Title = CapitalizedString(episodeName); } successfulSearch = true; } } } catch { } return(successfulSearch ? mP : null); }
public void MediaAttributes_MEDIA_ATMOS_TIMECODE() { MediaProperties ma = new MediaProperties(Settings.Default.AtmosESTC); Assert.IsTrue(ma.HasAtmos); }
public void MediaAttributes_MEDIA_HDR_ATTRIBUTES() { MediaProperties mi = new MediaProperties(Settings.Default.HDRMP4); Assert.IsTrue(mi.HasHDR); }
private void OnMediaChanged(MediaControlSession sender, MediaPropertiesChangedEventArgs args) { mediaProperties = sender.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); CurrentMediaChanged(sender, MediaInfo.FromMediaProperties(mediaProperties)); }
internal CameraViewModel(MediaProperties cam) { MediaProps = cam; MediaProps.PropertyChanged += CameraChangedEvent; GetUwpCaptureElement(); }
private bool Initialize(string destinationFileName, VideoQuality videoQuality) { IWMProfileManager profileManagerTemp = null; IWMProfile profile = null; int inputCount = 0; Guid inputTypeId; bool success = false; try { #region Initialize Properties CurrentSampleIndex = 0; CurrentSampleTimeStamp = 0; VideoChannelIndex = -1; MediaWriterConfigured = false; MediaWriterIsWriting = false; #endregion #region Create ProfileManager WMUtils.WMCreateProfileManager(out profileManagerTemp); IWMProfileManager2 profileManager = (IWMProfileManager2)profileManagerTemp; #endregion #region Configure ProfileManager profileManager.SetSystemProfileVersion(WMVersion.V8_0); #endregion #region Load Profile switch (videoQuality) { case VideoQuality.Kbps128: profileManager.LoadProfileByData(Wilke.Interactive.Drone.Control.Properties.Resources.VideoProfile128kbps, out profile); break; case VideoQuality.Kbps256: profileManager.LoadProfileByData(Wilke.Interactive.Drone.Control.Properties.Resources.VideoProfile256kbps, out profile); break; } #endregion #region Create Writer WMUtils.WMCreateWriter(IntPtr.Zero, out mediaWriter); #endregion #region Configure Writer MediaWriter.SetProfile(profile); MediaWriter.GetInputCount(out inputCount); // Find the first video input on the writer for (int index = 0; index < inputCount; index++) { // Get the properties of channel #index MediaWriter.GetInputProps(index, out mediaProperties); // Read the type of the channel MediaProperties.GetType(out inputTypeId); // If it is video, we are done if (inputTypeId == MediaType.Video) { VideoChannelIndex = index; break; } } // Didn't find a video channel if (VideoChannelIndex == -1) { throw new Exception("Profile does not accept video input"); } MediaWriter.SetOutputFilename(destinationFileName); #endregion success = true; } catch { throw; } return(success); }