Esempio n. 1
0
        public void LoadVideoWithDolbyAtmos(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(503808L);
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            _mediaInfoWrapper.VideoRate.Should().Be(24000000);
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is progressive");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(2);
            var atmosStream = _mediaInfoWrapper.AudioStreams[0];

            atmosStream.Codec.Should().Be(AudioCodec.TruehdAtmos, "First audio channel is Dolby TrueHD with Atmos");
            var dolbyAtmosStream = _mediaInfoWrapper.AudioStreams[1];

            dolbyAtmosStream.Codec.Should().Be(AudioCodec.Eac3Atmos, "First audio channel is Dolby Atmos");
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().BeEmpty();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().BeEmpty();
            _mediaInfoWrapper.AudioStreams[1].Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams[1].Tags.GeneralTags.Should().BeEmpty();
            var videoStream = _mediaInfoWrapper.VideoStreams[0];

            videoStream.Hdr.Should().Be(Hdr.None);
            videoStream.Codec.Should().Be(VideoCodec.Mpeg4IsoAvc);
            videoStream.Standard.Should().Be(VideoStandard.NTSC);
            videoStream.ColorSpace.Should().Be(ColorSpace.BT709);
            videoStream.SubSampling.Should().Be(ChromaSubSampling.Sampling420);
            videoStream.Tags.GeneralTags.Should().NotBeNull();
            videoStream.Tags.GeneralTags.Should().BeEmpty();
        }
Esempio n. 2
0
        public void RecordingToFileWithSnapshotsTest()
        {
            string filePath     = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".mp4"));
            string snapshotsDir = Path.ChangeExtension(filePath, null);

            try
            {
                RecorderOptions options = new RecorderOptions();
                options.VideoOptions = new VideoOptions {
                    SnapshotsWithVideo = true, SnapshotsInterval = 2, SnapshotFormat = ImageFormat.JPEG
                };
                using (var rec = Recorder.CreateRecorder(options))
                {
                    List <string>    snapshotCallbackList = new List <string>();
                    bool             isError             = false;
                    bool             isComplete          = false;
                    ManualResetEvent finalizeResetEvent  = new ManualResetEvent(false);
                    ManualResetEvent recordingResetEvent = new ManualResetEvent(false);
                    rec.OnRecordingComplete += (s, args) =>
                    {
                        isComplete = true;
                        finalizeResetEvent.Set();
                    };
                    rec.OnRecordingFailed += (s, args) =>
                    {
                        isError = true;
                        finalizeResetEvent.Set();
                        recordingResetEvent.Set();
                    };
                    rec.OnSnapshotSaved += (s, args) =>
                    {
                        snapshotCallbackList.Add(args.SnapshotPath);
                    };
                    rec.Record(filePath);
                    recordingResetEvent.WaitOne(11900); // 10 < x < 12 sec
                    rec.Stop();
                    finalizeResetEvent.WaitOne(5000);

                    Assert.IsFalse(isError);
                    Assert.IsTrue(isComplete);
                    Assert.IsTrue(new FileInfo(filePath).Length > 0);
                    var mediaInfo = new MediaInfoWrapper(filePath);
                    Assert.IsTrue(mediaInfo.Format == "MPEG-4");
                    Assert.IsTrue(mediaInfo.VideoStreams.Count > 0);

                    var snapshotsOnDisk = Directory.GetFiles(snapshotsDir);
                    Assert.AreEqual(6, snapshotsOnDisk.Count());  // First snapshot taken at time 0.
                    Assert.IsTrue(Enumerable.SequenceEqual(snapshotCallbackList, snapshotsOnDisk));
                    foreach (var snapshot in snapshotsOnDisk)
                    {
                        Assert.IsTrue(new MediaInfoWrapper(snapshot).Format == "JPEG");
                    }
                }
            }
            finally
            {
                File.Delete(filePath);
                Directory.Delete(snapshotsDir, recursive: true);
            }
        }
