Example #1
0
        public VideoParam AdjustVideoParam(VideoAdjusterParam videoAdjusterParam, string mediaContainer, IVideoSize videoSize)
        {
            var exceptionList = new List <VideoFormatException>();
            int size          = videoSize.Square();

            string container    = AdjustMediaContainer(videoAdjusterParam.MediaContainer, mediaContainer, exceptionList);
            string videoCodec   = AdjustVideoCodec(mediaContainer, videoAdjusterParam.VideoCodec, exceptionList);
            int    videoBitrate = AdjustVideoBitrate(videoAdjusterParam.VideoBitrate, size, exceptionList);
            int    videoWidth   = AdjustVideoWidth(videoSize.Width, exceptionList);
            int    videoHeight  = AdjustVideoHeight(videoSize.Height, exceptionList);
            double frameRate    = AdjustFrameRate(videoAdjusterParam.FrameRate, videoAdjusterParam.FrameRateMode, exceptionList);

            IVideoSize videoRotateSize = _adjustmentVideoMetadata.AdjustVideoRotateSize(videoWidth, videoHeight, videoAdjusterParam.VideoRotation);
            string     videoProfile    = _adjustmentVideoMetadata.AdjustVideoProfile(mediaContainer, videoAdjusterParam.VideoProfile);
            int        keyFrameRate    = _adjustmentVideoMetadata.AdjustKeyFrameRate(videoAdjusterParam.KeyFrameRate);

            CheckForException(exceptionList);

            VideoParam adjustVideoParam = CreateParam(container,
                                                      videoCodec,
                                                      videoProfile,
                                                      videoBitrate,
                                                      videoRotateSize.Width,
                                                      videoRotateSize.Height,
                                                      frameRate,
                                                      keyFrameRate,
                                                      videoAdjusterParam.VideoRotation);

            return(adjustVideoParam);
        }
Example #2
0
        public void CreateProcessedVideosTest()
        {
            //Arrange
            const string newContainer = "newContainer";
            const string contentType  = "contentType";

            var processedVideoBuilder = new Mock <IProcessedVideoBuilder>();
            var processedVideoList    = new ProcessedVideoList(processedVideoBuilder.Object);

            var videoParam      = new VideoAdjusterParam();
            var audioParam      = new AudioAdjusterParam();
            var processedVideo1 = new DomainProcessedVideo();
            var processedVideo2 = new DomainProcessedVideo();

            var size1    = new Mock <IVideoSize>();
            var size2    = new Mock <IVideoSize>();
            var sizeList = new List <IVideoSize> {
                size1.Object, size2.Object
            };

            processedVideoBuilder.Setup(m => m.BuildProcessedVideo(videoParam, audioParam, newContainer, size1.Object, contentType)).Returns(processedVideo1);
            processedVideoBuilder.Setup(m => m.BuildProcessedVideo(videoParam, audioParam, newContainer, size2.Object, contentType)).Returns(processedVideo2);

            //Act
            IEnumerable <DomainProcessedVideo> list = processedVideoList.CreateProcessedVideos(videoParam, audioParam, newContainer, sizeList, contentType);

            //Assert
            Assert.AreEqual(sizeList.Count, list.Count());
            Assert.IsTrue(list.Any(p => p == processedVideo1));
            Assert.IsTrue(list.Any(p => p == processedVideo1));
        }
        public VideoAdjusterParam CreateVideoParam(IVideoMetadata videoMetadata)
        {
            CheckVideoStream(videoMetadata.VideoStreamsCount);
            int keyFrameRate = ParseKeyFrameRate(videoMetadata.VideoFormatSettingsGOP);
            VideoAdjusterParam videoParam = CreateVideoParam(videoMetadata, keyFrameRate);

            return(videoParam);
        }
