Ejemplo n.º 1
0
        public void UploadVideo(RemoteFileInfo header)
        {
            // Tmp File Path
            var tmp_filepath = "tmpin" + header.IdVideo + ".mp4";
            // Copy header Stream
            MemoryStream input = new MemoryStream();
            header.Stream.CopyTo(input);

            // Close header Stream
            header.Stream.Dispose();

            Engine.Dbo.Encode encodeBase = new Engine.Dbo.Encode(Engine.Dbo.Encode.Definition.None, header.InputFormat, header.IdVideo, true);
            Engine.Dbo.Encode encode480 = new Engine.Dbo.Encode(Engine.Dbo.Encode.Definition.p480, header.InputFormat, header.IdVideo, false);
            Engine.Dbo.Encode encode720 = new Engine.Dbo.Encode(Engine.Dbo.Encode.Definition.p720, header.InputFormat, header.IdVideo, false);
            Engine.Dbo.Encode encode1080 = new Engine.Dbo.Encode(Engine.Dbo.Encode.Definition.p1080, header.InputFormat, header.IdVideo, false);

            encodeBase.Id = Engine.BusinessManagement.Encode.AddEncode(encodeBase);
            encode480.Id = Engine.BusinessManagement.Encode.AddEncode(encode480);
            encode720.Id = Engine.BusinessManagement.Encode.AddEncode(encode720);
            encode1080.Id = Engine.BusinessManagement.Encode.AddEncode(encode1080);

            // Create Tmp file
            var fileStream = File.Create(tmp_filepath);
            input.Seek(0, SeekOrigin.Begin);
            input.CopyTo(fileStream);
            fileStream.Close();

            // Upload thumbnail (First Frame)
            mongo.UploadThumbnail(tmp_filepath, header.IdVideo.ToString());
            // Upload base stream
            mongo.UploadStream(tmp_filepath, encodeBase.Id.ToString());

            // Destroy Tmp file
            File.Delete(tmp_filepath);

            /*
            Stream s = new MemoryStream();
            Format.ConvertTo(input, inputExtension, s, NReco.VideoConverter.Format.mp4, NReco.VideoConverter.FrameSize.hd480);
            mongo.UploadStream(s, idEncode480.ToString());
            encode480.IsEncode = true;
            Engine.BusinessManagement.Encode.UpdateEncode(encode480);

            s = new MemoryStream();
            Format.ConvertTo(input, Path.GetExtension(file.FileName).Substring(1), s, NReco.VideoConverter.Format.mp4, NReco.VideoConverter.FrameSize.hd720);
            mongo.UploadStream(s, idEncode720.ToString());
            encode720.IsEncode = true;
            Engine.BusinessManagement.Encode.UpdateEncode(encode720);

            s = new MemoryStream();
            Format.ConvertTo(input, Path.GetExtension(file.FileName).Substring(1), s, NReco.VideoConverter.Format.mp4, NReco.VideoConverter.FrameSize.hd1080);
            mongo.UploadStream(s, idEncode1080.ToString());
            encode1080.IsEncode = true;
            Engine.BusinessManagement.Encode.UpdateEncode(encode1080);
            return true;
             */
        }
Ejemplo n.º 2
0
        public static void UploadVideo(RemoteFileInfo file)
        {
            ChannelFactory<IUpload> httpFactory =
              new ChannelFactory<IUpload>(
                new BasicHttpBinding(),
                new EndpointAddress(
                  "http://localhost:988/Upload"));

            IUpload httpProxy =
              httpFactory.CreateChannel();

            httpProxy.UploadVideo(file);
        }
Ejemplo n.º 3
0
        public ActionResult Upload(UploadViewModel model)
        {
            if (!model.Tags.Split(' ').All(x => x.Length <= 20))
                ModelState.AddModelError("Tags", "Tags must be 20 charaters long and contains only number, letter and -");
            if (ModelState.IsValid && model.File != null)
            {
                var user = UserManager.FindById(User.Identity.GetUserId());
                string fileExtension = Path.GetExtension(model.File.FileName).Substring(1);
                try
                {
                    RemoteFileInfo fileInfo = new RemoteFileInfo();
                    fileInfo.Stream = model.File.InputStream;
                    fileInfo.InputFormat = fileExtension;

                    Engine.Dbo.Video video = new Engine.Dbo.Video()
                    {
                        Title = model.Title,
                        Description = model.Description,
                        User = Engine.BusinessManagement.User.FindUser(user.T_UserId),
                        UploadDate = DateTime.Now,
                    };

                    fileInfo.IdVideo = Engine.BusinessManagement.Video.AddVideo(video);

                    Engine.BusinessManagement.Tag.AddTags(model.Tags.Split().Distinct().Select(x => new Engine.Dbo.Tag() { Name = x }), fileInfo.IdVideo);

                    ClientManager.UploadVideo(fileInfo);
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    return RedirectToAction("Index", "Upload");
                }

                TempData["videoUploaded"] = true;
                return RedirectToAction("Display", "Account", new { nickname = user.UserName });
            }

            return View("Index", model);
        }