Exemple #1
0
        public void MkvInfo(string filePath)
        {
            using (var dataStream = File.OpenRead(filePath))
            {
                var reader = new EbmlReader(dataStream);
                //reader.EnterContainer();

                var headDumper = MakeElementDumper(
                    StandardDtd.EBMLDesc.EBMLVersion,
                    StandardDtd.EBMLDesc.EBMLReadVersion,
                    StandardDtd.EBMLDesc.DocTypeVersion,
                    StandardDtd.EBMLDesc.DocType,
                    StandardDtd.EBMLDesc.DocTypeReadVersion);

                var trackInfoDumper = MakeElementDumper(
                    MatroskaDtd.Tracks.TrackEntry.TrackNumber,
                    MatroskaDtd.Tracks.TrackEntry.Name,
                    MatroskaDtd.Tracks.TrackEntry.Language,
                    MatroskaDtd.Tracks.TrackEntry.TrackType,
                    MatroskaDtd.Tracks.TrackEntry.CodecName
                    );

                reader.ReadNext();
                Assert.AreEqual(StandardDtd.EBML.Identifier, reader.ElementId);

                headDumper(reader);

                if (reader.LocateElement(MatroskaDtd.Segment))
                {
                    reader.EnterContainer();

                    if (reader.LocateElement(MatroskaDtd.Tracks))
                    {
                        Console.WriteLine("Tracks");
                        reader.EnterContainer();
                        while (reader.ReadNext())
                        {
                            if (reader.ElementId == MatroskaDtd.Tracks.TrackEntry.Identifier)
                            {
                                trackInfoDumper(reader);
                            }
                            Console.WriteLine();
                        }
                        reader.LeaveContainer();
                        Console.WriteLine("end of Tracks");
                    }

                    if (reader.LocateElement(MatroskaDtd.Segment.Cluster))
                    {
                        Console.WriteLine("Got first track");

                        // TODO have to deal with interlaced track data
                    }
                    // reader.LeaveContainer();
                }

            }
        }
        public static ResultOfParsingMKV GetSubFromFile(string mkvFilePath)
        {

            ResultOfParsingMKV resPars = new ResultOfParsingMKV();

            using (var fs = new FileStream(mkvFilePath, FileMode.Open, FileAccess.Read))
            {
                using (EbmlReader ebmlReader = new EbmlReader(fs))
                {
                    var segmentFound = ebmlReader.LocateElement(MatroskaElementDescriptorProvider.Segment);
                    if (segmentFound)
                    {
                        StringBuilder sb = new StringBuilder();
                        MatroskaElementDescriptorProvider medp = new MatroskaElementDescriptorProvider();
                        ReadContainer(ebmlReader, medp, resPars, 0, sb);
                    }
                }
            }

            // reenumerate
            foreach(var elm in resPars.dicSub)
            {
                int i = 1;
                var coll = elm.Value.Items.OrderBy(x => x.TimeStart);
                foreach(var elm2 in coll)
                {
                    elm2.Number = i++;
                }
            }

            return resPars;
        }
Exemple #3
0
        // Hierarchie des tags du conteneur MKV
        public static void MatroskaTagsIndentator(string mkvFilePath)
        {
            MatroskaElementDescriptorProvider medp = new MatroskaElementDescriptorProvider();

            using (var fs = new FileStream(mkvFilePath, FileMode.Open, FileAccess.Read))
            using (EbmlReader ebmlReader = new EbmlReader(fs))
            {
                var segmentFound = ebmlReader.LocateElement(MatroskaElementDescriptorProvider.Segment);
                if (segmentFound)
                {
                    ebmlReader.EnterContainer();
                    MatroskaTagsDescriptor(ebmlReader, medp, "");
                }
            }
        }
