// Decoding Time to Sample Box private void ParseStts(Box sibling) { var box = sibling as TimeToSampleBox; _reader.BaseStream.Seek(4, SeekOrigin.Current); // FullBox box.EntryCount = _reader.ReadUInt32(); for (int i = 0; i < box.EntryCount; i++) { var entry = new TimeToSampleBox.Entry(); entry.SampleCount = _reader.ReadUInt32(); entry.SampleDelta = _reader.ReadUInt32(); box.Entries.Add(entry); } }
public static string FixVideoFileIfNecessary() { Java.IO.File videoFile = new Java.IO.File(Path.Combine(Environment.ExternalStorageDirectory.ToString(), "video_to_fix.mp4")); using (IDataSource channel = new FileDataSourceImpl(videoFile.AbsolutePath)) { IsoFile isoFile = new IsoFile(channel); IList trackBoxes = isoFile.MovieBox.GetBoxes(Java.Lang.Class.FromType(typeof(TrackBox))); bool hasError = true; foreach (TrackBox trackBox in trackBoxes) { TimeToSampleBox.Entry firstEntry = trackBox.MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.Entries[0]; if (firstEntry.Delta > 10000) { hasError = true; firstEntry.Delta = 3000; } } if (hasError) { Movie movie = new Movie(); foreach (TrackBox trackBox in trackBoxes) { movie.AddTrack(new Mp4TrackImpl(channel.ToString() + "[" + trackBox.TrackHeaderBox.TrackId + "]", trackBox)); } movie.Matrix = isoFile.MovieBox.MovieHeaderBox.Matrix; using IContainer outt = new DefaultMp4Builder().Build(movie); string filePath = Path.Combine(Environment.ExternalStorageDirectory.ToString(), "fixedVideo.mp4"); using FileChannel fileChannel = new RandomAccessFile(filePath, "rw").Channel; outt.WriteContainer(fileChannel); return(filePath); } } return(videoFile.AbsolutePath); }