public void AdjustContainerTest()
        {
            //Arrange
            const string myContainer         = "myContainer";
            const string anotherContainer    = "anotherContainer";
            var          serviceConfigurator = new MetadataServiceConfigurator(myContainer, null, null, null, null);

            var metadata1 = new VideoMetadata()
            {
                Container = myContainer
            };
            var metadata2 = new VideoMetadata()
            {
                Container = anotherContainer
            };
            var metadataWithoutContainer = new VideoMetadata()
            {
                Container = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadataWithoutContainer);

            //Act
            var container1 = metadataService1.AdjustContainer();
            var container2 = metadataService2.AdjustContainer();

            //Act & Assert
            CustomAssert.IsThrown <MediaFormatException>(() => metadataService3.AdjustContainer());

            //Assert
            Assert.AreEqual(myContainer, container1);
            Assert.AreEqual(myContainer, container2);
        }
        public void AdjustVideoKeyFrameSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadataKeyFrame0 = new VideoMetadata()
            {
                VideoKeyFrame = metadataConfigurator.MinKeyFrame - 1
            };
            var metadataKeyFrameMore60 = new VideoMetadata()
            {
                VideoKeyFrame = metadataConfigurator.MaxKeyFrame + 1
            };
            var metadataKeyFrame = new VideoMetadata()
            {
                VideoKeyFrame = 30
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadataKeyFrame0);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataKeyFrameMore60);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataKeyFrame);

            //Act;
            var keyFrame0      = metadataService1.AdjustKeyFrame();
            var keyFrameMore60 = metadataService2.AdjustKeyFrame();
            var keyFrame       = metadataService3.AdjustKeyFrame();

            //Assert
            Assert.AreEqual(metadataConfigurator.KeyFrame, keyFrame0);
            Assert.AreEqual(metadataConfigurator.KeyFrame, keyFrameMore60);
            Assert.AreEqual(metadataKeyFrame.VideoKeyFrame, keyFrame);
        }
Exemple #3
0
        public void CheckCorrectAudioValueListTest()
        {
            //Arrange
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMediaInfo
            {
                AudioBitRate       = serviceConfigurator.AudioBps720P1Channel,
                AudioChannels      = (int)AudioChannel.One,
                AudioFormat        = "AAC",
                AudioFormatProfile = "LC",
                VideoWidth         = 4096,
                VideoHeight        = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

            //Act
            metadataService.AdjustAudioBps();
            metadataService.AdjustAudioCodec();
            metadataService.AdjustAudioProfile();

            //Assert
            Assert.IsTrue(metadataService.CorrectAudioValueList.All((b) => b.Value));
        }
Exemple #4
0
        public void AdjustVideoKeyFrameSuccessTest()
        {
            //Arrange
            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);
            int myKeyFrame          = serviceConfigurator.MaxKeyFrame - 1;

            var metadataKeyFrame0 = new VideoMediaInfo
            {
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MinKeyFrame - 1)
            };
            var metadataKeyFrameMore60 = new VideoMediaInfo
            {
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MaxKeyFrame + 1)
            };
            var metadataKeyFrame = new VideoMediaInfo
            {
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", myKeyFrame)
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadataKeyFrame0);
            var metadataService2 = new MetadataService(serviceConfigurator, metadataKeyFrameMore60);
            var metadataService3 = new MetadataService(serviceConfigurator, metadataKeyFrame);

            //Act;
            int keyFrame0      = metadataService1.AdjustKeyFrame();
            int keyFrameMore60 = metadataService2.AdjustKeyFrame();
            int keyFrame       = metadataService3.AdjustKeyFrame();

            //Assert
            Assert.AreEqual(serviceConfigurator.KeyFrame, keyFrame0);
            Assert.AreEqual(serviceConfigurator.KeyFrame, keyFrameMore60);
            Assert.AreEqual(myKeyFrame, keyFrame);
        }
Exemple #5
0
        public void GetMjpegStringWithNumFrameMoreDurationTest()
        {
            //Arrange
            const string sourceFilePath      = "source file path";
            const string destinationPath     = "my path";
            const string destinationFileName = "my file";

            string destinationFilePath = Path.Combine(destinationPath, destinationFileName);
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMediaInfo
            {
                VideoDuration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1,
                VideoWidth    = 4096,
                VideoHeight   = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName);

            string ffmpegStr = "-i \"{0}\" -f image2 -ss {1} -frames:v 1 -y \"{2}.jpg\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      sourceFilePath,
                                      0,
                                      destinationFilePath);

            //Act
            string str = stringBuilder.GetStringForScreenshot();

            //Assert
            Assert.AreEqual(ffmpegStr, str);
        }
Exemple #6
0
        public void CheckCorrectVideoValueListTest()
        {
            //Arrange
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMediaInfo
            {
                AudioBitRate           = serviceConfigurator.AudioBps720P1Channel,
                AudioChannels          = (int)AudioChannel.One,
                AudioFormat            = serviceConfigurator.AudioCodec.Codec,
                AudioFormatProfile     = serviceConfigurator.AudioCodec.DefaultProfile,
                VideoBitRate           = serviceConfigurator.VideoBps1920X1080,
                VideoFormat            = serviceConfigurator.VideoCodec.Codec,
                VideoFormatProfile     = serviceConfigurator.VideoCodec.DefaultProfile,
                VideoFrameRate         = serviceConfigurator.MaxFps - 1,
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.KeyFrame),
                VideoWidth             = 4096,
                VideoHeight            = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

            //Act
            metadataService.AdjustVideoWidth();
            metadataService.AdjustVideoHeight();
            metadataService.AdjustKeyFrame();
            metadataService.AdjustVideoBps();
            metadataService.AdjustVideoCodec();
            metadataService.AdjustVideoFps();
            metadataService.AdjustVideoProfile();

            //Assert
            Assert.IsTrue(metadataService.CorrectVideoValueList.All((b) => b.Value));
        }
        public void AdjustVideoFpsSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1 = new VideoMetadata()
            {
                VideoFps = 29.970
            };

            var metadata2 = new VideoMetadata()
            {
                VideoFps = metadataConfigurator.MinFps - 1
            };

            var metadata3 = new VideoMetadata()
            {
                VideoFps = metadataConfigurator.MaxFps + 1
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata2);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata3);

            //Act
            var adjustedFps1 = metadataService1.AdjustVideoFps();

            //Act & Assert
            CustomAssert.IsThrown <MediaFormatException>(() => metadataService2.AdjustVideoFps());
            CustomAssert.IsThrown <MediaFormatException>(() => metadataService3.AdjustVideoFps());

            //Assert
            Assert.AreEqual(metadata1.VideoFps, adjustedFps1);
        }
