예제 #1
0
 public VideoGridImage(VideoMetadata video, VideoPreviewImageViewModel vm, List <MediaThumb> thumbs) :
     base(vm.MaxPreviewImageWidth, vm.NrRows, vm.NrColumns, getImages(thumbs), vm.BackgroundColor, vm.FontColor)
 {
     Video  = video;
     Vm     = vm;
     Thumbs = thumbs;
 }
        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 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);
        }
예제 #5
0
        public void GetMjpegStringWithNumFrameMoreDurationTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            const int    numFrame            = 10;
            var          serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                Duration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1,
                Width    = 4096,
                Height   = 2304,
                FilePath = "source file path"
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegStringBuilder(metadataService, destinationFilePath);
            var ffmpegStr       = "-i \"{0}\" -f image2 -ss {1} -frames:v 1 -y \"{2}.jpg\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      metadata.FilePath,
                                      0,
                                      destinationFilePath);

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

            //Assert
            Assert.AreEqual(ffmpegStr, str);
        }
        public void CheckCorrectAudioValueListTest()
        {
            //Arrange
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                AudioBps      = serviceConfigurator.AudioBps720P1Channel,
                AudioChannel  = AudioChannel.One,
                AudioCodec    = "AAC",
                AudioProfile  = "LC",
                VideoBps      = serviceConfigurator.VideoBps1920X1080,
                VideoCodec    = "AVC",
                VideoProfile  = "Baseline",
                VideoFps      = serviceConfigurator.MaxFps - 1,
                VideoKeyFrame = serviceConfigurator.KeyFrame,
                Width         = 4096,
                Height        = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

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

            //Assert
            Assert.IsTrue(metadataService.CorrectAudioValueList.All((b) => b.Value));
        }
        public void generateThumbnail(MediaProbe mediaProbe, VideoMetadata video,
            CancellationToken token, int timeoutSeconds, int nrThumbnails)
        {
            video.Thumbnail = null;

            List<MediaThumb> coverBitmaps = mediaProbe.grabAttachedImages(Constants.MAX_THUMBNAIL_WIDTH,
                 Constants.MAX_THUMBNAIL_HEIGHT, token, timeoutSeconds);

            if (coverBitmaps.Count > 0)
            {
                video.Thumbnail = new Thumbnail(coverBitmaps[0].Thumb);
            }

            if (coverBitmaps.Count == 0 || nrThumbnails > 1)
            {

                List<MediaThumb> thumbBitmaps = mediaProbe.grabThumbnails(Constants.MAX_THUMBNAIL_WIDTH,
                     Constants.MAX_THUMBNAIL_HEIGHT, 0, nrThumbnails, 0.025, token, timeoutSeconds, null);

                if (thumbBitmaps.Count > 0 && coverBitmaps.Count == 0)
                {
                    video.Thumbnail = new Thumbnail(thumbBitmaps[0].Thumb);
                }

            }
        }
예제 #8
0
        protected override void addImageInfo(int imageNr, Grid cell, string fontFamily, int margin)
        {
            if (Vm.IsAddInfo == false)
            {
                return;
            }

            cell.Margin = new Thickness(margin);

            MediaFileItem item = Items[imageNr];

            TextBlock name = new TextBlock();

            name.TextTrimming        = TextTrimming.CharacterEllipsis;
            name.HorizontalAlignment = HorizontalAlignment.Center;
            name.VerticalAlignment   = VerticalAlignment.Bottom;

            name.Text       = Path.GetFileName(item.Location);
            name.Foreground = new SolidColorBrush(FontColor);

            Grid.SetRow(name, 0);

            cell.Children.Add(name);

            if (item.Metadata == null)
            {
                return;
            }

            VideoMetadata videoInfo = item.Metadata as VideoMetadata;

            MediaViewer.MediaDatabase.ImageMetadata imageInfo = item.Metadata as MediaViewer.MediaDatabase.ImageMetadata;

            TextBlock info = new TextBlock();

            info.TextTrimming        = TextTrimming.CharacterEllipsis;
            info.HorizontalAlignment = HorizontalAlignment.Center;
            info.VerticalAlignment   = VerticalAlignment.Top;
            info.Foreground          = new SolidColorBrush(FontColor);

            String infoText = "";

            if (videoInfo != null)
            {
                infoText += videoInfo.Width + "x" + videoInfo.Height;
            }
            else
            {
                infoText += imageInfo.Width + "x" + imageInfo.Height;
            }

            infoText += ", " + MiscUtils.formatSizeBytes(item.Metadata.SizeBytes);

            info.Text = infoText;

            Grid.SetRow(info, 2);

            cell.Children.Add(info);
        }
