Example #1
0
        private string GetFolder(MediaProcessorContext context)
        {
            switch (context.Options.SaveMedia.SaveMode)
            {
            case SaveMediaMode.CreateNew:
                if (context.Metadata.DateTaken.HasValue)
                {
                    return(string.Join("/",
                                       "New",
                                       context.Metadata.DateTaken.Value.Year.ToString(),
                                       context.Metadata.DateTaken.Value.ToString("MMMM", new CultureInfo("en-US"))));
                }
                else
                {
                    return("New/Unknown_Date");
                }

            case SaveMediaMode.KeepInSource:
                var directoryName = Path.GetDirectoryName(context.File.Id);
                var relativePath  = directoryName.Replace(context.File.BasePath, "");

                if (string.IsNullOrWhiteSpace(relativePath))
                {
                    relativePath = "/";
                }

                return(relativePath.Replace("\\", "/"));

            default:
                throw new ApplicationException($"Invalid SaveMediaMode: {context.Options.SaveMedia.SaveMode}");
            }
        }
Example #2
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            IEnumerable <MediaFace> faces = new List <MediaFace>();

            if (context.FaceData is { })
Example #3
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var media = new Media
            {
                Id            = Guid.NewGuid(),
                MediaType     = context.MediaType,
                DateTaken     = context.Metadata.DateTaken,
                ImageUniqueId = context.Metadata.ImageId,
                GeoLocation   = context.Metadata.GeoLocation,
                Size          = GetSize(context),
                Folder        = GetFolder(context),
                Filename      = Path.GetFileName(context.File.Id),
                Dimension     = context.Metadata.Dimension,
                VideoInfo     = context.VideoInfo,
                OriginalHash  = ComputeHash(context),
                CameraId      = await GetCameraIdAsync(context, cancellationToken),
                Source        = new MediaSource
                {
                    Identifier = context.File.Id,
                    Type       = context.File.Source.ToString(),
                    ImportedAt = DateTime.UtcNow
                }
            };

            if (context.Thumbnails is { })
Example #4
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            if (context.FaceData != null)
            {
                double distance = 0.4;

                foreach (FaceData face in context.FaceData)
                {
                    try
                    {
                        Guid?personId = await _faceDetectionService.PredictPersonAsync(
                            new PredictPersonRequest
                        {
                            Distance = distance,
                            Encoding = face.Encoding
                        }, cancellationToken);

                        if (personId.HasValue)
                        {
                            face.PersonId          = personId;
                            face.DistanceThreshold = distance;
                            face.RecognitionType   = FaceRecognitionType.Computer;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     context.Thumbnails = await _thumbnailService.GenerateAllThumbnailAsync(
         context.Image,
         cancellationToken);
 }
Example #6
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var   stream = new MemoryStream(context.OriginalData !);
            Image image  = await Image.LoadAsync(stream);

            context.Image = _imageTransformService.AutoOrient(image);
        }
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     if (!context.Metadata.DateTaken.HasValue)
     {
         context.Metadata.DateTaken = _dateTakenParser.Parse(
             Path.GetFileNameWithoutExtension(context.File.Id));
     }
 }
        public async Task ExecuteAsync(MediaProcessorContext context, CancellationToken cancellationToken)
        {
            ExtractVideoDataResult?videoData = await _videoProcessingService.ExtractVideoDataAsync(
                context.File.Id,
                cancellationToken);

            context.Image     = Image.Load(videoData.ImageData);
            context.Metadata  = videoData.Meta;
            context.VideoInfo = videoData.Info;
            context.Size      = videoData.Size;
        }
Example #9
0
 public async virtual Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     foreach (string taskName in Tasks)
     {
         IMediaProcessorTask instance = _taskFactory.GetTask(taskName);
         Log.Information("Execute Task {Name}", taskName);
         await instance.ExecuteAsync(context, cancellationToken);
     }
 }
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            MemoryStream stream = new MemoryStream();
            await context.Image.SaveAsJpegAsync(stream, cancellationToken);

            stream.Position = 0;

            context.WebImage = _webPImageConverter.ConvertToWebP(stream).ToByteArray();
        }
