Esempio n. 1
0
        public Media(Dictionary<string, string> mediaInfo)
        {
            AudioPids = new ObservableCollection<AudioPid>();

            var pids = new List<Dictionary<string, string>>();
            var videoPidIndex = -1;

            #region PreParse
            foreach (var kv in mediaInfo) {
                var keyArr = kv.Key.Split('.');

                App.Log(kv.Key + " = " + kv.Value);

                switch (keyArr[0]) {

                    #region Streams
                    case "streams":
                        var pidIndex = Convert.ToInt32(keyArr[2]);

                        if(pids.Count < (pidIndex + 1))
                            pids.Add(new Dictionary<string, string>());

                        if (keyArr[3] == "codec_type" && kv.Value == "video")
                            videoPidIndex = pidIndex;

                        pids.Last().Add(kv.Key, kv.Value);
                        break;
                    #endregion

                    #region Media Format
                    case "format":
                        switch (keyArr[1]) {
                            case "filename":
                                Path = kv.Value;
                                break;
                            case "nb_streams":
                                PidCount = Convert.ToInt32(kv.Value);
                                break;
                            case "format_name":
                                FormatName = kv.Value;
                                break;
                            case "format_long_name":
                                FormatNameLong = kv.Value;
                                break;
                            case "duration":
                                var dbl = Convert.ToDouble(kv.Value.Replace('.', ','));
                                PlaytimeSeconds = Convert.ToInt32(dbl);
                                break;
                            case "size":
                                FileSize = Convert.ToInt32(kv.Value);
                                break;
                            case "bit_rate":
                                Bitrate = Convert.ToInt32(kv.Value);
                                break;
                        }
                        break;
                    #endregion

                    default:
                        continue;
                }
            }
            #endregion

            if (videoPidIndex > -1) {
                var videoPid = pids[videoPidIndex];
                pids.RemoveAt(videoPidIndex);
                VideoPid = new VideoPid(videoPid);
            }

            foreach (var pid in pids) {
                var audioPid = new AudioPid(pid);
                AudioPids.Add(audioPid);
            }
        }
Esempio n. 2
0
 public void UpdateWith(AudioPid pid)
 {
     base.UpdateWith(pid);
     SampleFormat = pid.SampleFormat;
     SampleRate = pid.SampleRate;
     ChannelCount = pid.ChannelCount;
 }