public void generateThumbnail(MediaProbe mediaProbe, VideoMetadata video, CancellationToken token, int timeoutSeconds, int nrThumbnails) { video.Thumbnail = null; List<MediaThumb> coverBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds); if (coverBitmaps.Count > 0) { video.Thumbnail = new Thumbnail(coverBitmaps[0].Thumb); } if (coverBitmaps.Count == 0 || nrThumbnails > 1) { List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT, 0, nrThumbnails, 0.025, token, timeoutSeconds, null); if (thumbBitmaps.Count > 0 && coverBitmaps.Count == 0) { video.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb); } } }
public virtual void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { XMPLib.MetaData.ErrorCallbackDelegate errorCallbackDelegate = new XMPLib.MetaData.ErrorCallbackDelegate(errorCallback); //XMPLib.MetaData xmpMetaDataReader = new XMPLib.MetaData(errorCallbackDelegate, null); XMPLib.MetaData xmpMetaDataReader = new XMPLib.MetaData(null, null); try { FileInfo info = new FileInfo(media.Location); info.Refresh(); media.LastModifiedDate = info.LastWriteTime < sqlMinDate ? sqlMinDate : info.LastWriteTime; media.FileDate = info.CreationTime < sqlMinDate ? sqlMinDate : info.CreationTime; media.MimeType = MediaFormatConvert.fileNameToMimeType(media.Name); if (media.SupportsXMPMetadata == false) return; xmpMetaDataReader.open(media.Location, Consts.OpenOptions.XMPFiles_OpenForRead); readXMPMetadata(xmpMetaDataReader, media); } catch (Exception e) { Logger.Log.Error("Cannot read XMP metadata for: " + media.Location, e); media.MetadataReadError = e; } finally { xmpMetaDataReader.Dispose(); xmpMetaDataReader = null; } }
public MediaFilePreviewViewModel2(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; EventAggregator.GetEvent <MediaSelectionEvent>().Subscribe(selectionEvent); MediaProbe = new MediaProbe(); }
public MediaFilePreviewViewModel2(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; EventAggregator.GetEvent<MediaSelectionEvent>().Subscribe(selectionEvent); MediaProbe = new MediaProbe(); }
public YoutubePreviewViewModel(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; EventAggregator.GetEvent<SelectionEvent>().Subscribe(selectionEvent); MediaProbe = new MediaProbe(); }
public YoutubePreviewViewModel(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; EventAggregator.GetEvent <SelectionEvent>().Subscribe(selectionEvent); MediaProbe = new MediaProbe(); }
public VideoPreviewImageProgressViewModel() { WindowTitle = "Video Preview Image"; WindowIcon = "pack://application:,,,/Resources/Icons/videopreview.ico"; mediaProbe = new MediaProbe(); OkCommand.IsExecutable = false; CancelCommand.IsExecutable = true; }
public void generateThumbnail(MediaProbe mediaProbe, AudioMetadata audio, CancellationToken token, int timeoutSeconds, int nrThumbnails) { // get attached images List <MediaThumb> thumbBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds); if (thumbBitmaps.Count > 0) { audio.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb); } }
public void generateThumbnail(MediaProbe mediaProbe, AudioMetadata audio, CancellationToken token, int timeoutSeconds, int nrThumbnails) { // get attached images List<MediaThumb> thumbBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds); if (thumbBitmaps.Count > 0) { audio.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb); } }
public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { AudioMetadata audio = media as AudioMetadata; audio.DurationSeconds = mediaProbe.DurationSeconds; audio.SizeBytes = mediaProbe.SizeBytes; audio.AudioContainer = mediaProbe.Container; audio.AudioCodec = mediaProbe.AudioCodecName; audio.SamplesPerSecond = mediaProbe.SamplesPerSecond; audio.BitsPerSample = (short)(mediaProbe.BytesPerSample * 8); audio.NrChannels = (short)mediaProbe.NrChannels; audio.BitRate = mediaProbe.AudioBitRate == 0 ? (long?)null : mediaProbe.AudioBitRate; List<string> fsMetaData = mediaProbe.MetaData; try { if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL)) { generateThumbnail(mediaProbe, audio, token, timeoutSeconds, 1); } } catch (Exception e) { Logger.Log.Error("Cannot read audio thumbnail: " + audio.Location, e); media.MetadataReadError = e; } if(audio.AudioCodec.ToLower().Equals("mp3") || audio.AudioCodec.ToLower().StartsWith("pcm")) { audio.SupportsXMPMetadata = true; } else { audio.SupportsXMPMetadata = false; } base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds); parseFFMpegMetaData(fsMetaData, audio); }
public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { AudioMetadata audio = media as AudioMetadata; audio.DurationSeconds = mediaProbe.DurationSeconds; audio.SizeBytes = mediaProbe.SizeBytes; audio.AudioContainer = mediaProbe.Container; audio.AudioCodec = mediaProbe.AudioCodecName; audio.SamplesPerSecond = mediaProbe.SamplesPerSecond; audio.BitsPerSample = (short)(mediaProbe.BytesPerSample * 8); audio.NrChannels = (short)mediaProbe.NrChannels; audio.BitRate = mediaProbe.AudioBitRate == 0 ? (long?)null : mediaProbe.AudioBitRate; List <string> fsMetaData = mediaProbe.MetaData; try { if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL)) { generateThumbnail(mediaProbe, audio, token, timeoutSeconds, 1); } } catch (Exception e) { Logger.Log.Error("Cannot read audio thumbnail: " + audio.Location, e); media.MetadataReadError = e; } if (audio.AudioCodec.ToLower().Equals("mp3") || audio.AudioCodec.ToLower().StartsWith("pcm")) { audio.SupportsXMPMetadata = true; } else { audio.SupportsXMPMetadata = false; } base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds); parseFFMpegMetaData(fsMetaData, audio); }
public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { ImageMetadata image = media as ImageMetadata; image.SizeBytes = data.Length; if (FileUtils.isUrl(image.Location)) { image.SupportsXMPMetadata = false; } else { image.SupportsXMPMetadata = true; base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds); } image.ImageContainer = mediaProbe.Container; image.Width = mediaProbe.Width; image.Height = mediaProbe.Height; image.PixelFormat = mediaProbe.PixelFormat; image.BitsPerPixel = (short)mediaProbe.BitsPerPixel; List<String> fsMetaData = mediaProbe.MetaData; try { if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL)) { generateThumbnail(mediaProbe, image, token, timeoutSeconds, 1); } } catch (Exception e) { Logger.Log.Error("Cannot create image thumbnail: " + image.Location, e); media.MetadataReadError = e; } }
public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { ImageMetadata image = media as ImageMetadata; image.SizeBytes = data.Length; if (FileUtils.isUrl(image.Location)) { image.SupportsXMPMetadata = false; } else { image.SupportsXMPMetadata = true; base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds); } image.ImageContainer = mediaProbe.Container; image.Width = mediaProbe.Width; image.Height = mediaProbe.Height; image.PixelFormat = mediaProbe.PixelFormat; image.BitsPerPixel = (short)mediaProbe.BitsPerPixel; List <String> fsMetaData = mediaProbe.MetaData; try { if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL)) { generateThumbnail(mediaProbe, image, token, timeoutSeconds, 1); } } catch (Exception e) { Logger.Log.Error("Cannot create image thumbnail: " + image.Location, e); media.MetadataReadError = e; } }
public static BaseMetadata read(String location, MetadataFactory.ReadOptions options, CancellationToken token, int timeoutSeconds) { BaseMetadata metadata = new UnknownMetadata(FileUtils.getPathWithoutFileName(location)); metadata.Name = Path.GetFileName(location); Logger.Log.Info("Reading metadata for: " + location); int timeoutMs = timeoutSeconds * 1000; Stream data = FileUtils.waitForFileAccess(location, FileAccess.Read, timeoutMs, token); MediaProbe mediaProbe = new MediaProbe(); try { mediaProbe.open(location, token); switch (mediaProbe.MediaType) { case MediaType.AUDIO_MEDIA: { metadata = new AudioMetadata(location, data); AudioFileMetadataReader reader = new AudioFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } case MediaType.IMAGE_MEDIA: { metadata = new ImageMetadata(location, data); ImageFileMetadataReader reader = new ImageFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } case MediaType.VIDEO_MEDIA: { metadata = new VideoMetadata(location, data); VideoFileMetadataReader reader = new VideoFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } default: break; } FileInfo info = new FileInfo(location); info.Refresh(); if (info.Attributes.HasFlag(FileAttributes.ReadOnly)) { metadata.IsReadOnly = true; } if (!options.HasFlag(MetadataFactory.ReadOptions.LEAVE_STREAM_OPENED_AFTER_READ)) { metadata.close(); } } catch (Exception e) { metadata.MetadataReadError = e; } finally { mediaProbe.close(); mediaProbe.Dispose(); } return(metadata); }
public void generateThumbnail(MediaProbe mediaProbe, ImageMetadata image, CancellationToken token, int timeoutSeconds, int nrThumbnails) { // possibly could not seek in video, try to get the first frame in the video List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH, Constants.MAX_THUMBNAIL_HEIGHT, 0, 1, 0, token, timeoutSeconds, null); if (thumbBitmaps.Count > 0) { BitmapSource thumb = thumbBitmaps[0].Thumb; if (image.Orientation.HasValue && image.Orientation.Value != 1) { System.Windows.Media.Transform transform = null; switch (image.Orientation.Value) { case 2: { //Mirror horizontal transform = new System.Windows.Media.MatrixTransform(-1, 0, 0, 1, 0, 0); break; } case 3: { //Rotate 180° transform = new System.Windows.Media.RotateTransform(180); break; } case 4: { //Mirror vertical transform = new System.Windows.Media.MatrixTransform(1, 0, 0, -1, 0, 0); break; } case 5: { //Mirror horizontal, rotate 270° transform = new System.Windows.Media.MatrixTransform(0, -1, -1, 0, 0, 0); break; } case 6: { //Rotate 90° transform = new System.Windows.Media.RotateTransform(90); break; } case 7: { //Mirror horizontal, rotate 90° transform = new System.Windows.Media.MatrixTransform(0, 1, 1, 0, 0, 0); break; } case 8: { //Rotate 270° transform = new System.Windows.Media.RotateTransform(270); break; } default: { Logger.Log.Warn("Unknown orientation for image"); break; } } if (transform != null) { thumb = new TransformedBitmap(thumb, transform); } } image.Thumbnail = new Thumbnail(thumb); } else { image.Thumbnail = null; } }
public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds) { VideoMetadata video = media as VideoMetadata; video.DurationSeconds = mediaProbe.DurationSeconds; video.SizeBytes = mediaProbe.SizeBytes; video.Width = mediaProbe.Width; video.Height = mediaProbe.Height; video.VideoContainer = mediaProbe.Container; video.VideoCodec = mediaProbe.VideoCodecName; video.PixelFormat = mediaProbe.PixelFormat; video.BitsPerPixel = (short)mediaProbe.BitsPerPixel; video.FramesPerSecond = mediaProbe.FrameRate; video.VideoBitRate = mediaProbe.VideoBitRate == 0 ? (long?)null : mediaProbe.VideoBitRate; video.AudioBitRate = mediaProbe.AudioBitRate == 0 ? (long?)null : mediaProbe.AudioBitRate; if (!String.IsNullOrEmpty(mediaProbe.AudioCodecName)) { video.AudioCodec = mediaProbe.AudioCodecName; video.SamplesPerSecond = mediaProbe.SamplesPerSecond; video.BitsPerSample = (short)(mediaProbe.BytesPerSample * 8); video.NrChannels = (short)mediaProbe.NrChannels; } else { video.AudioCodec = null; video.SamplesPerSecond = null; video.BitsPerSample = null; video.NrChannels = null; } List<String> fsMetaData = mediaProbe.MetaData; try { if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL)) { generateThumbnail(mediaProbe, video, token, timeoutSeconds, 1); } } catch (Exception e) { Logger.Log.Error("Cannot create video thumbnail: " + video.Location, e); media.MetadataReadError = e; } if (fsMetaData != null) { video.SupportsXMPMetadata = supportsXMPMetadata(video, fsMetaData); } else { video.SupportsXMPMetadata = false; } base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds); parseFFMpegMetaData(fsMetaData, video); }
public static BaseMetadata read(String location, MetadataFactory.ReadOptions options, CancellationToken token, int timeoutSeconds) { BaseMetadata metadata = new UnknownMetadata(FileUtils.getPathWithoutFileName(location)); metadata.Name = Path.GetFileName(location); Logger.Log.Info("Reading metadata for: " + location); int timeoutMs = timeoutSeconds * 1000; Stream data = FileUtils.waitForFileAccess(location, FileAccess.Read, timeoutMs, token); MediaProbe mediaProbe = new MediaProbe(); try { mediaProbe.open(location, token); switch (mediaProbe.MediaType) { case MediaType.AUDIO_MEDIA: { metadata = new AudioMetadata(location, data); AudioFileMetadataReader reader = new AudioFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } case MediaType.IMAGE_MEDIA: { metadata = new ImageMetadata(location, data); ImageFileMetadataReader reader = new ImageFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } case MediaType.VIDEO_MEDIA: { metadata = new VideoMetadata(location, data); VideoFileMetadataReader reader = new VideoFileMetadataReader(); reader.readMetadata(mediaProbe, data, options, metadata, token, timeoutSeconds); break; } default: break; } FileInfo info = new FileInfo(location); info.Refresh(); if (info.Attributes.HasFlag(FileAttributes.ReadOnly)) { metadata.IsReadOnly = true; } if (!options.HasFlag(MetadataFactory.ReadOptions.LEAVE_STREAM_OPENED_AFTER_READ)) { metadata.close(); } } catch (Exception e) { metadata.MetadataReadError = e; } finally { mediaProbe.close(); mediaProbe.Dispose(); } return metadata; }