예제 #9
0
 public ProcessedMediaModel(List <DomainProcessedVideo> domainProcessedVideos,
                            List <DomainProcessedScreenshot> domainProcessedScreenshots,
                            VideoMetadata videoMetadata)
 {
     DomainProcessedVideos      = domainProcessedVideos;
     DomainProcessedScreenshots = domainProcessedScreenshots;
     VideoMetadata = videoMetadata;
 }
예제 #10
0
        /// <summary>
        /// Load video metadata into memory.
        /// </summary>
        public async Task LoadMetadataAsync(bool ignoreStreamErrors = false)
        {
            if (LoadedMetadata)
            {
                throw new InvalidOperationException("Video metadata is already loaded!");
            }
            var r = FFmpegWrapper.OpenOutput(ffprobe, $"-i \"{Filename}\" -v quiet -print_format json=c=1 -show_format -show_streams");

            try
            {
                var metadata = await JsonSerializer.DeserializeAsync <VideoMetadata>(r);

                try
                {
                    var videoStream = metadata.Streams.Where(x => x.CodecType.ToLower().Trim() == "video").FirstOrDefault();
                    if (videoStream != null)
                    {
                        metadata.Width         = videoStream.Width.Value;
                        metadata.Height        = videoStream.Height.Value;
                        metadata.PixelFormat   = videoStream.PixFmt;
                        metadata.Codec         = videoStream.CodecName;
                        metadata.CodecLongName = videoStream.CodecLongName;

                        metadata.BitRate = videoStream.BitRate == null ? -1 :
                                           int.Parse(videoStream.BitRate);

                        metadata.BitDepth = videoStream.BitsPerRawSample == null?
                                            tryParseBitDepth(videoStream.PixFmt) :
                                                int.Parse(videoStream.BitsPerRawSample);

                        metadata.Duration = videoStream.Duration == null?
                                            double.Parse(metadata.Format.Duration ?? "0", CultureInfo.InvariantCulture) :
                                                double.Parse(videoStream.Duration, CultureInfo.InvariantCulture);

                        metadata.SampleAspectRatio = videoStream.SampleAspectRatio;
                        metadata.AvgFramerateText  = videoStream.AvgFrameRate;
                        metadata.AvgFramerate      = videoStream.AvgFrameRateNumber;

                        metadata.PredictedFrameCount = (int)(metadata.AvgFramerate * metadata.Duration);
                    }
                }
                catch (Exception ex)
                {
                    // failed to interpret video stream settings
                    if (!ignoreStreamErrors)
                    {
                        throw new InvalidDataException("Failed to parse video stream data! " + ex.Message);
                    }
                }

                LoadedMetadata = true;
                Metadata       = metadata;
            }
            catch (JsonException ex)
            {
                throw new InvalidOperationException("Failed to interpret ffprobe video metadata output! " + ex.Message);
            }
        }
 public void SaveVideoMetadata()
 {
   IVideoMetadata metadata = new VideoMetadata();
   metadata.Clear();
   metadata.Id = "22";
   metadata.Filename = "testVideo.wmv";
   using (XmlWriter writer = Helpers.CreateXmlWriter(@"testVideoMetadata.cxml"))
     metadata.Save(writer);
 }
예제 #12
0
 public MetadataInfo Copy()
 {
     return(new MetadataInfo
     {
         AudioMetadata = HasAudio ? AudioMetadata.Copy() : null,
         VideoMetadata = HasVideo ? VideoMetadata.Copy() : null,
         DataMetadata = HasData ? DataMetadata.Copy() : null,
     });
 }
예제 #13
0
        public void Initialize(string file, VideoMetadata metadata)
        {
            SourceFile        = file;
            SourceMetadata    = metadata;
            TargetTotalFrames = (int)Math.Ceiling(SourceMetadata.FrameRate * SourceMetadata.Duration.TotalSeconds);
            TargetBitrate     = metadata.Bitrate;

            InitializeEx();
        }
        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);
        }
예제 #15
0
        public void SaveVideoMetadata()
        {
            IVideoMetadata metadata = new VideoMetadata();

            metadata.Clear();
            metadata.Id       = "22";
            metadata.Filename = "testVideo.wmv";
            using (XmlWriter writer = Helpers.CreateXmlWriter(@"testVideoMetadata.cxml"))
                metadata.Save(writer);
        }