Esempio n. 3
0
        public void LoadBluRayWithMenuAndDolbyAtmos(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(24716230397L);
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            _mediaInfoWrapper.VideoRate.Should().Be(32173617);
            _mediaInfoWrapper.IsBluRay.Should().BeTrue("Is BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is progressive");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(22);
            var atmos = _mediaInfoWrapper.AudioStreams[0];

            atmos.Codec.Should().Be(AudioCodec.TruehdAtmos);
            atmos.Channel.Should().Be(8);
            var video = _mediaInfoWrapper.VideoStreams[0];

            video.Hdr.Should().Be(Hdr.None);
            video.Codec.Should().Be(VideoCodec.Mpeg4IsoAvc);
            video.ColorSpace.Should().Be(ColorSpace.BT709);
            video.SubSampling.Should().Be(ChromaSubSampling.Sampling420);
            _mediaInfoWrapper.MenuStreams.Count.Should().Be(1);
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().BeEmpty();
        }
        public void LoadFlacWithCover(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName);
            Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
            Assert.AreEqual(141439565L, _mediaInfoWrapper.Size);
            Assert.IsFalse(_mediaInfoWrapper.HasVideo, "Video stream does not supported int the MP3!");
            Assert.IsFalse(_mediaInfoWrapper.IsBluRay, "Is BluRay");
            Assert.IsFalse(_mediaInfoWrapper.IsDvd);
            Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
            Assert.IsFalse(_mediaInfoWrapper.Is3D);
            Assert.AreEqual(1, _mediaInfoWrapper.AudioStreams.Count);
            // MP3 file contains all tags in general stream
            Assert.IsNotEmpty(_mediaInfoWrapper.Tags.Tags);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.Album);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.Track);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.TrackPosition);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.Artist);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.RecordedDate);
            Assert.IsNotNull(_mediaInfoWrapper.Tags.Genre);
            Assert.IsNotEmpty(_mediaInfoWrapper.Tags.Covers);
            Assert.AreEqual(1, _mediaInfoWrapper.Tags.Covers.Count());
            var cover = _mediaInfoWrapper.Tags.Covers.First();

            Assert.AreEqual("image/jpeg", cover.Mime);
            Assert.IsNotEmpty(_mediaInfoWrapper.AudioStreams[0].Tags.Tags);
        }
Esempio n. 5
0
        public void LoadVideoWithDolbyDigital(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(86016L);
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is progressive");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(1);
            var ac3 = _mediaInfoWrapper.AudioStreams[0];

            ac3.Codec.Should().Be(AudioCodec.Ac3);
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().BeEmpty();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().BeEmpty();
            var videoStream = _mediaInfoWrapper.VideoStreams[0];

            videoStream.Hdr.Should().Be(Hdr.None);
            videoStream.Codec.Should().Be(VideoCodec.Mpeg4IsoAvc);
            videoStream.Standard.Should().Be(VideoStandard.NTSC);
            videoStream.SubSampling.Should().Be(ChromaSubSampling.Sampling420);
            videoStream.Tags.GeneralTags.Should().NotBeNull();
            videoStream.Tags.GeneralTags.Should().BeEmpty();
        }
Esempio n. 6
0
        public void LoadFlacWithCover(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(141439565L);
            _mediaInfoWrapper.HasVideo.Should().BeFalse("Video stream does not supported in FLAC!");
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is missing");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(1);
            // FLAC file contains all tags in general stream
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeEmpty();
            _mediaInfoWrapper.Tags.Album.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.Track.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.TrackPosition.Should().NotBeNull();
            _mediaInfoWrapper.Tags.Artist.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.RecordedDate.Should().NotBeNull();
            _mediaInfoWrapper.Tags.Genre.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.Covers.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.Covers.Count().Should().Be(1);
            var cover = _mediaInfoWrapper.Tags.Covers.First();

            cover.Mime.Should().Be("image/jpeg");
            var audio = _mediaInfoWrapper.AudioStreams[0];

            audio.Codec.Should().Be(AudioCodec.Flac);
            audio.Tags.GeneralTags.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeEmpty();
        }
