Exemplo n.º 1
0
        public async Task GenerateVideosAsync(CancellationToken cancellationToken)
        {
            await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official);

            List <Store.Media> videos = await _storeContext.Medias.AsQueryable()
                                        .Where(x => x.MediaType == Store.MediaType.Video)
                                        .ToListAsync(cancellationToken);

            var todo = videos.Count;

            var videoPreview = @"H:\Drive\Moments\System\VideoPreview";

            foreach (Store.Media video in videos)
            {
                todo--;

                var filename = _mediaBlobStore.GetFilename(new MediaBlobData
                {
                    Directory = video.Folder,
                    Filename  = video.Filename,
                    Type      = MediaBlobType.Media
                });

                try
                {
                    var outfile = Path.Combine(videoPreview, $"720P_{video.Id}.mp4");

                    if (!File.Exists(outfile))
                    {
                        var inputLength = new FileInfo(filename).Length / 1024 / 1024;

                        await _videoProcessing.ConvertTo720Async(filename, outfile, cancellationToken);

                        Console.WriteLine($"{todo} - Video created: {Path.GetFileName(outfile)}");

                        var outLength = new FileInfo(outfile).Length / 1024 / 1024;

                        Console.WriteLine($"{inputLength} --> {outLength} (-{100.0 / inputLength * outLength}%)");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error in Media: {video.Id}. --> {ex.Message}");
                }
            }
        }
Exemplo n.º 2
0
        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);
        }