Exemple #8
0
        public void CreateScreenshotTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            StartScreenshot(serviceConfigurator, filePathes);
        }
Exemple #9
0
        public void CreateScreenshotTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            StartScreenshot(serviceConfigurator, filePathes);
        }
        public void AdjustAudioProfileTest()
        {
            //Arrange
            const string myCodec1       = "myCodec1";
            const string myCodec2       = "myCodec2";
            const string anotherProfile = "anotherProfile";
            const string firstProfile   = "firstProfile";

            var audioCodec = new CodecData(myCodec1, null, firstProfile);

            var supportedAudioCodecs = new List <CodecData>()
            {
                audioCodec,
                new CodecData(myCodec2, null)
            };

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, audioCodec, supportedAudioCodecs);

            var metadata1 = new VideoMetadata()
            {
                AudioCodec   = myCodec1,
                AudioProfile = firstProfile
            };
            var metadata2 = new VideoMetadata()
            {
                AudioCodec   = myCodec1,
                AudioProfile = anotherProfile
            };
            var metadata3 = new VideoMetadata()
            {
                AudioCodec   = myCodec2,
                AudioProfile = anotherProfile
            };
            var metadataWithoutProfile = new VideoMetadata()
            {
                AudioCodec   = myCodec1,
                AudioProfile = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutProfile);

            //Act
            var profile1 = metadataService1.AdjustAudioProfile();
            var profile2 = metadataService2.AdjustAudioProfile();
            var profile3 = metadataService3.AdjustAudioProfile();
            var profile4 = metadataService4.AdjustAudioProfile();

            //Assert
            Assert.AreEqual(firstProfile, profile1);
            Assert.AreEqual(firstProfile, profile2);
            Assert.AreEqual(anotherProfile, profile3);
            Assert.AreEqual(firstProfile, profile4);
        }
Exemple #11
0
        private void StartScreenshot(MetadataServiceConfigurator serviceConfigurator, string[] filePathes)
        {
            int    count        = 0;
            double avgEncodeFps = 0;
            var    errorVideos  = new List <string>();
            var    allSw        = new Stopwatch();
            var    decodeSw     = new Stopwatch();

            foreach (string filePath in filePathes)
            {
                allSw.Restart();
                Trace.WriteLine(String.Format("\n-------------Start decode file: {0}-------------\n", filePath));

                try
                {
                    string         destinationFileName = GetDestinationFileName(filePath);
                    var            mediaInfo           = new MediaInfoWrapper();
                    var            metadataInfo        = new VideoMetadataInfo(mediaInfo);
                    VideoMediaInfo metadata            = metadataInfo.GetMetadata(filePath);
                    var            metadataService     = new MetadataService(serviceConfigurator, metadata);
                    var            stringBuilder       = new FfmpegService(metadataService, filePath, _destinationPath, destinationFileName);
                    var            ffmpeg       = new Ffmpeg(stringBuilder);
                    string         ffmpegString = stringBuilder.GetStringForScreenshot();

                    WriteFileInfo(ffmpegString, metadata);

                    decodeSw.Restart();
                    ffmpeg.StartScreenshotProcess();
                    allSw.Stop();
                    decodeSw.Stop();
                    WriteFinishProcess(decodeSw.Elapsed, allSw.Elapsed, ffmpeg.EncodeFps);

                    avgEncodeFps += ffmpeg.EncodeFps;
                    count++;
                }
                catch (MediaFormatException ex)
                {
                    string errorMessage = String.Format("Error File:\t\t{0}.\nError Param:\t\t{1}", filePath, ex.Message);
                    Trace.WriteLine(errorMessage);
                    errorVideos.Add(errorMessage);
                }
                catch (ExternalProcessException ex)
                {
                    string errorMessage = String.Format("Error File:\t\t{0}.\nFfmpeg return:\t\t{1}\n{2}", filePath, ex.Result, ex.Arguments);
                    Trace.WriteLine(errorMessage);
                    errorVideos.Add(errorMessage);
                }
                finally
                {
                    Trace.WriteLine(String.Format("\n-------------Finish decode file: {0}-------------\n", filePath));
                }
            }

            avgEncodeFps = avgEncodeFps / count;
            WriteFinishInfo(avgEncodeFps, count, errorVideos);
        }
Exemple #12
0
        public void TheoraEncodeTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);
            var videoCodec = new CodecData(FfmpegConstant.TheoraCodec, FfmpegConstant.TheoraCodecLib);
            var audioCodec = new CodecData(FfmpegConstant.VorbisCodec, FfmpegConstant.VorbisCodecLib);

            var serviceConfigurator = new MetadataServiceConfigurator(FfmpegConstant.OggContainer, FfmpegConstant.OggFfmpegContainer, videoCodec, audioCodec);

            StartEncode(serviceConfigurator, filePathes);
        }
Exemple #13
0
        public void Mp4EncodeTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);
            var      videoCodec = new CodecData(FfmpegConstant.AvcCodec, FfmpegConstant.AvcCodecLib, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcBaselineProfile);
            var      audioCodec = new CodecData(FfmpegConstant.AacCodec, FfmpegConstant.AacCodecLib);

            var serviceConfigurator = new MetadataServiceConfigurator(FfmpegConstant.Mp4Container, FfmpegConstant.Mp4FfmpegContainer, videoCodec, audioCodec);

            StartEncode(serviceConfigurator, filePathes);
        }
Exemple #14
0
        public void TheoraEncodeTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);
            var      videoCodec = new CodecData(FfmpegConstant.TheoraCodec, FfmpegConstant.TheoraCodecLib);
            var      audioCodec = new CodecData(FfmpegConstant.VorbisCodec, FfmpegConstant.VorbisCodecLib);

            var serviceConfigurator = new MetadataServiceConfigurator(FfmpegConstant.OggContainer, FfmpegConstant.OggFfmpegContainer, videoCodec, audioCodec);

            StartEncode(serviceConfigurator, filePathes);
        }
Exemple #15
0
        public void Mp4EncodeTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);
            var videoCodec = new CodecData(FfmpegConstant.AvcCodec, FfmpegConstant.AvcCodecLib, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcBaselineProfile);
            var audioCodec = new CodecData(FfmpegConstant.AacCodec, FfmpegConstant.AacCodecLib);

            var serviceConfigurator = new MetadataServiceConfigurator(FfmpegConstant.Mp4Container, FfmpegConstant.Mp4FfmpegContainer, videoCodec, audioCodec);

            StartEncode(serviceConfigurator, filePathes);
        }
