示例#1
0
        public IActionResult Upload(IFormFile file, string id)
        {
            string duration = string.Empty;
            Bundle <UploadViewModel> model = new Bundle <UploadViewModel>(new UploadViewModel {
                Id = id
            });

            if (file != null)
            {
                var tempVideoPath = CreateTempVideoPath(model.PageModel.Id);
                UploadFile(file, tempVideoPath);

                IMediaInfo mediaInfo = MediaInfo.Get(tempVideoPath).Result;

                var outputPath = CreateVideoPath(model.PageModel.Id);

                model.PageModel.ThumbnailOptions = new VideoThumbnail[3];

                CreateThumbnails(tempVideoPath, outputPath, Convert.ToInt32(mediaInfo.Duration.TotalSeconds), model.PageModel.ThumbnailOptions);
                ConvertAndSaveVideo(mediaInfo, outputPath, id);

                model.PageModel.VideoTitle = Path.GetFileNameWithoutExtension(file.FileName);
                model.PageModel.Duration   = mediaInfo.Duration.ToString();

                string videoUrl     = $"{_htmlRootVideoPath}/{id}/video{FileExtensions.Mp4}";
                string thumbnailUrl = $"{_htmlRootVideoPath}/{id}/thumbnail{FileExtensions.Png}";

                _videoService.CreateVideo(id, videoUrl, thumbnailUrl, mediaInfo.Duration,
                                          Path.GetFileNameWithoutExtension(file.FileName), model.PageModel.Year, string.Empty, string.Empty, User.Identity.Name);
            }

            return(new JsonResult(model));
        }