public StorageVideo(StorageFile file, BasicProperties basic, VideoProperties props, MediaEncodingProfile profile) : base(file, basic) { _fullRectangle = new Rect(0, 0, props.GetWidth(), props.GetHeight()); _basic = basic; Properties = props; Profile = profile; videoDuration = props.Duration.TotalMilliseconds; originalSize = (long)basic.Size; originalWidth = (int)props.GetWidth(); originalHeight = (int)props.GetHeight(); originalBitrate = bitrate = (int)props.Bitrate; //(trackBitrate / 100000 * 100000); if (bitrate > 900000) { bitrate = 900000; } LoadPreview(); }
public static async Task <TLPhotoSizeBase> GetVideoThumbnailAsync(StorageFile file, VideoProperties props, VideoTransformEffectDefinition effect) { double originalWidth = props.GetWidth(); double originalHeight = props.GetHeight(); if (effect != null && !effect.CropRectangle.IsEmpty) { file = await CropAsync(file, effect.CropRectangle); originalWidth = effect.CropRectangle.Width; originalHeight = effect.CropRectangle.Height; } TLPhotoSizeBase result; var fileLocation = new TLFileLocation { VolumeId = TLLong.Random(), LocalId = TLInt.Random(), Secret = TLLong.Random(), DCId = 0 }; var desiredName = string.Format("{0}_{1}_{2}.jpg", fileLocation.VolumeId, fileLocation.LocalId, fileLocation.Secret); var desiredFile = await FileUtils.CreateTempFileAsync(desiredName); using (var fileStream = await OpenReadAsync(file)) using (var outputStream = await desiredFile.OpenAsync(FileAccessMode.ReadWrite)) { var decoder = await BitmapDecoder.CreateAsync(fileStream); double ratioX = (double)90 / originalWidth; double ratioY = (double)90 / originalHeight; double ratio = Math.Min(ratioX, ratioY); uint width = (uint)(originalWidth * ratio); uint height = (uint)(originalHeight * ratio); var transform = new BitmapTransform(); transform.ScaledWidth = width; transform.ScaledHeight = height; transform.InterpolationMode = BitmapInterpolationMode.Linear; if (effect != null) { transform.Flip = effect.Mirror == MediaMirroringOptions.Horizontal ? BitmapFlip.Horizontal : BitmapFlip.None; } var pixelData = await decoder.GetSoftwareBitmapAsync(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage); var propertySet = new BitmapPropertySet(); var qualityValue = new BitmapTypedValue(0.77, PropertyType.Single); propertySet.Add("ImageQuality", qualityValue); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outputStream); encoder.SetSoftwareBitmap(pixelData); await encoder.FlushAsync(); result = new TLPhotoSize { W = (int)width, H = (int)height, Size = (int)outputStream.Size, Type = string.Empty, Location = fileLocation }; } return(result); }