Exemple #16
0
        public void GetMp4StringFromIncorrectMetadataTest()
        {
            //Arrange
            const string sourceFilePath      = "source file path";
            const string destinationPath     = "my path";
            const string destinationFileName = "my file";

            string destinationFilePath = Path.Combine(destinationPath, destinationFileName);
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var metadata = new VideoMediaInfo
            {
                GeneralFormat          = "MPEG-PS",
                AudioBitRate           = serviceConfigurator.AudioBps720P1Channel + 1,
                AudioChannels          = (int)AudioChannel.One,
                AudioFormat            = "AC-3",
                AudioFormatProfile     = null,
                VideoBitRate           = serviceConfigurator.VideoBps1920X1080 + 1,
                VideoFormat            = "MPEG Video",
                VideoFrameRate         = serviceConfigurator.MaxFps - 1,
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MaxKeyFrame + 1),
                VideoFormatProfile     = "High",
                VideoWidth             = 4096,
                VideoHeight            = 2304,
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName);

            string ffmpegStr = "-i \"{0}\" -f {1} -vcodec {2} -b:v {3} -r {4} -g {5} -s {6}x{7} -profile {8} -acodec {9} -b:a {10} -quality good -cpu-used 0 -threads {11} -y \"{12}.{13}\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      sourceFilePath,
                                      metadataService.ContainerForFfmpeg,
                                      metadataService.VideoCodecLib,
                                      serviceConfigurator.VideoBps1920X1080,
                                      serviceConfigurator.MaxFps - 1,
                                      serviceConfigurator.KeyFrame,
                                      metadata.VideoWidth,
                                      metadata.VideoHeight,
                                      serviceConfigurator.VideoCodec.DefaultProfile,
                                      metadataService.AudioCodecLib,
                                      serviceConfigurator.AudioBps720P1Channel,
                                      Environment.ProcessorCount,
                                      destinationFilePath,
                                      serviceConfigurator.FfmpegContainer);

            //Act
            string str = stringBuilder.GetStringForEncoder();

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        public void CorectAudioValueListFillingTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            //Act
            var metadataService = new MetadataService(metadataConfigurator, null);

            //Assert
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.AudioBps, false)));
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.AudioCodec, false)));
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.AudioProfile, false)));
        }
        public void AdjustAudioCodecTest()
        {
            //Arrange
            const string myCodec1     = "myCodec1";
            const string myCodec2     = "myCodec2";
            const string anotherCodec = "anotherCodec";

            var audioCodec = new CodecData(myCodec1, null);

            var supportedAudioCodecs = new List <CodecData>()
            {
                audioCodec,
                new CodecData(myCodec2, null)
            };

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, audioCodec, supportedAudioCodecs);

            var metadata1 = new VideoMetadata()
            {
                AudioCodec = myCodec1
            };
            var metadata2 = new VideoMetadata()
            {
                AudioCodec = myCodec2
            };
            var metadata3 = new VideoMetadata()
            {
                AudioCodec = anotherCodec
            };
            var metadataWithoutCodec = new VideoMetadata()
            {
                AudioCodec = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutCodec);

            //Act
            var codec1 = metadataService1.AdjustAudioCodec();
            var codec2 = metadataService2.AdjustAudioCodec();
            var codec3 = metadataService3.AdjustAudioCodec();
            var codec4 = metadataService4.AdjustAudioCodec();

            //Assert
            Assert.AreEqual(myCodec1, codec1);
            Assert.AreEqual(myCodec2, codec2);
            Assert.AreEqual(myCodec1, codec3);
            Assert.AreEqual(null, codec4);
        }
Exemple #19
0
        public void CreateScreenshotTest()
        {
            Directory.CreateDirectory(DestinationPath);
            var filePathes           = Directory.GetFiles(SourcePath);
            var videoCodec           = new CodecData("VP8", "libvpx");
            var audioCodec           = new CodecData("Vorbis", "libvorbis");
            var supportedAudioCodecs = new List <CodecData>()
            {
                audioCodec
            };
            var serviceConfigurator = new MetadataServiceConfigurator("WebM", "webm", videoCodec, audioCodec, supportedAudioCodecs);

            StartScreenshot(serviceConfigurator, filePathes);
        }
        public void AdjustVideoProfileTest()
        {
            //Arrange
            const string myCodec        = "myCodec";
            const string anotherProfile = "anotherProfile";
            const string firstProfile   = "firstProfile";
            const string secondProfile  = "secondProfile";

            var videoCodec = new CodecData(myCodec, null, firstProfile, secondProfile);

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, videoCodec, null, null);

            var metadata1 = new VideoMetadata()
            {
                VideoCodec   = myCodec,
                VideoProfile = firstProfile
            };
            var metadata2 = new VideoMetadata()
            {
                VideoCodec   = myCodec,
                VideoProfile = secondProfile
            };
            var metadata3 = new VideoMetadata()
            {
                VideoCodec   = myCodec,
                VideoProfile = anotherProfile
            };
            var metadataWithoutCodec = new VideoMetadata()
            {
                VideoCodec   = myCodec,
                VideoProfile = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutCodec);

            //Act
            var profile1 = metadataService1.AdjustVideoProfile();
            var profile2 = metadataService2.AdjustVideoProfile();
            var profile3 = metadataService3.AdjustVideoProfile();
            var profile4 = metadataService4.AdjustVideoProfile();

            //Assert
            Assert.AreEqual(firstProfile, profile1);
            Assert.AreEqual(secondProfile, profile2);
            Assert.AreEqual(firstProfile, profile3);
            Assert.AreEqual(firstProfile, profile4);
        }
Exemple #21
0
        public void CreateScreenshotTest()
        {
            Directory.CreateDirectory(DestinationPath);
            var filePathes = Directory.GetFiles(SourcePath);
            var videoCodec = new CodecData("VP8", "libvpx");
            var audioCodec = new CodecData("Vorbis", "libvorbis");
            var supportedAudioCodecs = new List<CodecData>()
                                           {
                                               audioCodec
                                           };
            var serviceConfigurator = new MetadataServiceConfigurator("WebM", "webm", videoCodec, audioCodec, supportedAudioCodecs);

            StartScreenshot(serviceConfigurator, filePathes);
        }
Exemple #22
0
        public void Mp4EncodeTest()
        {
            Directory.CreateDirectory(DestinationPath);
            var filePathes = Directory.GetFiles(SourcePath);
            var videoCodec = new CodecData("AVC", "libx264", "Main", "Main", "Baseline");
            var audioCodec = new CodecData("MPEG Audio", "libmp3lame", "Layer 3", "Layer 3");
            var supportedAudioCodecs = new List<CodecData>()
                                           {
                                               audioCodec,
                                               new CodecData("AAC", null)
                                           };
            var serviceConfigurator = new MetadataServiceConfigurator("MPEG-4", "mp4", videoCodec, audioCodec, supportedAudioCodecs);

            StartEncode(serviceConfigurator, filePathes);
        }