Example #4
0
 public bool VideoParamCompare(VideoAdjusterParam videoAdjusterParam, VideoParam videoParam, string newContainer, IVideoSize videoSize)
 {
     return(videoAdjusterParam.VideoCodec == videoParam.VideoCodec &&
            ((newContainer == MetadataConstant.Mp4Container && videoAdjusterParam.VideoProfile == videoParam.VideoProfile) || (MetadataConstant.Mp4Container != newContainer)) &&
            videoAdjusterParam.VideoBitrate == videoParam.VideoBitrate &&
            videoSize.Width == videoParam.VideoWidth &&
            videoSize.Height == videoParam.VideoHeight &&
            videoAdjusterParam.FrameRate == videoParam.FrameRate &&
            videoAdjusterParam.KeyFrameRate == videoParam.KeyFrameRate);
 }
        public DomainProcessedVideo BuildProcessedVideo(VideoAdjusterParam videoAdjusterParam, AudioAdjusterParam audioAdjusterParam, string newContainer, IVideoSize videoSize, string contentType)
        {
            VideoParam           videoParam     = _videoAdjuster.AdjustVideoParam(videoAdjusterParam, newContainer, videoSize);
            AudioParam           audioParam     = _audioAdjuster.AdjustAudioParam(audioAdjusterParam, newContainer, videoSize);
            bool                 isVideoCopy    = _comparator.VideoParamCompare(videoAdjusterParam, videoParam, newContainer, videoSize);
            bool                 isAudioCopy    = _comparator.AudioParamCompare(audioAdjusterParam, audioParam);
            DomainProcessedVideo processedVideo = CreateProcessedVideo(videoParam, audioParam, isVideoCopy, isAudioCopy, contentType);

            return(processedVideo);
        }
Example #6
0
        public void Initialize()
        {
            const string mediaContainer = "mediaContainer";
            const string videoCodec     = "videoCodec";
            const string videoProfile   = "videoProfile";
            const int    videoBitrate   = 10000;
            const int    width          = 150;
            const int    height         = 100;
            const double frameRate      = 25;
            const int    keyFrameRate   = 10;

            const string audioCodec   = "audioCodec";
            const int    audioBitrate = 500;

            _comparator = new Comparator();

            _videoSize = new VideoSize(width, height);

            _videoAdjusterParam = new VideoAdjusterParam()
            {
                MediaContainer = mediaContainer,
                VideoCodec     = videoCodec,
                VideoProfile   = videoProfile,
                VideoBitrate   = videoBitrate,
                FrameRate      = frameRate,
                KeyFrameRate   = keyFrameRate
            };

            _videoParam = new VideoParam()
            {
                MediaContainer = mediaContainer,
                VideoCodec     = videoCodec,
                VideoProfile   = videoProfile,
                VideoBitrate   = videoBitrate,
                VideoWidth     = width,
                VideoHeight    = height,
                FrameRate      = frameRate,
                KeyFrameRate   = keyFrameRate
            };

            _audioAdjusterParam = new AudioAdjusterParam()
            {
                AudioCodec   = audioCodec,
                AudioBitrate = audioBitrate
            };

            _audioParam = new AudioParam()
            {
                AudioCodec   = audioCodec,
                AudioBitrate = audioBitrate
            };
        }
