Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="elst"></param>
        /// <returns></returns>
        private ListView BuildListView(Mp4TfraBox tfra)
        {
            ListView listView = new ListView();

            GridView grid = new GridView();

            GridViewColumn c1 = new GridViewColumn();

            c1.DisplayMemberBinding = new Binding("Time");
            c1.Header = "Time";
            grid.Columns.Add(c1);

            GridViewColumn c2 = new GridViewColumn();

            c2.DisplayMemberBinding = new Binding("MoofOffset");
            c2.Header = "Moof offset";
            grid.Columns.Add(c2);

            GridViewColumn c3 = new GridViewColumn();

            c3.DisplayMemberBinding = new Binding("TrafNumber");
            c3.Header = "Traf number";
            grid.Columns.Add(c3);

            GridViewColumn c4 = new GridViewColumn();

            c4.DisplayMemberBinding = new Binding("TrunNumber");
            c4.Header = "Trun number";
            grid.Columns.Add(c4);

            GridViewColumn c5 = new GridViewColumn();

            c5.DisplayMemberBinding = new Binding("SampleNumber");
            c5.Header = "Sample number";
            grid.Columns.Add(c5);

            ObservableCollection <Mp4TfraEntry> coll = new ObservableCollection <Mp4TfraEntry>(tfra.Entries);

            listView.ItemsSource = coll;
            listView.View        = grid;

            return(listView);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonbuttonCalculate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SaveFileDialog safeFileDialog = new SaveFileDialog();

                safeFileDialog.Filter      = "Fixed offset video file (*.fov)|*.fov";
                safeFileDialog.FilterIndex = 1;
                safeFileDialog.FileName    = Path.Combine(Path.GetDirectoryName(manifestInfo.Filename), manifestInfo.Name + ".fov");

                if (safeFileDialog.ShowDialog() == true)
                {
                    BackgroundWorker backgroundWorker = new BackgroundWorker();

                    Exception exceptionError = null;

                    backgroundWorker.DoWork += delegate(object s, DoWorkEventArgs args)
                    {
                        try
                        {
                            string fileName = safeFileDialog.FileName;

                            TextWriter output = new StreamWriter(fileName, false, Encoding.UTF8);

                            try
                            {
                                foreach (StreamInfo streamInfo in manifestInfo.Streams)
                                {
                                    foreach (QualityLevelInfo qualityLevel in streamInfo.QualityLevels)
                                    {
                                        Mp4Stream stream = new Mp4FileStream(qualityLevel.Filename, FileAccess.Read);

                                        try
                                        {
                                            Mp4MfraBox mfra = GetMfra(stream);

                                            Mp4TfraBox tfra = (Mp4TfraBox)mfra.Children.First(b => b.Type == Mp4BoxType.TFRA && ((Mp4TfraBox)b).TrackId == qualityLevel.TrackId);

                                            foreach (MediaChunk chunk in streamInfo.Chunks)
                                            {
                                                Mp4TfraEntry entry = tfra.Entries[chunk.ChunkId];

                                                stream.Position = (long)entry.MoofOffset;

                                                uint size = 0;

                                                // moof
                                                size             = stream.ReadUInt32();
                                                stream.Position += (size - 4);

                                                // mdat
                                                size += stream.ReadUInt32();

                                                string line = string.Format("mediatype={0},bitrate={1},starttime={2},file={3},offset={4},size={5}", streamInfo.MediaType.ToString().ToLower(), qualityLevel.Bitrate, entry.Time, Path.GetFileName(qualityLevel.Filename), entry.MoofOffset, size);

                                                output.WriteLine(line);
                                            }
                                        }
                                        finally
                                        {
                                            stream.Close();
                                        }
                                    }
                                }
                            }
                            finally
                            {
                                output.Close();
                            }
                        }
                        catch (Exception ex)
                        {
                            exceptionError = ex;
                        }
                    };

                    ProgressWindow progressWindow = new ProgressWindow();

                    progressWindow.Owner  = this;
                    progressWindow.Worker = backgroundWorker;

                    progressWindow.ShowDialog();

                    if (exceptionError == null)
                    {
                        MessageBox.Show("Fixed offset file created.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        throw exceptionError;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorWindow errorWindow = new ErrorWindow("Error reading the video set of files.", ex);
                errorWindow.Owner = this;
                errorWindow.ShowDialog();
            }
        }