Esempio n. 7
0
        public static IEnumerable <MediaFile> Load(string Path)
        {
            foreach (FileInfo mediaFile in mediaFiles(Path))
            {
                mediaInfoWrapper = new MediaInfoWrapper(mediaFile.FullName);

                yield return(new MediaFile()
                {
                    AudioCodec = mediaInfoWrapper.AudioCodec,
                    AudioBitrate = mediaInfoWrapper.AudioRate,
                    AudioChannels = mediaInfoWrapper.AudioChannelsFriendly,
                    VideoCodec = mediaInfoWrapper.BestVideoStream.Format,
                    VideoBitrate = mediaInfoWrapper.VideoRate,
                    VideoFramerate = mediaInfoWrapper.Framerate,
                    VideoResolution = new VideoResolution()
                    {
                        Width = mediaInfoWrapper.BestVideoStream.Width,
                        Height = mediaInfoWrapper.BestVideoStream.Height,
                        FormattedResolution = mediaInfoWrapper.VideoResolution
                    },
                    Is3D = mediaInfoWrapper.Is3D,
                    IsBluRay = mediaInfoWrapper.IsBluRay,
                    IsDvd = mediaInfoWrapper.IsDvd,
                    IsHdr = mediaInfoWrapper.IsHdr,
                    FileName = mediaFile,
                    FileSize = mediaFile.Length,
                    TotalBitrate = (mediaInfoWrapper.AudioRate + mediaInfoWrapper.VideoRate),
                    Duration = mediaInfoWrapper.BestVideoStream.Duration,
                });
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Get Movie Date
        /// </summary>
        /// <param name="path">Filename</param>
        /// <param name="status">Date status</param>
        /// <returns>Date</returns>
        private DateTime GetMovDate(string path, out dateImgStat status)
        {
            status = dateImgStat.None;
            try
            {
                try
                {
                    MediaInfoWrapper wrap = new MediaInfoWrapper(path);
                    if (wrap.Tags != null && wrap.Tags.EncodedDate != null)
                    {
                        status = dateImgStat.Exif;
                        return(wrap.Tags.EncodedDate ?? DateTime.Now);
                    }
                    else
                    {
                        status = dateImgStat.File;
                        return(System.IO.File.GetCreationTime(path));
                    }
                }
                catch { }

                status = dateImgStat.File;
                return(System.IO.File.GetCreationTime(path));
            }
            catch
            {
                status = dateImgStat.None;
                return(DateTime.MinValue);
            }
        }
Esempio n. 9
0
        public void LoadMp3FileWithTags(string fileName, long size)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(size);
            _mediaInfoWrapper.HasVideo.Should().BeFalse("Video stream does not supported in MP3!");
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is missing");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(1);
            // MP3 file contains all tags in general stream
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeEmpty();
            _mediaInfoWrapper.Tags.Album.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.Track.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.TrackPosition.Should().NotBeNull();
            _mediaInfoWrapper.Tags.Artist.Should().NotBeNullOrEmpty();
            _mediaInfoWrapper.Tags.RecordedDate.Should().NotBeNull();
            _mediaInfoWrapper.Tags.Genre.Should().NotBeNullOrEmpty();
            var audio = _mediaInfoWrapper.AudioStreams[0];

            audio.Codec.Should().Be(AudioCodec.MpegLayer3);
            audio.Tags.GeneralTags.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeEmpty();
        }
Esempio n. 10
0
 /// <summary>
 /// Get properties from MediaInfo
 /// </summary>
 /// <param name="fname"></param>
 public bool CopyMediaInfo(string fname)
 {
     try
     {
         var logger = GlobalServiceProvider.Get <MediaInfo.ILogger>();
         var mi     = new MediaInfoWrapper(fname, logger);
         if (!mi.MediaInfoNotloaded)
         {
             mi.WriteInfo();
             var audioStream = mi.BestAudioStream;
             if (audioStream != null)
             {
                 FileType   = audioStream.Format;
                 Codec      = audioStream.Codec.ToCodecString();
                 BitRate    = (int)(audioStream.Bitrate / 1000);
                 Duration   = (int)audioStream.Duration.TotalSeconds;
                 Channels   = audioStream.Channel;
                 SampleRate = (int)audioStream.SamplingRate;
                 // TODO: Add bitrate mode
                 BitRateMode = string.Empty;
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 11
0
        public void LoadMultiStreamContainer(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(135172L);
            _mediaInfoWrapper.HasVideo.Should().BeFalse("Video stream does not supported in MKA!");
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is missing");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(2);
            // MKA file contains all tags in general stream
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.Tags.GeneralTags.Should().NotBeEmpty();
            _mediaInfoWrapper.Tags.EncodedDate.Should().NotBeNull();
            var audio = _mediaInfoWrapper.AudioStreams[0];

            audio.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeEmpty();
            audio.Tags.Album.Should().NotBeNullOrEmpty();
            audio.Tags.Track.Should().NotBeNullOrEmpty();
            audio.Tags.Artist.Should().NotBeNullOrEmpty();
            audio.Tags.ReleasedDate.Should().NotBeNull();
            audio.Codec.Should().Be(AudioCodec.MpegLayer3);
            audio = _mediaInfoWrapper.AudioStreams[1];
            audio.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeNull();
            audio.Tags.GeneralTags.Should().NotBeEmpty();
            audio.Tags.Album.Should().NotBeNullOrEmpty();
            audio.Tags.Track.Should().NotBeNullOrEmpty();
            audio.Tags.Artist.Should().NotBeNullOrEmpty();
            audio.Codec.Should().Be(AudioCodec.MpegLayer3);
        }
Esempio n. 12
0
        public void LoadSimpleVideo(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.Size.Should().Be(1371743L);
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            _mediaInfoWrapper.VideoRate.Should().Be(310275);
            _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
            _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
            _mediaInfoWrapper.IsInterlaced.Should().BeFalse("Video stream is progressive");
            _mediaInfoWrapper.Is3D.Should().BeFalse("Video stream is not 3D");
            _mediaInfoWrapper.Tags.EncodedDate.Should().NotBeNull();
            _mediaInfoWrapper.Tags.TaggedDate.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams.Count.Should().Be(1);
            _mediaInfoWrapper.AudioStreams[0].Tags.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().NotBeNull();
            _mediaInfoWrapper.AudioStreams[0].Tags.GeneralTags.Should().NotBeEmpty();
            var videoStream = _mediaInfoWrapper.VideoStreams[0];

            videoStream.Hdr.Should().Be(Hdr.None);
            videoStream.Codec.Should().Be(VideoCodec.H263);
            videoStream.Standard.Should().Be(VideoStandard.NTSC);
            videoStream.SubSampling.Should().Be(ChromaSubSampling.Sampling420);
            videoStream.Tags.GeneralTags.Should().NotBeNull();
            videoStream.Tags.GeneralTags.Should().NotBeEmpty();
            videoStream.Tags.EncodedLibrary.Should().NotBeNullOrEmpty();
        }
Esempio n. 13
0
        protected MediaInfoWrapper ReadMediaInfo(IFileSystemResourceAccessor mediaItemAccessor)
        {
            MediaInfoWrapper result = new MediaInfoWrapper();

            ILocalFsResourceAccessor localFsResourceAccessor = mediaItemAccessor as ILocalFsResourceAccessor;

            if (ReferenceEquals(localFsResourceAccessor, null))
            {
                Stream stream = null;
                try
                {
                    stream = mediaItemAccessor.OpenRead();
                    if (stream != null)
                    {
                        result.Open(stream);
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
            }
            else
            {
                using (localFsResourceAccessor.EnsureLocalFileSystemAccess())
                    result.Open(localFsResourceAccessor.LocalFileSystemPath);
            }
            return(result);
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            string folder = args[0];

            using (var fileStream = File.Create(@"csv.csv"))
                using (var streamWriter = new StreamWriter(fileStream, Encoding.Unicode))
                    using (var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture))
                    {
                        csvWriter.WriteField("Path");
                        csvWriter.WriteField("Format");
                        csvWriter.WriteField("BytesAt0xc");
                        csvWriter.WriteField("BytesAt0xcSequenceEqual0x66-0x6d-0x74");
                        csvWriter.WriteField("ByteAt0x14");
                        csvWriter.WriteField("ByteAt0x14EqualsTo2or17");
                        csvWriter.WriteField("Match");
                        csvWriter.NextRecord();

                        foreach (string wavPath in Directory.EnumerateFiles(folder, "*.wav", SearchOption.AllDirectories))
                        {
                            // Path
                            csvWriter.WriteField(wavPath);

                            // Format
                            string format = new MediaInfoWrapper(wavPath).AudioCodec;
                            csvWriter.WriteField(format);

                            using (FileStream fs = File.OpenRead(wavPath))
                            {
                                // BytesAt0xc
                                fs.Seek(0xc, SeekOrigin.Begin);
                                var bytesAt0x0c = new byte[3];
                                fs.Read(bytesAt0x0c, 0, bytesAt0x0c.Length);

                                csvWriter.WriteField(BitConverter.ToString(bytesAt0x0c));

                                // BytesAt0x0SequenceEqual0x66-0x6d-0x74
                                bool bytesAt0xcSequenceEqual0x66_0x6d_0x74 = bytesAt0x0c.SequenceEqual(fmt);
                                csvWriter.WriteField(bytesAt0xcSequenceEqual0x66_0x6d_0x74 ? "YES" : "NO");

                                // ByteAt0x14
                                fs.Seek(0x14, SeekOrigin.Begin);
                                int byteAt0x14 = fs.ReadByte();

                                csvWriter.WriteField(byteAt0x14);

                                // ByteAt0x14EqualsTo2or17
                                bool byteAt0x14EqualsTo2or17 = new[] { 2, 17 }.Contains(byteAt0x14);
                                csvWriter.WriteField(byteAt0x14EqualsTo2or17 ? "YES" : "NO");

                                // Match
                                bool match = "ADPCM".Equals(format, StringComparison.OrdinalIgnoreCase) == (bytesAt0xcSequenceEqual0x66_0x6d_0x74 && byteAt0x14EqualsTo2or17);
                                csvWriter.WriteField(match ? "SUCCESS" : "FAIL");
                            }

                            csvWriter.NextRecord();
                            streamWriter.Flush();
                        }
                    }
        }
            public static VideoResult CreateDVDInfo(string dvdTitle, MediaInfoWrapper videoTsInfo)
            {
                VideoResult result = new VideoResult(dvdTitle, videoTsInfo)
                {
                    IsDVD = true, MimeType = "video/dvd"
                };

                return(result);
            }
 public void LoadSimpleVideo(string fileName)
 {
     _mediaInfoWrapper = new MediaInfoWrapper(fileName);
     Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
     Assert.IsTrue(_mediaInfoWrapper.HasVideo, "Hasn't video stream");
     Assert.IsFalse(_mediaInfoWrapper.IsBluRay, "Is BluRay");
     Assert.IsFalse(_mediaInfoWrapper.IsDvd);
     Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
 }
Esempio n. 17
0
        /// <summary>
        /// Updates the MediaInfo fields using the fileinfo (can mount disk image if needed)
        /// </summary>
        /// <param name="mountImage">If true automounts disk images to grab MediaInfo</param>
        /// <returns></returns>
        public UpdateMediaInfoResults UpdateMediaInfo(bool mountImage)
        {
            MediaState state = this.State;

            switch (state)
            {
            case MediaState.Offline:
                return(UpdateMediaInfoResults.MediaNotAvailable);

            case MediaState.Removed:
                return(UpdateMediaInfoResults.GeneralError);

            case MediaState.NotMounted:
                if (mountImage)
                {
                    if (this.Mount() != MountResult.Success)
                    {
                        return(UpdateMediaInfoResults.GeneralError);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    return(UpdateMediaInfoResults.ImageFileNotMounted);
                }
            }

            // Get the path to the video file
            string videoPath = this.GetVideoPath();

            // Start to update media info
            try {
                logger.Debug("Updating media info for '{0}'", videoPath);
                MediaInfoWrapper mInfoWrapper = this.VideoFormat.GetMediaInfo(videoPath);
                this.Duration         = mInfoWrapper.Duration;
                this.VideoWidth       = mInfoWrapper.Width;
                this.VideoHeight      = mInfoWrapper.Height;
                this.VideoFrameRate   = (float)mInfoWrapper.Framerate;
                this.HasSubtitles     = mInfoWrapper.HasSubtitles;
                this.VideoCodec       = mInfoWrapper.VideoCodec;
                this.AudioCodec       = mInfoWrapper.AudioCodec;
                this.VideoResolution  = mInfoWrapper.VideoResolution;
                this.AudioChannels    = mInfoWrapper.AudioChannelsFriendly;
                this.AudioCodec       = mInfoWrapper.AudioCodec;
                this.VideoAspectRatio = mInfoWrapper.AspectRatio;

                return(UpdateMediaInfoResults.Success);
            }
            catch (Exception ex) {
                logger.DebugException("", ex);
                return(UpdateMediaInfoResults.GeneralError);
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public void LoadAudioFile(string fileName, int channels, int bitDepth, double samplingRate, AudioCodec codec)
 {
   _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
   _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
   var audio = _mediaInfoWrapper.AudioStreams[0];
   audio.Codec.Should().Be(codec);
   audio.Channel.Should().Be(channels);
   audio.BitDepth.Should().Be(bitDepth);
   audio.SamplingRate.Should().Be(samplingRate);
 }
 public void LoadVideoWithoutAudio(string fileName)
 {
     _mediaInfoWrapper = new MediaInfoWrapper(fileName);
     Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
     Assert.IsTrue(_mediaInfoWrapper.HasVideo, "Hasn't video stream");
     Assert.IsFalse(_mediaInfoWrapper.IsBluRay, "Is BluRay");
     Assert.IsFalse(_mediaInfoWrapper.IsDvd);
     Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
     Assert.AreEqual(0, _mediaInfoWrapper.AudioStreams.Count);
 }
Esempio n. 21
0
        public MediaFile(string path)
        {
            var mediaInfo = new MediaInfoWrapper(path);

            MediaPath       = path;
            MediaContainer  = Path.GetExtension(path).TrimStart('.');
            VideoStreams    = mediaInfo.VideoStreams;
            AudioStreams    = mediaInfo.AudioStreams;
            SubtitleStreams = mediaInfo.Subtitles;
        }
Esempio n. 22
0
        private static int GetMetaDetails([NotNull] this FileInfo movieFile, Func <ShellObject, IShellProperty> extractMethod, Func <string, int> parseMethod, string operation, Func <MediaInfoWrapper, int> meExtractMethod, Func <int, int> meParseMethod)
        {
            try
            {
                string duration;
                using (ShellObject shell = ShellObject.FromParsingName(movieFile.FullName))
                {
                    duration = extractMethod(shell).FormatForDisplay(PropertyDescriptionFormatOptions.None);
                }

                if (!string.IsNullOrWhiteSpace(duration))
                {
                    int returnValue = parseMethod(duration);

                    if ((returnValue) > 0)
                    {
                        return(returnValue);
                    }
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                Logger.Warn($"Unable to find file as part of {operation} for {movieFile.FullName}");
                return(-1);
            }
            catch (ArgumentException)
            {
                Logger.Warn(
                    $"Unable to use shell to access file (ArgumentException) as part of {operation} for {movieFile.FullName}");
            }
            catch (ShellException)
            {
                Logger.Warn($"Unable to use shell to access file as part of {operation} for {movieFile.FullName}");
            }
            catch (PlatformNotSupportedException pe)
            {
                Logger.Error(
                    $"Unable to use shell to access file as part of {operation} for {movieFile.FullName}. Platform is not supported: {pe.Message}");
            }

            MediaInfoWrapper mw = new MediaInfoWrapper(movieFile.FullName);
            int returnVal       = meExtractMethod(mw);

            if (returnVal != 0)
            {
                return(meParseMethod(returnVal));
            }
            else
            {
                Logger.Warn($"Could not {operation} for {movieFile.FullName} by using MediaInfo.");
            }

            return(-1);
        }
Esempio n. 23
0
        public void LoadHdDemo(string fileName, VideoCodec videoCodec, int height, ColorSpace colorSpace, ChromaSubSampling chromaSubSampling)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            var video = _mediaInfoWrapper.VideoStreams[0];

            video.Height.Should().Be(height);
            video.Codec.Should().Be(videoCodec);
            video.ColorSpace.Should().Be(colorSpace);
            video.SubSampling.Should().Be(chromaSubSampling);
        }
Esempio n. 24
0
 public void LoadHdAudioFromVideoContainer(string fileName, int channels, int bitDepth, double samplingRate, AudioCodec codec, int index, int audioCount)
 {
   _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
   _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
   _mediaInfoWrapper.IsBluRay.Should().BeFalse("Is not BluRay disk");
   _mediaInfoWrapper.IsDvd.Should().BeFalse("Is not DVD disk");
   _mediaInfoWrapper.AudioStreams.Count.Should().Be(audioCount);
   var flac = _mediaInfoWrapper.AudioStreams[index];
   flac.Codec.Should().Be(codec);
   flac.Channel.Should().Be(channels);
   flac.BitDepth.Should().Be(bitDepth);
   flac.SamplingRate.Should().Be(samplingRate);
 }
Esempio n. 25
0
    public DateTime?GetEncodedDate(byte[] fileData)
    {
        string result       = Path.GetTempPath();
        var    fileNameTemp = Path.Combine(result, "temp.mp4");

        if (!ByteArrayToFile(fileNameTemp, fileData))
        {
            return(null);
        }
        var mediaInfo = new MediaInfoWrapper(fileNameTemp);

        return(mediaInfo.Tags.EncodedDate);
    }
        public void LoadBluRayWithMenuAndDolbyAtmos(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName);
            Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
            Assert.IsTrue(_mediaInfoWrapper.HasVideo, "Hasn't video stream");
            Assert.IsTrue(_mediaInfoWrapper.IsBluRay, "Is BluRay");
            Assert.IsFalse(_mediaInfoWrapper.IsDvd);
            Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
            var atmos = _mediaInfoWrapper.AudioStreams[0];

            Assert.IsTrue(atmos.Codec == AudioCodec.TruehdAtmos);
            Assert.AreEqual(1, _mediaInfoWrapper.MenuStreams.Count);
        }
        public void LoadVideoWithDolbyDigital(string fileName)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName);
            Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
            Assert.IsTrue(_mediaInfoWrapper.HasVideo, "Hasn't video stream");
            Assert.IsFalse(_mediaInfoWrapper.IsBluRay, "Is BluRay");
            Assert.IsFalse(_mediaInfoWrapper.IsDvd);
            Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
            Assert.AreEqual(1, _mediaInfoWrapper.AudioStreams.Count);
            var ac3 = _mediaInfoWrapper.AudioStreams[0];

            Assert.AreEqual(AudioCodec.Ac3, ac3.Codec);
        }
        public void LoadVideoWithDtsMa(string fileName, int audioStreamCount, int dtsIndex)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName);
            Assert.IsFalse(_mediaInfoWrapper.MediaInfoNotloaded, "InfoWrapper not loaded");
            Assert.IsTrue(_mediaInfoWrapper.HasVideo, "Hasn't video stream");
            Assert.IsFalse(_mediaInfoWrapper.IsBluRay, "Is BluRay");
            Assert.IsFalse(_mediaInfoWrapper.IsDvd);
            Assert.IsFalse(_mediaInfoWrapper.IsInterlaced);
            Assert.AreEqual(audioStreamCount, _mediaInfoWrapper.AudioStreams.Count);
            var dts = _mediaInfoWrapper.AudioStreams[dtsIndex];

            Assert.IsTrue(dts.Codec == AudioCodec.DtsHd);
        }
Esempio n. 29
0
        public void SlideshowTest()
        {
            string directoryPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            try
            {
                RecorderOptions options = new RecorderOptions();
                options.RecorderMode = RecorderMode.Slideshow;
                options.VideoOptions = new VideoOptions {
                    Framerate = 5
                };
                Directory.CreateDirectory(directoryPath);
                Assert.IsTrue(Directory.Exists(directoryPath));
                using (var rec = Recorder.CreateRecorder(options))
                {
                    bool             isError             = false;
                    bool             isComplete          = false;
                    ManualResetEvent finalizeResetEvent  = new ManualResetEvent(false);
                    ManualResetEvent recordingResetEvent = new ManualResetEvent(false);
                    rec.OnRecordingComplete += (s, args) =>
                    {
                        isComplete = true;
                        finalizeResetEvent.Set();
                    };
                    rec.OnRecordingFailed += (s, args) =>
                    {
                        isError = true;
                        finalizeResetEvent.Set();
                        recordingResetEvent.Set();
                    };

                    rec.Record(directoryPath);
                    recordingResetEvent.WaitOne(1000);
                    rec.Stop();
                    finalizeResetEvent.WaitOne(5000);

                    Assert.IsFalse(isError);
                    Assert.IsTrue(isComplete);
                    foreach (string filePath in Directory.GetFiles(directoryPath))
                    {
                        FileInfo fi        = new FileInfo(filePath);
                        var      mediaInfo = new MediaInfoWrapper(filePath);
                        Assert.IsTrue(mediaInfo.Format == "PNG");
                    }
                }
            }
            finally
            {
                Directory.Delete(directoryPath, true);
            }
        }
Esempio n. 30
0
        public void Load3dDemo(string fileName, VideoCodec videoCodec, Hdr hdr, ColorSpace colorSpace, StereoMode stereoMode, ChromaSubSampling subSampling)
        {
            _mediaInfoWrapper = new MediaInfoWrapper(fileName, _logger);
            _mediaInfoWrapper.MediaInfoNotloaded.Should().BeFalse("InfoWrapper should be loaded");
            _mediaInfoWrapper.HasVideo.Should().BeTrue("Video stream must be detected");
            _mediaInfoWrapper.Is3D.Should().BeTrue("Video stream is 3D");
            var video = _mediaInfoWrapper.VideoStreams[0];

            video.Hdr.Should().Be(hdr);
            video.Codec.Should().Be(videoCodec);
            video.Stereoscopic.Should().Be(stereoMode);
            video.ColorSpace.Should().Be(colorSpace);
            video.SubSampling.Should().Be(subSampling);
        }
Esempio n. 31
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));
                }
            }
        }