Exemple #23
0
        public void Mp4EncodeTest()
        {
            Directory.CreateDirectory(DestinationPath);
            var filePathes           = Directory.GetFiles(SourcePath);
            var videoCodec           = new CodecData("AVC", "libx264", "Main", "Main", "Baseline");
            var audioCodec           = new CodecData("MPEG Audio", "libmp3lame", "Layer 3", "Layer 3");
            var supportedAudioCodecs = new List <CodecData>()
            {
                audioCodec,
                new CodecData("AAC", null)
            };
            var serviceConfigurator = new MetadataServiceConfigurator("MPEG-4", "mp4", videoCodec, audioCodec, supportedAudioCodecs);

            StartEncode(serviceConfigurator, filePathes);
        }
        public void AdjustHeightVideoSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMetadata()
            {
                Height = 100
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            var adjustedHeight = metadataService.AdjustVideoHeight();

            //Assert
            Assert.AreEqual(metadata.Height, adjustedHeight);
        }
        public void AdjustWidthVideoSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMetadata()
            {
                Width = 100
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            var adjustedwidth = metadataService.AdjustVideoWidth();

            //Assert
            Assert.AreEqual(metadata.Width, adjustedwidth);
        }
Exemple #26
0
        public void Mp4EncodeWithDifferentResolutionTest()
        {
            Directory.CreateDirectory(_destinationPath);
            string[] filePathes = Directory.GetFiles(_sourcePath);
            var      videoCodec = new CodecData(FfmpegConstant.AvcCodec, FfmpegConstant.AvcCodecLib, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcMainProfile, FfmpegConstant.AvcBaselineProfile);
            var      audioCodec = new CodecData(FfmpegConstant.AacCodec, FfmpegConstant.AacCodecLib);

            var resolutions         = new[] { Int16.MaxValue, 500, 400, 100, 10 };
            var serviceConfigurator = new MetadataServiceConfigurator(FfmpegConstant.Mp4Container, FfmpegConstant.Mp4FfmpegContainer, videoCodec, audioCodec);

            foreach (int resolution in resolutions)
            {
                serviceConfigurator.MaxWidth  = resolution;
                serviceConfigurator.MaxHeight = resolution;
                StartEncode(serviceConfigurator, filePathes, String.Format("{0}_", resolution));
            }
        }
        public void AdjustHeightVideoSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMetadata()
            {
                Height = 100
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            var adjustedHeight = metadataService.AdjustVideoHeight();

            //Assert
            Assert.AreEqual(metadata.Height, adjustedHeight);
        }
        public void AdjustWidthVideoSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMetadata()
                               {
                                   Width = 100
                               };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            var adjustedwidth = metadataService.AdjustVideoWidth();

            //Assert
            Assert.AreEqual(metadata.Width, adjustedwidth);
        }
Exemple #29
0
        public void CorectVideoValueListFillingTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            //Act
            var metadataService = new MetadataService(metadataConfigurator, null);

            //Assert
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.Width, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.Height, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.VideoBps, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.VideoCodec, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.VideoFps, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.VideoKeyFrame, false)));
            Assert.IsTrue(metadataService.CorrectVideoValueList.Contains(new KeyValuePair <MetadataValue, bool>(MetadataValue.VideoProfile, false)));
        }
Exemple #30
0
        public void CheckCorrectContainerTest()
        {
            //Arrange
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMediaInfo
            {
                GeneralFormat = serviceConfigurator.Container
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

            //Act
            metadataService.AdjustContainer();

            //Assert
            Assert.IsTrue(metadataService.CorrectContainer);
        }
Exemple #31
0
        public void AdjustWidthVideoSuccessTest()
        {
            //Arrange
            const int width = 35;
            var       metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMediaInfo
            {
                VideoWidth = width * metadataConfigurator.VideoSizeMul
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            int adjustedwidth = metadataService.AdjustVideoWidth();

            //Assert
            Assert.AreEqual(metadata.VideoWidth, adjustedwidth);
        }
Exemple #32
0
        public void AdjustHeightVideoSuccessTest()
        {
            //Arrange
            const int height = 23;
            var       metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata = new VideoMediaInfo
            {
                VideoHeight = height * metadataConfigurator.VideoSizeMul
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            int adjustedHeight = metadataService.AdjustVideoHeight();

            //Assert
            Assert.AreEqual(metadata.VideoHeight, adjustedHeight);
        }
Exemple #33
0
        public void GetMp4StringFromMetadataWithMp2Test()
        {
            //Arrange
            const string sourceFilePath      = "source file path";
            const string destinationPath     = "my path";
            const string destinationFileName = "my file";

            string destinationFilePath = Path.Combine(destinationPath, destinationFileName);
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var metadata = new VideoMediaInfo
            {
                GeneralFormat          = "MPEG-4",
                AudioBitRate           = 152000,
                AudioChannels          = (int)AudioChannel.Two,
                AudioFormat            = "MPEG Audio",
                AudioFormatProfile     = "Layer 2",
                VideoBitRate           = 2500000,
                VideoFormat            = "AVC",
                VideoFrameRate         = 24,
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MaxKeyFrame),
                VideoFormatProfile     = "Baseline",
                VideoWidth             = 4096,
                VideoHeight            = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName);

            string ffmpegStr = "-i \"{0}\" -f mp4 -vcodec copy -acodec {1} -b:a {2} -quality good -cpu-used 0 -threads {3} -y \"{4}.{5}\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      sourceFilePath,
                                      metadataService.AudioCodecLib,
                                      metadata.AudioBitRate,
                                      Environment.ProcessorCount,
                                      destinationFilePath,
                                      serviceConfigurator.FfmpegContainer);

            //Act
            string str = stringBuilder.GetStringForEncoder();

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
Exemple #34
0
        public void AdjustHeightMoreConfigureMaxHeightTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            metadataConfigurator.MaxHeight = 100 * metadataConfigurator.VideoSizeMul;

            var metadata = new VideoMediaInfo
            {
                VideoHeight = metadataConfigurator.MaxHeight + metadataConfigurator.VideoSizeMul
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            int adjustedHeight = metadataService.AdjustVideoHeight();

            //Assert
            Assert.AreEqual(metadataConfigurator.MaxHeight, adjustedHeight);
        }
        public void AdjustVideoBpsForVideoSizeLessConfigureMaxSizeTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1920X1080X8000 = new VideoMediaInfo
                {
                    VideoWidth = 1920,
                    VideoHeight = 1080,
                    VideoBitRate = metadataConfigurator.VideoBps1920X1080
                };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata1920X1080X8000);

            //Act
            int adjBps1920X1080X8000 = metadataService1.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps1920X1080, adjBps1920X1080X8000);
        }