Example #7
0
        public void Initialize()
        {
            _videoAdjusterParam = new VideoAdjusterParam()
            {
                MediaContainer = "mediaContainer",
                VideoCodec     = "videoCodec",
                VideoBitrate   = 12345,
                VideoProfile   = "videoProfile",
                FrameRate      = 25,
                KeyFrameRate   = 10,
                FrameRateMode  = "frameRateMode",
                VideoRotation  = 270
            };

            _adjustmentVideoParam = new Mock <IAdjustmentVideoMetadata>();
            _videoAdjuster        = new VideoAdjuster(_adjustmentVideoParam.Object);
        }
        public List <DomainProcessedVideo> Generate(IVideoMetadata videoMetadata)
        {
            int width  = videoMetadata.VideoWidth;
            int height = videoMetadata.VideoHeight;

            List <IVideoSize>  sizeList   = _resolutionCalculator.Calculate(width, height);
            VideoAdjusterParam videoParam = _multimediaAdjusterParamFactory.CreateVideoParam(videoMetadata);
            AudioAdjusterParam audioParam = _multimediaAdjusterParamFactory.CreateAudioParam(videoMetadata);
            IEnumerable <DomainProcessedVideo> mp4ProcessedVideos  = _processedVideoList.CreateProcessedVideos(videoParam, audioParam, MetadataConstant.Mp4Container, sizeList, ContentType.Mp4Content);
            IEnumerable <DomainProcessedVideo> webmProcessedVideos = _processedVideoList.CreateProcessedVideos(videoParam, audioParam, MetadataConstant.WebmContainer, sizeList, ContentType.WebmContent);

            var list = new List <DomainProcessedVideo>();

            list.AddRange(mp4ProcessedVideos);
            list.AddRange(webmProcessedVideos);

            return(list);
        }
        public void BuildProcessedVideoTest()
        {
            //Arrange
            const string newContainer       = "newContainer";
            const string contentType        = "contentType";
            const bool   isVideoParamEquals = true;
            const bool   isAudioParamEquals = false;
            const int    videoWidth         = 2134;

            var videoAdjusterParam = new VideoAdjusterParam();
            var audioAdjusterParam = new AudioAdjusterParam();

            var videoParam = new VideoParam()
            {
                VideoWidth = videoWidth, MediaContainer = newContainer
            };
            var audioParam   = new AudioParam();
            var outputFormat = string.Format("{0}x{1}", videoParam.MediaContainer, videoParam.VideoWidth);

            var videoSize          = new Mock <IVideoSize>();
            var videoParamAdjuster = new Mock <IVideoAdjuster>();
            var audioParamAdjuster = new Mock <IAudioAdjuster>();
            var comparator         = new Mock <IComparator>();

            videoParamAdjuster.Setup(m => m.AdjustVideoParam(videoAdjusterParam, newContainer, videoSize.Object)).Returns(videoParam);
            audioParamAdjuster.Setup(m => m.AdjustAudioParam(audioAdjusterParam, newContainer, videoSize.Object)).Returns(audioParam);
            comparator.Setup(m => m.VideoParamCompare(videoAdjusterParam, videoParam, newContainer, videoSize.Object)).Returns(isVideoParamEquals);
            comparator.Setup(m => m.AudioParamCompare(audioAdjusterParam, audioParam)).Returns(isAudioParamEquals);

            var builder = new ProcessedVideoBuilder(videoParamAdjuster.Object, audioParamAdjuster.Object, comparator.Object);

            //Act
            var processedVideo = builder.BuildProcessedVideo(videoAdjusterParam, audioAdjusterParam, newContainer, videoSize.Object, contentType);

            //Assert
            Assert.AreEqual(videoParam, processedVideo.VideoParam);
            Assert.AreEqual(audioParam, processedVideo.AudioParam);
            Assert.AreEqual(isVideoParamEquals, processedVideo.IsVideoCopy);
            Assert.AreEqual(isAudioParamEquals, processedVideo.IsAudioCopy);
            Assert.AreEqual(outputFormat, processedVideo.OutputFormat);
            Assert.AreEqual(contentType, processedVideo.ContentType);
        }
        public void GenerateProcessedVedeoTest()
        {
            //Arrange
            var calculator         = new Mock <IResolutionCalculator>();
            var paramFactory       = new Mock <IMultimediaAdjusterParamFactory>();
            var processedVideoList = new Mock <IProcessedVideoList>();

            var processedVideoGenerator = new ProcessedVideoGenerator(calculator.Object, paramFactory.Object, processedVideoList.Object);

            var videoParam = new VideoAdjusterParam();
            var audioParam = new AudioAdjusterParam();

            var sizeList           = new List <IVideoSize>();
            var mp4ProcessedVideos = new List <DomainProcessedVideo> {
                new DomainProcessedVideo()
            };
            var webmProcessedVideos = new List <DomainProcessedVideo> {
                new DomainProcessedVideo()
            };

            var metadata = new Mock <IVideoMetadata>();

            metadata.Setup(p => p.VideoWidth).Returns(2345);
            metadata.Setup(p => p.VideoHeight).Returns(345);

            calculator.Setup(m => m.Calculate(metadata.Object.VideoWidth, metadata.Object.VideoHeight)).Returns(sizeList);
            paramFactory.Setup(m => m.CreateVideoParam(metadata.Object)).Returns(videoParam);
            paramFactory.Setup(m => m.CreateAudioParam(metadata.Object)).Returns(audioParam);

            processedVideoList.Setup(m => m.CreateProcessedVideos(videoParam, audioParam, MetadataConstant.Mp4Container, sizeList, ContentType.Mp4Content)).Returns(mp4ProcessedVideos);
            processedVideoList.Setup(m => m.CreateProcessedVideos(videoParam, audioParam, MetadataConstant.WebmContainer, sizeList, ContentType.WebmContent)).Returns(webmProcessedVideos);

            //Act
            List <DomainProcessedVideo> list = processedVideoGenerator.Generate(metadata.Object);

            //Assert
            Assert.AreEqual(mp4ProcessedVideos.Count + webmProcessedVideos.Count, list.Count);
            Assert.IsTrue(mp4ProcessedVideos.All(p => list.Any(procVid => procVid == p)));
            Assert.IsTrue(webmProcessedVideos.All(p => list.Any(procVid => procVid == p)));
        }
 public IEnumerable <DomainProcessedVideo> CreateProcessedVideos(VideoAdjusterParam videoAdjusterParam, AudioAdjusterParam audioAdjusterParam, string newContainer, List <IVideoSize> sizeList,
                                                                 string contentType)
 {
     return(sizeList.Select(videoSize => _processedVideoBuilder.BuildProcessedVideo(videoAdjusterParam, audioAdjusterParam, newContainer, videoSize, contentType)));
 }