예제 #16
0
        public static List <Tuple <String, String> > formatProperties(VideoMetadata video)
        {
            List <Tuple <String, String> > propList = new List <Tuple <string, string> >();

            addPropIfExists("Major Brand", video.MajorBrand, propList);
            addPropIfExists("Minor Version", video.MinorVersion, propList);
            addPropIfExists("WMF SDK Version", video.WMFSDKVersion, propList);
            addPropIfExists("Variable Bitrate", video.IsVariableBitRate, propList);

            return(propList);
        }
        private void AddMedia_Click(object sender, EventArgs e)
        {
            string ofilename = openFileDialog1.FileName;
            string filename  = $"{NewPath}{Path.GetFileName(ofilename)}";

            File.Copy(ofilename, filename, true);

            if (MediaType == "song")
            {
                string format, duration, name, artist, album, genre, pubYear, label;

                format   = MetaGrid.Rows[1].Cells[1].Value.ToString();
                duration = MetaGrid.Rows[2].Cells[1].Value.ToString();
                name     = MetaGrid.Rows[3].Cells[1].Value.ToString();
                artist   = MetaGrid.Rows[4].Cells[1].Value.ToString();
                album    = MetaGrid.Rows[5].Cells[1].Value.ToString();
                genre    = MetaGrid.Rows[6].Cells[1].Value.ToString();
                pubYear  = MetaGrid.Rows[7].Cells[1].Value.ToString();
                label    = MetaGrid.Rows[8].Cells[1].Value.ToString();



                SongMetadata meta = new SongMetadata(name, artist, album, genre, pubYear, label);
                Song         song = new Song(filename, meta, format, duration);
            }

            else if (MediaType == "video")
            {
                string format, duration, name, creator, genre, category, studio, description, resolution, aspect, director, actors, pubYear;
                format      = MetaGrid.Rows[1].Cells[1].Value.ToString();
                duration    = MetaGrid.Rows[2].Cells[1].Value.ToString();
                name        = MetaGrid.Rows[3].Cells[1].Value.ToString();
                creator     = MetaGrid.Rows[4].Cells[1].Value.ToString();
                genre       = MetaGrid.Rows[5].Cells[1].Value.ToString();
                category    = MetaGrid.Rows[6].Cells[1].Value.ToString();
                actors      = MetaGrid.Rows[7].Cells[1].Value.ToString();
                director    = MetaGrid.Rows[8].Cells[1].Value.ToString();
                studio      = MetaGrid.Rows[9].Cells[1].Value.ToString();
                pubYear     = MetaGrid.Rows[10].Cells[1].Value.ToString();
                description = MetaGrid.Rows[11].Cells[1].Value.ToString();
                resolution  = MetaGrid.Rows[12].Cells[1].Value.ToString();
                aspect      = MetaGrid.Rows[13].Cells[1].Value.ToString();



                VideoMetadata meta = new VideoMetadata(name, creator, genre, category, studio, description,
                                                       resolution, aspect, director, actors, pubYear);
                Video video = new Video(filename, meta, format, duration);
            }
            Spotflix.Save("Spotflix.bin");
            panelAddMedia.Hide();
            MetaGrid.Rows.Clear();
        }
        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 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 VideoMetadata ParseMetadata(string name)
        {
            var metadata = new VideoMetadata();

            var nameParts = name.Split('_');

            metadata.DVRName    = nameParts[0].Split('\\').Last();
            metadata.CameraName = nameParts[1];
            metadata.IsMain     = nameParts[2].Contains("main");
            metadata.Date       = this.ParseDateTime(nameParts[3]);
            metadata.FileName   =
                $"{metadata.DVRName}_{metadata.CameraName}_{nameParts[3].Substring(0, 4)}-{nameParts[3].Substring(4, 2)}-{nameParts[3].Substring(6, 2)}--{nameParts[3].Substring(8, 2)}-{nameParts[3].Substring(10, 2)}-{nameParts[3].Substring(12, 2)}.mp4";
            return(metadata);
        }
