예제 #1
0
 private void Calculate_DoWork(object s, DoWorkEventArgs args)
 {
     try
     {
         string fileName = _CalculateManifestSaveFileDialog.FileName;
         using var output = new StreamWriter(fileName, false, Encoding.UTF8);
         foreach (StreamInfo streamInfo in _ManifestInfo.Streams)
         {
             foreach (QualityLevelInfo qualityLevel in streamInfo.QualityLevels)
             {
                 var stream = new Mp4FileStream(qualityLevel.Filename, FileAccess.Read);
                 try
                 {
                     Mp4MfraBox mfra = GetMfra(stream);
                     var        tfra = mfra.Children.OfType <Mp4TfraBox>()
                                       .First(b => 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();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _DoWorkException = ex;
     }
 }
        /// <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();
            }
        }