Example #11
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            MemoryStream stream = new MemoryStream();
            await context.Image.SaveAsJpegAsync(stream, cancellationToken);

            stream.Position = 0;

            IEnumerable <FaceDetectionResponse> detectedFaces = await _faceDetectionService
                                                                .DetectFacesAsync(stream, cancellationToken);

            IEnumerable <FaceData> faceData = detectedFaces.Select(f =>
                                                                   new FaceData
            {
                Box      = f.Box,
                Encoding = f.Encoding,
                Id       = Guid.NewGuid()
            }).ToList();

            IEnumerable <BoxExtractionInput> inputs = faceData.Select(f =>
                                                                      new BoxExtractionInput
            {
                Box = f.Box,
                Id  = f.Id
            });

            stream.Position = 0;

            IEnumerable <BoxExtractionResult> faceImages = await _boxExtractorService
                                                           .ExtractBoxesAsync(stream, inputs, ThumbnailSizeName.M, default);

            ILookup <Guid, BoxExtractionResult> faceLookup = faceImages.ToLookup(x => x.Id);

            foreach (FaceData face in faceData)
            {
                ThumbnailResult thumb = faceLookup[face.Id].Single().Thumbnail;

                face.Thumbnail = new MediaThumbnail
                {
                    Id         = Guid.NewGuid(),
                    Data       = thumb.Data,
                    Dimensions = thumb.Dimensions,
                    Format     = thumb.Format,
                    Size       = thumb.Size
                };
            }

            context.FaceData = faceData;
        }
Example #12
0
        public async Task ScanByMediaIdAsync(Guid mediaId, CancellationToken cancellationToken)
        {
            Media media = await _mediaService.GetByIdAsync(mediaId, cancellationToken);

            Stream stream = _mediaService.GetMediaStream(media);

            var context = new MediaProcessorContext
            {
                Media = media,
                Image = await Image.LoadAsync(stream)
            };

            await _flow.ExecuteAsync(context, cancellationToken);
        }
Example #13
0
        public Task ExecuteAsync(MediaProcessorContext context, CancellationToken cancellationToken)
        {
            if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Delete)
            {
                File.Delete(context.File.Id);
            }
            else if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Move)
            {
                //TODO: Move
            }
            else if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Replace)
            {
                //TODO: Overwrite source
            }

            return(Task.CompletedTask);
        }
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var filename          = _mediaService.GetFilename(context.Media, MediaFileType.Original);
            var convertedFilename = _mediaService.GetFilename(context.Media, MediaFileType.Video720);

            if (File.Exists(convertedFilename))
            {
                File.Delete(convertedFilename);
            }

            await _videoProcessingService.ConvertTo720Async(
                filename,
                convertedFilename,
                cancellationToken);
        }
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var filename    = _mediaService.GetFilename(context.Media, MediaFileType.Original);
            var gifFilename = _mediaService.GetFilename(context.Media, MediaFileType.VideoGif);

            if (File.Exists(gifFilename))
            {
                File.Delete(gifFilename);
            }

            await _videoProcessingService.GeneratePreviewGifAsync(
                filename,
                gifFilename,
                cancellationToken);
        }
Example #16
0
        public async virtual Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            foreach (string taskName in Tasks)
            {
                IMediaProcessorTask instance = _taskFactory.GetTask(taskName);
                Log.Information("Execute Task {Name}", taskName);

                try
                {
                    await instance.ExecuteAsync(context, cancellationToken);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error executing Task {Name}", taskName);
                    throw;
                }
            }
        }
Example #17
0
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     context.Metadata = await _metadataExtractor.GetMetadataAsync(context.Image, default);
 }