예제 #21
0
 private void WriteFileInfo(string ffmpegString, VideoMetadata metadata)
 {
     Trace.WriteLine(String.Format("Width:\t\t{0}", metadata.Width));
     Trace.WriteLine(String.Format("Width:\t\t{0}", metadata.Height));
     Trace.WriteLine(String.Format("File Size:\t\t{0}", metadata.FileSize));
     Trace.WriteLine(String.Format("Container:\t\t{0}", metadata.Container));
     Trace.WriteLine(String.Format("Video Codec:\t\t{0}", metadata.VideoCodec));
     Trace.WriteLine(String.Format("Video Profile:\t\t{0}", metadata.VideoProfile));
     Trace.WriteLine(String.Format("Video Bitrate:\t\t{0}", metadata.VideoBps));
     Trace.WriteLine(String.Format("Audio Codec:\t\t{0}", metadata.AudioCodec));
     Trace.WriteLine(String.Format("Audio Profile:\t\t{0}", metadata.AudioProfile));
     Trace.WriteLine(String.Format("Audio Channel(s):\t\t{0}", metadata.AudioChannel));
     Trace.WriteLine(String.Format("Audio Bitrate:\t\t{0}", metadata.AudioBps));
     Trace.WriteLine(String.Format("Ffmpeg String:\t\t{0}", ffmpegString));
 }
예제 #22
0
 public async Task AddUploadedVideoFile(VideoMetadata metadata, string azureUrl)
 {
     var model = new UploadedVideoFileModel
     {
         Id                  = Guid.NewGuid().ToString(),
         FileName            = metadata.FileName,
         FilePath            = azureUrl,
         Date                = DateTime.UtcNow,
         DvrName             = metadata.DVRName,
         VideoStartDateLocal = metadata.Date,
         CameraName          = metadata.ParsedCameraName
     };
     var collection = database.GetCollection <UploadedVideoFileModel>("uploadedVideoFiles");
     await collection.InsertOneAsync(model);
 }
예제 #23
0
        public void GetMp4StringFromIncorrectMetadataTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            var          serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var          metadata            = new VideoMetadata()
            {
                Container     = "MPEG-PS",
                AudioBps      = serviceConfigurator.AudioBps720P1Channel + 1,
                AudioChannel  = AudioChannel.One,
                AudioCodec    = "AC-3",
                AudioProfile  = null,
                VideoBps      = serviceConfigurator.VideoBps1920X1080 + 1,
                VideoCodec    = "MPEG Video",
                VideoFps      = serviceConfigurator.MaxFps - 1,
                VideoKeyFrame = serviceConfigurator.MaxKeyFrame + 1,
                VideoProfile  = "High",
                Width         = 4096,
                Height        = 2304,
                FilePath      = "source file path"
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegStringBuilder(metadataService, destinationFilePath);

            var ffmpegStr = "-i \"{0}\" -f {1} -vcodec {2} -b:v {3} -r {4} -g {5} -profile {6} -acodec {7} -b:a {8} -y \"{9}.{10}\"";

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

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

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        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);
        }
        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);
        }
        private bool supportsXMPMetadata(VideoMetadata video, List<string> fsMetaData)
        {
            // XMP Metadata does not support matroska
            if (video.MimeType.Equals("video/x-matroska") || video.MimeType.Equals("video/webm"))
            {
                return (false);
            }
            else if (video.MimeType.Equals("video/mp4"))
            {
                // mp4 versions incompatible with XMP metadata

                if (fsMetaData.Contains("major_brand: isom") &&
                    fsMetaData.Contains("minor_version: 1"))
                {
                    return (false);
                }

                if (fsMetaData.Contains("major_brand: mp42") &&
                    fsMetaData.Contains("minor_version: 0"))
                {

                    if (fsMetaData.Contains("compatible_brands: isom"))
                    {
                        return (false);
                    }

                    if (fsMetaData.Contains("compatible_brands: 000000964375"))
                    {
                        return (false);
                    }
                }

            }
            else if (video.MimeType.Equals("video/avi"))
            {

                if (video.VideoCodec.Equals("mpeg2video"))
                {

                    return (false);
                }
            }

            return (true);
        }