Exemple #4
0
        private void ReadData(Stream src)
        {
            var reader = new EbmlReader(src);

            var readMap = new[]
                {
                    new {Element = MatroskaDtd.Segment.Info.Title, Code = new Action(() => _title = reader.ReadUtf())},
                    new {Element = MatroskaDtd.Segment.Info.WritingApp, Code = new Action(() => _writingApp = reader.ReadUtf())},
                    new {Element = MatroskaDtd.Segment.Info.MuxingApp, Code = new Action(() => MuxingApp = reader.ReadUtf())},
                    new {Element = MatroskaDtd.Segment.Info.Duration, Code = new Action(() => Duration = TimeSpan.FromMilliseconds(reader.ReadFloat()))},
                };

            if (!reader.LocateElement(MatroskaDtd.Segment))
                throw new InvalidDataException("Failed to locate Segment");

            reader.EnterContainer();

            var segmentInfoIdentifier = MatroskaDtd.Segment.Info.Identifier;

            // support for Void block right before SegmentInfo
            var priorElementId = VInt.MakeId(0);
            var priorElementStart = -1l;

            // locate SegmentInfo and track its predesessor
            while (reader.ReadNext())
            {
                if (reader.ElementId == segmentInfoIdentifier) break;
                priorElementId = reader.ElementId;
                priorElementStart = reader.ElementPosition;
            }

            if (reader.ElementId != segmentInfoIdentifier)
                throw new InvalidDataException("Failed to locate Segment");

            _dataStart = priorElementId == StandardDtd.Void.Identifier ? priorElementStart : reader.ElementPosition;
            var oldDataStart = reader.ElementPosition;

            reader.EnterContainer();

            while (reader.ReadNext())
            {
                var entry = readMap.FirstOrDefault(arg => arg.Element.Identifier == reader.ElementId);
                if (entry != null)
                    entry.Code();
            }

            reader.LeaveContainer();

            // getting start of the next element
            reader.ReadNext();
            if (reader.ElementId == StandardDtd.Void.Identifier)
            {
                reader.ReadNext();
            }
            _dataLength = (int)(reader.ElementPosition - _dataStart);

            var oldDataLen = (int)(reader.ElementPosition - oldDataStart);
            _oldSegmentInfoData = new byte[oldDataLen];
            _stream.Seek(oldDataStart, SeekOrigin.Begin);
            _stream.Read(_oldSegmentInfoData, 0, oldDataLen);
        }
Exemple #5
0
        private void GetMatroskaTags()
        {
            MatroskaElementDescriptorProvider medp = new MatroskaElementDescriptorProvider();

            using (var fs = new FileStream(path + "/" + fullName, FileMode.Open, FileAccess.Read))
            using (EbmlReader ebmlReader = new EbmlReader(fs))
            {
                //Console.WriteLine("--------------" + labelName + "----------------");
                var segmentFound = ebmlReader.LocateElement(MatroskaElementDescriptorProvider.Segment);
                if (segmentFound)
                {
                    ebmlReader.EnterContainer();
                    while (ebmlReader.ReadNext())
                    {
                        var descriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                        if (descriptor == null) continue;
                        if (descriptor.Name == "Tracks")
                        {
                            ebmlReader.EnterContainer();
                            while (ebmlReader.ReadNext())
                            {
                                var trackDescriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                                if (trackDescriptor == null) continue;
                                if (trackDescriptor.Name == "TrackEntry")
                                {
                                    ebmlReader.EnterContainer();
                                    long trackType = 0;
                                    string trackLanguage = null;
                                    while (ebmlReader.ReadNext())
                                    {
                                        var trackEntryDescriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                                        if (trackEntryDescriptor == null) continue;
                                        if (trackEntryDescriptor.Name == "Video")
                                        {
                                            ebmlReader.EnterContainer();
                                            while (ebmlReader.ReadNext())
                                            {
                                                var videoDescriptor = medp.GetElementDescriptor(ebmlReader.ElementId);
                                                
                                                if (videoDescriptor == null) continue;
                                                if (videoDescriptor.Name == "PixelWidth")
                                                {
                                                    width = ebmlReader.ReadInt();
                                                }
                                                else if (videoDescriptor.Name == "PixelHeight")
                                                {
                                                    height = ebmlReader.ReadInt();
                                                }
                                            }
                                            ebmlReader.LeaveContainer();
                                        }
                                        else if (trackEntryDescriptor.Name == "TrackType")
                                        {
                                            trackType = ebmlReader.ReadInt();
                                        }
                                        else if (trackEntryDescriptor.Name == "Language")
                                        {
                                            trackLanguage = ebmlReader.ReadUtf();

                                            if (trackType == 0x11) //subtitle
                                            {
                                                listLanguageSubtitle.Add(trackLanguage);
                                                //Console.WriteLine("subtitle : ->" + trackLanguage + "<-");
                                            }
                                            else if (trackType == 2) //audio
                                            {
                                                listLanguageAudio.Add(trackLanguage);
                                                //Console.WriteLine("audio : ->" + trackLanguage + "<-");
                                            }
                                        }

                                    }
                                    ebmlReader.LeaveContainer();
                                }
                            }
                            ebmlReader.LeaveContainer();
                            break;
                        }
                    }
                }
            }
        }