Exemple #36
0
        public void AdjustWidthMoreConfigureMaxWidthTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            metadataConfigurator.MaxWidth = 100 * metadataConfigurator.VideoSizeMul;

            var metadata = new VideoMediaInfo
            {
                VideoWidth = metadataConfigurator.MaxWidth + metadataConfigurator.VideoSizeMul
            };
            var metadataService = new MetadataService(metadataConfigurator, metadata);

            //Act
            int adjustedwidth = metadataService.AdjustVideoWidth();

            //Assert
            Assert.AreEqual(metadataConfigurator.MaxWidth, adjustedwidth);
        }
Exemple #37
0
        public void AdjustVideoBpsForVideoSizeLessConfigureMaxSizeTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1920X1080X8000 = new VideoMediaInfo
            {
                VideoWidth   = 1920,
                VideoHeight  = 1080,
                VideoBitRate = metadataConfigurator.VideoBps1920X1080
            };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata1920X1080X8000);

            //Act
            int adjBps1920X1080X8000 = metadataService1.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps1920X1080, adjBps1920X1080X8000);
        }
Exemple #38
0
        public void GetWebMStringFromCorrectMetadataTest()
        {
            //Arrange
            const string sourceFilePath      = "source file path";
            const string destinationPath     = "my path";
            const string destinationFileName = "my file";

            string destinationFilePath = Path.Combine(destinationPath, destinationFileName);
            MetadataServiceConfigurator serviceConfigurator = Factory.CreateWebMMetadataServiceConfigurator();
            var metadata = new VideoMediaInfo
            {
                GeneralFormat          = "WebM",
                AudioBitRate           = 152000,
                AudioChannels          = (int)AudioChannel.Two,
                AudioFormat            = "Vorbis",
                AudioFormatProfile     = null,
                VideoBitRate           = 2500000,
                VideoFormat            = "VP8",
                VideoFrameRate         = 24,
                VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MaxKeyFrame),
                VideoFormatProfile     = null,
                VideoWidth             = 4096,
                VideoHeight            = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegService(metadataService, sourceFilePath, destinationPath, destinationFileName);

            string ffmpegStr = "-i \"{0}\" -f webm -vcodec copy -acodec copy -quality good -cpu-used 0 -threads {1} -y \"{2}.{3}\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      sourceFilePath,
                                      Environment.ProcessorCount,
                                      destinationFilePath,
                                      serviceConfigurator.FfmpegContainer);

            //Act
            string str = stringBuilder.GetStringForEncoder();

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        public void AdjustHeightVideoFailTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1 = new VideoMetadata()
            {
                Height = 0
            };

            var metadata2 = new VideoMetadata()
            {
                Height = -1
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata2);

            //Act & Assert
            CustomAssert.IsThrown<MediaFormatException>(() => metadataService1.AdjustVideoHeight());
            CustomAssert.IsThrown<MediaFormatException>(() => metadataService2.AdjustVideoHeight());
        }