Esempio n. 32
0
    private static string GetAspectRatio(string FileName)
    {
      try
      {
        var minfo = new MediaInfoWrapper(FileName);

        LogMyFilms.Debug("Mediainfo width: " + minfo.Width);
        LogMyFilms.Debug("Mediainfo height: " + minfo.Height);
        //ToDo: Calculate aspect ratio here...

        return minfo.AspectRatio;
      }
      catch (Exception ex)
      {
        LogMyFilms.Error("GetAspectRatio: Error getting aspectratio via mediainfo.dll - Exception: " + ex.ToString());
      }
      return "";
    }
Esempio n. 33
0
    public static int MovieDuration(ArrayList files)
    {
      int totalMovieDuration = 0;

      foreach (string file in files)
      {
        int fileId = VideoDatabase.GetFileId(file);
        int tempDuration = VideoDatabase.GetMovieDuration(fileId);

        if (tempDuration > 0)
        {
          totalMovieDuration += tempDuration;
        }
        else
        {
          var mInfo = new MediaInfoWrapper(file);

          if (fileId > -1)
            VideoDatabase.SetMovieDuration(fileId, mInfo.VideoDuration / 1000);
          totalMovieDuration += mInfo.VideoDuration / 1000;
        }
      }
      return totalMovieDuration;
    }
Esempio n. 34
0
        private static string GetInfoFromWrapper(string filename)
        {
            var sb = new StringBuilder();

              var wrapper = new MediaInfoWrapper(filename);
              sb.AppendLine(wrapper.AudioCount.ToString());

              return sb.ToString();
        }