예제 #29
0
        public void GetMp4StringFromIncorrectMetadataTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var metadata = new VideoMetadata()
                               {
                                   Container = "MPEG-PS",
                                   AudioBps = serviceConfigurator.AudioBps720P1Channel+1,
                                   AudioChannel = AudioChannel.One,
                                   AudioCodec = "AC-3",
                                   AudioProfile = null,
                                   VideoBps = serviceConfigurator.VideoBps1920X1080+1,
                                   VideoCodec = "MPEG Video",
                                   VideoFps = serviceConfigurator.MaxFps - 1,
                                   VideoKeyFrame = serviceConfigurator.MaxKeyFrame+1,
                                   VideoProfile = "High",
                                   Width = 4096,
                                   Height = 2304,
                                   FilePath = "source file path"
                               };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder = new FfmpegStringBuilder(metadataService, destinationFilePath);

            var ffmpegStr = "-i \"{0}\" -f {1} -vcodec {2} -b:v {3} -r {4} -g {5} -profile {6} -acodec {7} -b:a {8} -y \"{9}.{10}\"";
            ffmpegStr = String.Format(ffmpegStr,
                metadata.FilePath,
                metadataService.ContainerForFfmpeg,
                metadataService.VideoCodecLib,
                 serviceConfigurator.VideoBps1920X1080,
                 serviceConfigurator.MaxFps - 1,
                serviceConfigurator.KeyFrame,
                serviceConfigurator.VideoCodec.DefaultProfile,
                metadataService.AudioCodecLib,
                serviceConfigurator.AudioBps720P1Channel,
                destinationFilePath,
                serviceConfigurator.FfmpegContainer);
            
            //Act
            var str = stringBuilder.GetStringForEncoder();

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        public void CheckCorrectContainerTest()
        {
            //Arrange
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                Container = serviceConfigurator.Container
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

            //Act
            metadataService.AdjustContainer();

            //Assert
            Assert.IsTrue(metadataService.CorrectContainer);
        }
예제 #31
0
        public void GetMp4StringFromMetadataWithMp2Test()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            var          serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var          metadata            = new VideoMetadata()
            {
                Container     = "MPEG-4",
                AudioBps      = 152000,
                AudioChannel  = AudioChannel.Two,
                AudioCodec    = "MPEG Audio",
                AudioProfile  = "Layer 2",
                VideoBps      = 2500000,
                VideoCodec    = "AVC",
                VideoFps      = 24,
                VideoKeyFrame = 2,
                VideoProfile  = "Baseline",
                Width         = 4096,
                Height        = 2304,
                FilePath      = "source file path"
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder   = new FfmpegStringBuilder(metadataService, destinationFilePath);

            var ffmpegStr = "-i \"{0}\" -f mp4 -vcodec copy -acodec {1} -b:a {2} -y \"{3}.{4}\"";

            ffmpegStr = String.Format(ffmpegStr,
                                      metadata.FilePath,
                                      metadataService.AudioCodecLib,
                                      metadata.AudioBps,
                                      destinationFilePath,
                                      serviceConfigurator.FfmpegContainer);

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

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        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 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());
        }
        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());
        }
        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 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 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);
        }
예제 #40
0
        private VideoMetadata GetVideoMetadata(int width, int height, string container, string videoCodec, int videoBps, int videoKeyFrame, double videoFps, string audioCodec, int audioBps, long fileSize, int duration, AudioChannel audioChannel,string audioProfile, string videoFormatProfile = null)
        {
            var metadata = new VideoMetadata()
                               {
                                   AudioBps = audioBps,
                                   AudioCodec = audioCodec,
                                   AudioChannel=audioChannel,
                                   AudioProfile=audioProfile,
                                   Container = container,
                                   Duration = duration,
                                   FileSize = fileSize,
                                   Height = height,
                                   VideoBps = videoBps,
                                   VideoCodec = videoCodec,
                                   VideoFps = videoFps,
                                   VideoKeyFrame = videoKeyFrame,
                                   VideoProfile = videoFormatProfile,
                                   Width = width
                               };

            return metadata;
        }
        public void CheckCorrectAudioValueListTest()
        {
            //Arrange
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                AudioBps = serviceConfigurator.AudioBps720P1Channel,
                AudioChannel = AudioChannel.One,
                AudioCodec = "AAC",
                AudioProfile = "LC",
                VideoBps = serviceConfigurator.VideoBps1920X1080,
                VideoCodec = "AVC",
                VideoProfile = "Baseline",
                VideoFps = serviceConfigurator.MaxFps - 1,
                VideoKeyFrame = serviceConfigurator.KeyFrame,
                Width = 4096,
                Height = 2304
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

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

            //Assert
            Assert.IsTrue(metadataService.CorrectAudioValueList.All((b) => b.Value));
        }
        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 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 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 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);
        }
