Ejemplo n.º 1
0
        public void Clear()
        {
            Codec = String.Empty;

            Aspect  = "0x0";
            Bitrate = 0;

            Channels       = 0;
            TrackType      = String.Empty;
            FrameRate      = 0;
            SamplingRateHz = 0;

            Width       = RealWidth;
            PixelAspect = 1;

            Height     = Height;
            DurationMS = DurationMS;

            TargetAudioCodec = MediaConvertGUIConfiguration.GetAudioCodecByName("none");
            RotatationAngle  = 0;
        }
Ejemplo n.º 2
0
        public void OpenSchemeFromXML(string fileName)
        {
            // http://stackoverflow.com/questions/243022/parsing-through-xml-elements-in-xmlreader

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(fileName);
            var xmlRoot = xmlDoc.DocumentElement;

            foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme"))
            {
                MediaContainer container;

                var node = item.SelectSingleNode("Container");
                if ((node != null) &&
                    (node.FirstChild != null))
                {
                    container = MediaConvertGUIConfiguration.GetContainerByName(node.FirstChild.Value);
                    if (container != null)
                    {
                        TargetContainer = container;
                    }
                }
            }

            var firstVideoTrack = FirstVideoTrack;

            if (firstVideoTrack != null)
            {
                foreach (XmlNode item in xmlRoot.SelectNodes(@"/MultimediaScheme/Video"))
                {
                    int width;
                    var widthNode = item.SelectSingleNode("Width");
                    if ((widthNode != null) && (widthNode.FirstChild != null))
                    {
                        if (int.TryParse(widthNode.FirstChild.Value, out width))
                        {
                            firstVideoTrack.Width = width;
                        }
                    }

                    int height;
                    var heightNode = item.SelectSingleNode("Height");
                    if ((heightNode != null) && (heightNode.FirstChild != null))
                    {
                        if (int.TryParse(heightNode.FirstChild.Value, out height))
                        {
                            firstVideoTrack.Height = height;
                        }
                    }

                    int bitrate;
                    var bitrateNode = item.SelectSingleNode("Bitrate");
                    if ((bitrateNode != null) && (bitrateNode.FirstChild != null))
                    {
                        if (int.TryParse(bitrateNode.FirstChild.Value, out bitrate))
                        {
                            firstVideoTrack.Bitrate = bitrate;
                        }
                    }

                    decimal framerate;
                    var     framerateNode = item.SelectSingleNode("Framerate");
                    if ((framerateNode != null) && (framerateNode.FirstChild != null))
                    {
                        if (decimal.TryParse(framerateNode.FirstChild.Value, out framerate))
                        {
                            firstVideoTrack.FrameRate = framerate;
                        }
                    }

                    var aspectNode = item.SelectSingleNode("Aspect");
                    if ((aspectNode != null) && (aspectNode.FirstChild != null))
                    {
                        if (Regex.IsMatch(aspectNode.FirstChild.Value, "^[0-9]+:[0-9]+$"))
                        {
                            firstVideoTrack.Aspect = aspectNode.FirstChild.Value;
                        }
                    }

                    var codecNode = item.SelectSingleNode("Codec");
                    if ((codecNode != null) && (codecNode.FirstChild != null))
                    {
                        var codec = MediaConvertGUIConfiguration.GetVideoCodecByName(codecNode.FirstChild.Value);

                        if (codec != null)
                        {
                            this.TargetVideoCodec = codec;
                        }
                    }
                }
            }

            var firstAudioTrack = FirstAudioTrack;

            if (this.AudioTracks.Count > 0)
            {
                var actualTrackIndex = 1;
                foreach (XmlNode trackNode in xmlRoot.SelectNodes(@"/MultimediaScheme/Audio/Track"))
                {
                    var codecNode = trackNode.SelectSingleNode("Codec");
                    if ((codecNode != null) && (codecNode.FirstChild != null))
                    {
                        var aCodec = MediaConvertGUIConfiguration.GetAudioCodecByName(codecNode.FirstChild.Value);
                        if (aCodec != null)
                        {
                            AudioTracks[actualTrackIndex].TargetAudioCodec = aCodec;
                        }
                    }

                    int channels;
                    var channelsNode = trackNode.SelectSingleNode("Channels");
                    if ((channelsNode != null) && (channelsNode.FirstChild != null))
                    {
                        if (int.TryParse(channelsNode.FirstChild.Value, out channels))
                        {
                            AudioTracks[actualTrackIndex].Channels = channels;
                        }
                    }

                    int bitrate;
                    var bitrateNode = trackNode.SelectSingleNode("Bitrate");
                    if ((bitrateNode != null) && (bitrateNode.FirstChild != null))
                    {
                        if (int.TryParse(bitrateNode.FirstChild.Value, out bitrate))
                        {
                            AudioTracks[actualTrackIndex].Bitrate = bitrate;
                        }
                    }

                    decimal sRate;
                    var     sRateNode = trackNode.SelectSingleNode("SamplingRate");
                    if ((sRateNode != null) && (sRateNode.FirstChild != null))
                    {
                        if (decimal.TryParse(sRateNode.FirstChild.Value, out sRate))
                        {
                            AudioTracks[actualTrackIndex].SamplingRateHz = sRate;
                        }
                    }

                    actualTrackIndex++;
                    if (actualTrackIndex > AudioTracks.Count)
                    {
                        break;
                    }
                }
            }
        }