Exemple #40
0
        private void StartEncode(MetadataServiceConfigurator serviceConfigurator, string[] filePathes)
        {
            var allSw = new Stopwatch();
            var decodeSw = new Stopwatch();
            foreach (var filePath in filePathes)
            {
                allSw.Start();
                Trace.WriteLine(String.Format("\n-------------Start decode file: {0}-------------\n", filePath));
                
                try
                {
                    var destinationFilePath = GetDestinationFilePath(filePath);
                    var mediaInfo = new MediaInfoWrapper();
                    var metadataInfo = new VideoMetadataInfo(mediaInfo);
                    var metadata = metadataInfo.GetMetadata(filePath);
                    var metadataService = new MetadataService(serviceConfigurator, metadata);
                    var stringBuilder = new FfmpegStringBuilder(metadataService, destinationFilePath);
                    var ffmpeg = new Ffmpeg(stringBuilder);
                    var ffmpegString = stringBuilder.GetStringForEncoder();

                    WriteFileInfo(ffmpegString, metadata);

                    decodeSw.Start();
                    var result = ffmpeg.StartEncodeProcess();
                    allSw.Stop();
                    decodeSw.Stop();
                    WriteFinishProcess(decodeSw.Elapsed, allSw.Elapsed, result);
                }
                catch (MediaFormatException ex)
                {
                    Trace.WriteLine(String.Format("Error File: {0}. Error Param: {1}", ex.VideoUri, ex.InvalidParameter));
                }
                finally
                {
                    Trace.WriteLine(String.Format("\n-------------Finish decode file: {0}-------------\n", filePath));
                }
            }
        }
        public void AdjustAudioBpsForVideoSizeMoreConfigureMaxSizeTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);
            metadataConfigurator.MaxWidth = 854;
            metadataConfigurator.MaxHeight = 480;

            var metadata128Bps = new VideoMediaInfo
                {
                    VideoWidth = 1920,
                    VideoHeight = 1080,
                    AudioChannels = (int) AudioChannel.One,
                    AudioBitRate = metadataConfigurator.AudioBps720P1Channel
                };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata128Bps);

            //Act
            int adjBps = metadataService1.AdjustAudioBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.AudioBps360P1Channel, adjBps);
        }
        public void AdjustScreenshotTimeTest()
        {
            //Arrange
            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);
            
            var metadata1 = new VideoMetadata()
                                {
                                    Duration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1
                                };
            var metadata2 = new VideoMetadata()
                                {
                                    Duration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds + 1
                                };
            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);

            //Act
            var time1 = metadataService1.AdjustScreenshotTime();
            var time2 = metadataService2.AdjustScreenshotTime();

            //Assert
            Assert.AreEqual(0, time1);
            Assert.AreEqual((int)serviceConfigurator.ScreenshotTime.Seconds, time2);
        }
        public void CorectAudioValueListFillingTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            //Act
            var metadataService = new MetadataService(metadataConfigurator, null);

            //Assert
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair<MetadataValue, bool>(MetadataValue.AudioBps, false)));
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair<MetadataValue, bool>(MetadataValue.AudioCodec, false)));
            Assert.IsTrue(metadataService.CorrectAudioValueList.Contains(new KeyValuePair<MetadataValue, bool>(MetadataValue.AudioProfile, false)));
        }
        public void AdjustAudioBpsFor854X480And640X360AndLessX2ChannelSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata64Bps = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps360P2Channel
                };
            var metadataMore64Bps = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps360P2Channel + 1
                };
            var metadataLess64Bps = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps360P2Channel - 1
                };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata64Bps);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataMore64Bps);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataLess64Bps);

            //Act
            int adjBps64Bps = metadataService1.AdjustAudioBps();
            int adjBpsMore64Bps = metadataService2.AdjustAudioBps();
            int adjBpsLess64Bps = metadataService3.AdjustAudioBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.AudioBps360P2Channel, adjBps64Bps);
            Assert.AreEqual(metadataConfigurator.AudioBps360P2Channel, adjBpsMore64Bps);
            Assert.AreEqual(metadataLess64Bps.AudioBitRate, adjBpsLess64Bps);
        }
        public void AdjustAudioProfileTest()
        {
            //Arrange
            const string myCodec1 = "myCodec1";
            const string myCodec2 = "myCodec2";
            const string anotherProfile = "anotherProfile";
            const string firstProfile = "firstProfile";

            var audioCodec = new CodecData(myCodec1, null, firstProfile);

            var supportedAudioCodecs = new List<CodecData>()
                                           {
                                               audioCodec,
                                               new CodecData(myCodec2,null)
                                           };

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, audioCodec, supportedAudioCodecs);

            var metadata1 = new VideoMetadata()
            {
                AudioCodec = myCodec1,
                AudioProfile = firstProfile
            };
            var metadata2 = new VideoMetadata()
            {
                AudioCodec = myCodec1,
                AudioProfile = anotherProfile
            };
            var metadata3 = new VideoMetadata()
            {
                AudioCodec = myCodec2,
                AudioProfile = anotherProfile
            };
            var metadataWithoutProfile = new VideoMetadata()
            {
                AudioCodec = myCodec1,
                AudioProfile = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutProfile);

            //Act
            var profile1 = metadataService1.AdjustAudioProfile();
            var profile2 = metadataService2.AdjustAudioProfile();
            var profile3 = metadataService3.AdjustAudioProfile();
            var profile4 = metadataService4.AdjustAudioProfile();

            //Assert
            Assert.AreEqual(firstProfile, profile1);
            Assert.AreEqual(firstProfile, profile2);
            Assert.AreEqual(anotherProfile, profile3);
            Assert.AreEqual(firstProfile, profile4);
        }
        public void AdjustVideoBpsFor1920X1080SuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1920X1080X8000 = new VideoMediaInfo
                {
                    VideoWidth = 1920,
                    VideoHeight = 1080,
                    VideoBitRate = metadataConfigurator.VideoBps1920X1080
                };
            var metadata1920X1080More8000 = new VideoMediaInfo
                {
                    VideoWidth = 1920,
                    VideoHeight = 1080,
                    VideoBitRate = metadataConfigurator.VideoBps1920X1080 + 1
                };
            var metadata1920X1080Less8000 = new VideoMediaInfo
                {
                    VideoWidth = 1920,
                    VideoHeight = 1080,
                    VideoBitRate = metadataConfigurator.VideoBps1920X1080 - 1
                };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1920X1080X8000);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata1920X1080More8000);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata1920X1080Less8000);

            //Act
            int adjBps1920X1080X8000 = metadataService1.AdjustVideoBps();
            int adjBps1920X1080More8000 = metadataService2.AdjustVideoBps();
            int adjBps1920X1080Less8000 = metadataService3.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps1920X1080, adjBps1920X1080X8000);
            Assert.AreEqual(metadataConfigurator.VideoBps1920X1080, adjBps1920X1080More8000);
            Assert.AreEqual(metadata1920X1080Less8000.VideoBitRate, adjBps1920X1080Less8000);
        }
        public void AdjustVideoBpsFor854X480SuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata854X480X2500 = new VideoMetadata()
            {
                Width = 854,
                Height = 480,
                VideoBps = metadataConfigurator.VideoBps854X480
            };
            var metadata854X480More2500 = new VideoMetadata()
            {
                Width = 854,
                Height = 480,
                VideoBps = metadataConfigurator.VideoBps854X480 + 1
            };
            var metadata854X480Less2500 = new VideoMetadata()
            {
                Width = 854,
                Height = 480,
                VideoBps = metadataConfigurator.VideoBps854X480 - 1
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata854X480X2500);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata854X480More2500);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata854X480Less2500);

            //Act
            var adjBps854X480X2500 = metadataService1.AdjustVideoBps();
            var adjBps854X480More2500 = metadataService2.AdjustVideoBps();
            var adjBps854X480Less2500 = metadataService3.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps854X480, adjBps854X480X2500);
            Assert.AreEqual(metadataConfigurator.VideoBps854X480, adjBps854X480More2500);
            Assert.AreEqual(metadata854X480Less2500.VideoBps, adjBps854X480Less2500);
        }
        public void AdjustContainerTest()
        {
            //Arrange
            const string myContainer = "myContainer";
            const string anotherContainer = "anotherContainer";
            var serviceConfigurator = new MetadataServiceConfigurator(myContainer, null, null, null, null);

            var metadata1 = new VideoMetadata()
            {
                Container = myContainer
            };
            var metadata2 = new VideoMetadata()
            {
                Container = anotherContainer
            };
            var metadataWithoutContainer = new VideoMetadata()
            {
                Container = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadataWithoutContainer);

            //Act
            var container1 = metadataService1.AdjustContainer();
            var container2 = metadataService2.AdjustContainer();

            //Act & Assert
            CustomAssert.IsThrown<MediaFormatException>(() => metadataService3.AdjustContainer());

            //Assert
            Assert.AreEqual(myContainer, container1);
            Assert.AreEqual(myContainer, container2);
        }
        public void AdjustVideoCodecTest()
        {
            //Arrange
            const string anotherCodecName = "anotherCodec";
            const string myCodecName = "myCodec";
            var myCodec = new CodecData(myCodecName, null);

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, myCodec, null, null);

            var metadata1 = new VideoMetadata()
            {
                VideoCodec = myCodecName
            };
            var metadata2 = new VideoMetadata()
            {
                VideoCodec = anotherCodecName
            };
            var metadataWithoutCodec = new VideoMetadata()
            {
                VideoCodec = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadataWithoutCodec);

            //Act
            var codec1 = metadataService1.AdjustVideoCodec();
            var codec2 = metadataService2.AdjustVideoCodec();

            //Act & Assert
            CustomAssert.IsThrown<MediaFormatException>(() => metadataService3.AdjustContainer());

            //Assert
            Assert.AreEqual(myCodecName, codec1);
            Assert.AreEqual(myCodecName, codec2);
        }
        public void AdjustVideoKeyFrameSuccessTest()
        {
            //Arrange
            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);
            int myKeyFrame = serviceConfigurator.MaxKeyFrame - 1;

            var metadataKeyFrame0 = new VideoMediaInfo
                {
                    VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MinKeyFrame - 1)
                };
            var metadataKeyFrameMore60 = new VideoMediaInfo
                {
                    VideoFormatSettingsGOP = String.Format("M=1, N={0}", serviceConfigurator.MaxKeyFrame + 1)
                };
            var metadataKeyFrame = new VideoMediaInfo
                {
                    VideoFormatSettingsGOP = String.Format("M=1, N={0}", myKeyFrame)
                };

            var metadataService1 = new MetadataService(serviceConfigurator, metadataKeyFrame0);
            var metadataService2 = new MetadataService(serviceConfigurator, metadataKeyFrameMore60);
            var metadataService3 = new MetadataService(serviceConfigurator, metadataKeyFrame);

            //Act;
            int keyFrame0 = metadataService1.AdjustKeyFrame();
            int keyFrameMore60 = metadataService2.AdjustKeyFrame();
            int keyFrame = metadataService3.AdjustKeyFrame();

            //Assert
            Assert.AreEqual(serviceConfigurator.KeyFrame, keyFrame0);
            Assert.AreEqual(serviceConfigurator.KeyFrame, keyFrameMore60);
            Assert.AreEqual(myKeyFrame, keyFrame);
        }
        public void AdjustVideoKeyFrameSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadataKeyFrame0 = new VideoMetadata()
            {
                VideoKeyFrame = metadataConfigurator.MinKeyFrame - 1
            };
            var metadataKeyFrameMore60 = new VideoMetadata()
            {
                VideoKeyFrame = metadataConfigurator.MaxKeyFrame + 1
            };
            var metadataKeyFrame = new VideoMetadata()
            {
                VideoKeyFrame = 30
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadataKeyFrame0);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataKeyFrameMore60);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataKeyFrame);

            //Act;
            var keyFrame0 = metadataService1.AdjustKeyFrame();
            var keyFrameMore60 = metadataService2.AdjustKeyFrame();
            var keyFrame = metadataService3.AdjustKeyFrame();

            //Assert
            Assert.AreEqual(metadataConfigurator.KeyFrame, keyFrame0);
            Assert.AreEqual(metadataConfigurator.KeyFrame, keyFrameMore60);
            Assert.AreEqual(metadataKeyFrame.VideoKeyFrame, keyFrame);
        }
        public void AdjustAudioBpsFor854X480And640X360AndLessX6ChannelSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata64Bps = new VideoMetadata()
            {
                Width = 640,
                Height = 360,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps360P6Channel
            };
            var metadataMore64Bps = new VideoMetadata()
            {
                Width = 640,
                Height = 360,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps360P6Channel + 1
            };
            var metadataLess64Bps = new VideoMetadata()
            {
                Width = 640,
                Height = 360,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps360P6Channel - 1
            };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata64Bps);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataMore64Bps);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataLess64Bps);

            //Act
            var adjBps64Bps = metadataService1.AdjustAudioBps();
            var adjBpsMore64Bps = metadataService2.AdjustAudioBps();
            var adjBpsLess64Bps = metadataService3.AdjustAudioBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.AudioBps360P6Channel, adjBps64Bps);
            Assert.AreEqual(metadataConfigurator.AudioBps360P6Channel, adjBpsMore64Bps);
            Assert.AreEqual(metadataLess64Bps.AudioBps, adjBpsLess64Bps);
        }
        public void AdjustAudioBpsFor1920X1080And1280X720X6ChannelSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata512Bps = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps720P6Channel
            };
            var metadataMore512Bps = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps720P6Channel + 1
            };
            var metadataLess512Bps = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                AudioChannel = AudioChannel.Six,
                AudioBps = metadataConfigurator.AudioBps720P6Channel - 1
            };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata512Bps);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataMore512Bps);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataLess512Bps);

            //Act
            var adjBps512Bps = metadataService1.AdjustAudioBps();
            var adjBpsMore512Bps = metadataService2.AdjustAudioBps();
            var adjBpsLess512Bps = metadataService3.AdjustAudioBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.AudioBps720P6Channel, adjBps512Bps);
            Assert.AreEqual(metadataConfigurator.AudioBps720P6Channel, adjBpsMore512Bps);
            Assert.AreEqual(metadataLess512Bps.AudioBps, adjBpsLess512Bps);
        }
        public void AdjustVideoBpsForLess640X360SuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1000Bps = new VideoMetadata()
            {
                Width = 40,
                Height = 60,
                VideoBps = metadataConfigurator.VideoBps640X360
            };
            var metadataMore1000Bps = new VideoMetadata()
            {
                Width = 40,
                Height = 60,
                VideoBps = metadataConfigurator.VideoBps640X360 + 1
            };
            var metadataLess1000Bps = new VideoMetadata()
            {
                Width = 40,
                Height = 60,
                VideoBps = metadataConfigurator.VideoBps640X360 - 1
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1000Bps);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataMore1000Bps);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataLess1000Bps);

            //Act
            var adjBps1000Bps = metadataService1.AdjustVideoBps();
            var adjBpsMore1000Bps = metadataService2.AdjustVideoBps();
            var adjBpsLess1000Bps = metadataService3.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps640X360, adjBps1000Bps);
            Assert.AreEqual(metadataConfigurator.VideoBps640X360, adjBpsMore1000Bps);
            Assert.AreEqual(metadataLess1000Bps.VideoBps, adjBpsLess1000Bps);
        }
        public void AdjustAudioBpsFor1920X1080And1280X720X2ChannelSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata384Bps = new VideoMediaInfo
                {
                    VideoWidth = 1280,
                    VideoHeight = 720,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps720P2Channel
                };
            var metadataMore384Bps = new VideoMediaInfo
                {
                    VideoWidth = 1280,
                    VideoHeight = 720,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps720P2Channel + 1
                };
            var metadataLess384Bps = new VideoMediaInfo
                {
                    VideoWidth = 1280,
                    VideoHeight = 720,
                    AudioChannels = (int) AudioChannel.Two,
                    AudioBitRate = metadataConfigurator.AudioBps720P2Channel - 1
                };
            var metadataService1 = new MetadataService(metadataConfigurator, metadata384Bps);
            var metadataService2 = new MetadataService(metadataConfigurator, metadataMore384Bps);
            var metadataService3 = new MetadataService(metadataConfigurator, metadataLess384Bps);

            //Act
            int adjBps384Bps = metadataService1.AdjustAudioBps();
            int adjBpsMore384Bps = metadataService2.AdjustAudioBps();
            int adjBpsLess384Bps = metadataService3.AdjustAudioBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.AudioBps720P2Channel, adjBps384Bps);
            Assert.AreEqual(metadataConfigurator.AudioBps720P2Channel, adjBpsMore384Bps);
            Assert.AreEqual(metadataLess384Bps.AudioBitRate, adjBpsLess384Bps);
        }
        public void AdjustVideoProfileTest()
        {
            //Arrange
            const string myCodec = "myCodec";
            const string anotherProfile = "anotherProfile";
            const string firstProfile = "firstProfile";
            const string secondProfile = "secondProfile";

            var videoCodec = new CodecData(myCodec, null, firstProfile, secondProfile);

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, videoCodec, null, null);

            var metadata1 = new VideoMetadata()
            {
                VideoCodec = myCodec,
                VideoProfile = firstProfile
            };
            var metadata2 = new VideoMetadata()
            {
                VideoCodec = myCodec,
                VideoProfile = secondProfile
            };
            var metadata3 = new VideoMetadata()
            {
                VideoCodec = myCodec,
                VideoProfile = anotherProfile
            };
            var metadataWithoutCodec = new VideoMetadata()
            {
                VideoCodec = myCodec,
                VideoProfile = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutCodec);

            //Act
            var profile1 = metadataService1.AdjustVideoProfile();
            var profile2 = metadataService2.AdjustVideoProfile();
            var profile3 = metadataService3.AdjustVideoProfile();
            var profile4 = metadataService4.AdjustVideoProfile();

            //Assert
            Assert.AreEqual(firstProfile, profile1);
            Assert.AreEqual(secondProfile, profile2);
            Assert.AreEqual(firstProfile, profile3);
            Assert.AreEqual(firstProfile, profile4);
        }
        public void AdjustVideoBpsFor640X360SuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata640X360X1000 = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    VideoBitRate = metadataConfigurator.VideoBps640X360
                };
            var metadata640X360More1000 = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    VideoBitRate = metadataConfigurator.VideoBps640X360 + 1
                };
            var metadata640X360Less1000 = new VideoMediaInfo
                {
                    VideoWidth = 640,
                    VideoHeight = 360,
                    VideoBitRate = metadataConfigurator.VideoBps640X360 - 1
                };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata640X360X1000);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata640X360More1000);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata640X360Less1000);

            //Act
            int adjBps640X360X1000 = metadataService1.AdjustVideoBps();
            int adjBps640X360More1000 = metadataService2.AdjustVideoBps();
            int adjBps640X360Less1000 = metadataService3.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps640X360, adjBps640X360X1000);
            Assert.AreEqual(metadataConfigurator.VideoBps640X360, adjBps640X360More1000);
            Assert.AreEqual(metadata640X360Less1000.VideoBitRate, adjBps640X360Less1000);
        }
        public void AdjustAudioCodecTest()
        {
            //Arrange
            const string myCodec1 = "myCodec1";
            const string myCodec2 = "myCodec2";
            const string anotherCodec = "anotherCodec";

            var audioCodec = new CodecData(myCodec1, null);

            var supportedAudioCodecs = new List<CodecData>()
                                           {
                                               audioCodec,
                                               new CodecData(myCodec2, null)
                                           };

            var serviceConfigurator = new MetadataServiceConfigurator(null, null, null, audioCodec, supportedAudioCodecs);

            var metadata1 = new VideoMetadata()
            {
                AudioCodec = myCodec1
            };
            var metadata2 = new VideoMetadata()
            {
                AudioCodec = myCodec2
            };
            var metadata3 = new VideoMetadata()
            {
                AudioCodec = anotherCodec
            };
            var metadataWithoutCodec = new VideoMetadata()
            {
                AudioCodec = null
            };

            var metadataService1 = new MetadataService(serviceConfigurator, metadata1);
            var metadataService2 = new MetadataService(serviceConfigurator, metadata2);
            var metadataService3 = new MetadataService(serviceConfigurator, metadata3);
            var metadataService4 = new MetadataService(serviceConfigurator, metadataWithoutCodec);

            //Act
            var codec1 = metadataService1.AdjustAudioCodec();
            var codec2 = metadataService2.AdjustAudioCodec();
            var codec3 = metadataService3.AdjustAudioCodec();
            var codec4 = metadataService4.AdjustAudioCodec();

            //Assert
            Assert.AreEqual(myCodec1, codec1);
            Assert.AreEqual(myCodec2, codec2);
            Assert.AreEqual(myCodec1, codec3);
            Assert.AreEqual(null, codec4);
        }
        public void AdjustVideoFpsSuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1 = new VideoMetadata()
                                {
                                    VideoFps = 29.970
                                };

            var metadata2 = new VideoMetadata()
                                {
                                    VideoFps = metadataConfigurator.MinFps - 1
                                };

            var metadata3 = new VideoMetadata()
                                {
                                    VideoFps = metadataConfigurator.MaxFps + 1
                                };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata2);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata3);

            //Act
            var adjustedFps1 = metadataService1.AdjustVideoFps();
            
            //Act & Assert
            CustomAssert.IsThrown<MediaFormatException>(() => metadataService2.AdjustVideoFps());
            CustomAssert.IsThrown<MediaFormatException>(() =>metadataService3.AdjustVideoFps());

            //Assert
            Assert.AreEqual(metadata1.VideoFps, adjustedFps1);
        }
        public void AdjustVideoBpsFor1280X720SuccessTest()
        {
            //Arrange
            var metadataConfigurator = new MetadataServiceConfigurator(null, null, null, null, null);

            var metadata1280X720X5000 = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                VideoBps = metadataConfigurator.VideoBps1280X720
            };
            var metadata1280X720More5000 = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                VideoBps = metadataConfigurator.VideoBps1280X720 + 1
            };
            var metadata1280X720Less5000 = new VideoMetadata()
            {
                Width = 1280,
                Height = 720,
                VideoBps = metadataConfigurator.VideoBps1280X720 - 1
            };

            var metadataService1 = new MetadataService(metadataConfigurator, metadata1280X720X5000);
            var metadataService2 = new MetadataService(metadataConfigurator, metadata1280X720More5000);
            var metadataService3 = new MetadataService(metadataConfigurator, metadata1280X720Less5000);

            //Act
            var adjBps1280X720X5000 = metadataService1.AdjustVideoBps();
            var adjBps1280X720More5000 = metadataService2.AdjustVideoBps();
            var adjBps1280X720Less5000 = metadataService3.AdjustVideoBps();

            //Assert
            Assert.AreEqual(metadataConfigurator.VideoBps1280X720, adjBps1280X720X5000);
            Assert.AreEqual(metadataConfigurator.VideoBps1280X720, adjBps1280X720More5000);
            Assert.AreEqual(metadata1280X720Less5000.VideoBps, adjBps1280X720Less5000);
        }