예제 #46
0
        public void GetMp4StringWithoutAudioTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();
            var metadata = new VideoMetadata()
                               {
                                   Container = "MPEG-4",
                                   AudioBps = 0,
                                   AudioChannel = AudioChannel.None,
                                   AudioCodec = null,
                                   AudioProfile = null,
                                   VideoBps = 2500000,
                                   VideoCodec = "AVC",
                                   VideoFps = 24,
                                   VideoKeyFrame = 2,
                                   VideoProfile = "Baseline",
                                   Width = 4096,
                                   Height = 2304,
                                   FilePath = "source file path"
                               };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder = new FfmpegStringBuilder(metadataService, destinationFilePath);

            var ffmpegStr = "-i \"{0}\" -f mp4 -vcodec copy -y \"{1}.{2}\"";
            ffmpegStr = String.Format(ffmpegStr,
                metadata.FilePath,
                destinationFilePath,
                serviceConfigurator.FfmpegContainer);

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

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        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);
        }
예제 #48
0
        public void GetMjpegStringWithNumFrameMoreDurationTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            const int numFrame = 10;
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                Duration = (int)serviceConfigurator.ScreenshotTime.TotalMilliseconds - 1,
                Width = 4096,
                Height = 2304,
                FilePath = "source file path"
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder = new FfmpegStringBuilder(metadataService, destinationFilePath);
            var ffmpegStr = "-i \"{0}\" -f image2 -ss {1} -frames:v 1 -y \"{2}.jpg\"";
            ffmpegStr = String.Format(ffmpegStr,
               metadata.FilePath,
               0,
               destinationFilePath);

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

            //Assert
            Assert.AreEqual(ffmpegStr, str);
        }
 public void CreateVideoMetadata()
 {
   IVideoMetadata metadata = new VideoMetadata();
   metadata.Clear();
 }
        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 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 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 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);
        }
예제 #54
0
        public void GetWebMStringFromCorrectMetadataTest()
        {
            //Arrange
            const string destinationFilePath = "destination Path";
            var serviceConfigurator = Factory.CreateWebMMetadataServiceConfigurator();
            var metadata = new VideoMetadata()
                               {
                                   Container = "WebM",
                                   AudioBps = 152000,
                                   AudioChannel = AudioChannel.Two,
                                   AudioCodec = "Vorbis",
                                   AudioProfile = null,
                                   VideoBps = 2500000,
                                   VideoCodec = "VP8",
                                   VideoFps = 24,
                                   VideoKeyFrame = 2,
                                   VideoProfile = null,
                                   Width = 4096,
                                   Height = 2304,
                                   FilePath = "source file path"
                               };

            var metadataService = new MetadataService(serviceConfigurator, metadata);
            var stringBuilder = new FfmpegStringBuilder(metadataService, destinationFilePath);

            var ffmpegStr = "-i \"{0}\" -f webm -vcodec copy -acodec copy -y \"{1}.{2}\"";
            ffmpegStr = String.Format(ffmpegStr,
                metadata.FilePath,
                destinationFilePath,
                serviceConfigurator.FfmpegContainer);

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

            //Assert
            Assert.AreEqual(ffmpegStr, str, true);
        }
        public void CheckCorrectContainerTest()
        {
            //Arrange
            var serviceConfigurator = Factory.CreateMp4MetadataServiceConfigurator();

            var metadata = new VideoMetadata()
            {
                Container = serviceConfigurator.Container
            };

            var metadataService = new MetadataService(serviceConfigurator, metadata);

            //Act
            metadataService.AdjustContainer();

            //Assert
            Assert.IsTrue(metadataService.CorrectContainer);
        }
예제 #56
0
 private void WriteFileInfo(string ffmpegString, VideoMetadata metadata)
 {
     Trace.WriteLine(String.Format("Width:\t\t{0}", metadata.Width));
     Trace.WriteLine(String.Format("Width:\t\t{0}", metadata.Height));
     Trace.WriteLine(String.Format("File Size:\t\t{0}", metadata.FileSize));
     Trace.WriteLine(String.Format("Container:\t\t{0}", metadata.Container));
     Trace.WriteLine(String.Format("Video Codec:\t\t{0}", metadata.VideoCodec));
     Trace.WriteLine(String.Format("Video Profile:\t\t{0}", metadata.VideoProfile));
     Trace.WriteLine(String.Format("Video Bitrate:\t\t{0}", metadata.VideoBps));
     Trace.WriteLine(String.Format("Audio Codec:\t\t{0}", metadata.AudioCodec));
     Trace.WriteLine(String.Format("Audio Profile:\t\t{0}", metadata.AudioProfile));
     Trace.WriteLine(String.Format("Audio Channel(s):\t\t{0}", metadata.AudioChannel));
     Trace.WriteLine(String.Format("Audio Bitrate:\t\t{0}", metadata.AudioBps));
     Trace.WriteLine(String.Format("Ffmpeg String:\t\t{0}", ffmpegString));
 }