Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("file.mp4 [-e] [-s]");
                return;
            }
            var filename = args[0];

            using (var mp4file = MP4File.Parse(filename))
            {
                if (args.Contains("-s"))
                {
                    Display(mp4file.Nested, "");
                }
                if (args.Contains("-e"))
                {
                    foreach (var trak in mp4file.MOOV.TRAKS)
                    {
                        var trackname = filename + $".track.{trak.TrackId}.bin";
                        using (var filewrite = File.OpenWrite(trackname))
                        {
                            trak.WriteAllTo(filewrite);
                        }
                    }
                }
            }
        }
        public void SetUp()
        {
            string directory = TestUtilities.GetTestFileDirectory();
            string fileName  = Path.Combine(directory, "TVEpisode.m4v");

            this.file = MP4File.Open(fileName);
        }
Beispiel #3
0
 public void TestSmallm4v()
 {
     using (var mp4file = MP4File.Parse("small.m4v"))
     {
         Assert.Equal <uint>(123551, mp4file.MOOV.TRAKS[0].TotalSize);
         var memoryStream = new MemoryStream();
         mp4file.MOOV.TRAKS[0].WriteAllTo(memoryStream);
         var expected = File.ReadAllBytes("small.m4v.stream1");
         var actual   = memoryStream.ToArray();
         Assert.Equal(expected, actual);
     }
 }
Beispiel #4
0
        public Mp4Data(string path)
        {
            var file = MP4File.Open(path);

            if (file.Chapters == null)
            {
                return;
            }
            Chapter = new ChapterInfo();
            var index = 0;

            foreach (var chapterClip in file.Chapters)
            {
                Chapter.Chapters.Add(new Chapter(chapterClip.Title, Chapter.Duration, ++index));
                Chapter.Duration += chapterClip.Duration;
            }
        }
Beispiel #5
0
 public void ParseHeaders(string filename, string majorBrand, UInt32 minorVersion, int trakCount, int compatibleBrandsCount)
 {
     output.WriteLine($"filename: {filename}");
     using (var mp4file = MP4File.Parse(filename))
     {
         Assert.Equal(majorBrand, mp4file.FTYP.MajorBrand);
         Assert.Equal(minorVersion, mp4file.FTYP.MinorVersion);
         Assert.Equal(compatibleBrandsCount, mp4file.FTYP.CompatibleBrands.Count);
         Assert.Equal(trakCount, mp4file.MOOV.TRAKS.Count);
         output.WriteLine($"majorbrand: {mp4file.FTYP.MajorBrand}");
         output.WriteLine($"minorVersion: {mp4file.FTYP.MinorVersion}");
         output.WriteLine($"tracks: {mp4file.MOOV.TRAKS.Count}");
         foreach (var trak in mp4file.MOOV.TRAKS)
         {
             output.WriteLine($"trak: {trak.TrackId}, {trak.StreamName}, samples: {trak.SampleCount}, hdlr: {trak.MDIA.HDLR.ComponentType}, {trak.MDIA.HDLR.ComponentSubtype},{trak.MDIA.HDLR.ComponentName} ");
         }
     }
 }
Beispiel #6
0
        private void RunSetValueTest(string propertyName, object expectedPropertyValue)
        {
            // We're going to use reflection to test setting of properties, so that
            // we can avoid massive amounts of duplicated code. The reflection code
            // below is equivalent of running the below code with ".PropertyName"
            // replaced by the actual property name.
            //
            // this.file.PropertyName = expectedPropertyValue;
            // this.file.WriteTags();
            // this.file = new MP4File(fileCopy);
            // this.file.ReadTags();
            // if (expectedPropertyValue == null)
            // {
            //     Assert.IsNull(this.file.PropertyName);
            // }
            // else
            // {
            //     Assert.AreEqual(expectedPropertyValue, this.file.PropertyName);
            // }
            PropertyInfo propInfo = this.file.Tags.GetType().GetProperty(propertyName);

            if (propInfo == null)
            {
                throw new InvalidOperationException("No property on the object with the name " + propertyName);
            }

            object originalValue = propInfo.GetValue(this.file.Tags, null);

            propInfo.SetValue(this.file.Tags, expectedPropertyValue, null);

            this.file.Save();

            this.file = MP4File.Open(this.fileCopy);
            propInfo  = this.file.Tags.GetType().GetProperty(propertyName);
            if (expectedPropertyValue == null)
            {
                Assert.IsNull(propInfo.GetValue(this.file.Tags, null));
            }
            else
            {
                Assert.AreEqual(expectedPropertyValue, propInfo.GetValue(this.file.Tags, null));
            }
        }
Beispiel #7
0
 public void Read()
 {
     this.file = MP4File.Open(fileCopy);
 }
        private void RunSetValueTest(string propertyName, object expectedPropertyValue)
        {
            // We're going to use reflection to test setting of properties, so that
            // we can avoid massive amounts of duplicated code. The reflection code
            // below is equivalent of running the below code with ".PropertyName"
            // replaced by the actual property name.
            //
            // this.file.PropertyName = expectedPropertyValue;
            // this.file.WriteTags();
            // this.file = new MP4File(fileCopy);
            // this.file.ReadTags();
            // if (expectedPropertyValue == null)
            // {
            //     Assert.IsNull(this.file.PropertyName);
            // }
            // else
            // {
            //     Assert.AreEqual(expectedPropertyValue, this.file.PropertyName);
            // }
            PropertyInfo propInfo = this.file.Tags.GetType().GetProperty(propertyName);
            if (propInfo == null)
            {
                throw new InvalidOperationException("No property on the object with the name " + propertyName);
            }

            object originalValue = propInfo.GetValue(this.file.Tags, null);
            propInfo.SetValue(this.file.Tags, expectedPropertyValue, null);

            this.file.Save();

            this.file = MP4File.Open(this.fileCopy);
            propInfo = this.file.Tags.GetType().GetProperty(propertyName);
            if (expectedPropertyValue == null)
            {
                Assert.IsNull(propInfo.GetValue(this.file.Tags, null));
            }
            else
            {
                Assert.AreEqual(expectedPropertyValue, propInfo.GetValue(this.file.Tags, null));
            }
        }
 public void Read()
 {
     this.file = MP4File.Open(fileCopy);
 }
Beispiel #10
0
 public void ShouldNotAllowFileNameWhichDoesNotExist()
 {
     MP4File file = MP4File.Open(@"C:\This\Path\Does\Not\Exist\Nor\Does\This\File.m4v");
 }
Beispiel #11
0
 public void ShouldNotAllowEmptyStringFileName()
 {
     MP4File file = MP4File.Open(string.Empty);
 }
Beispiel #12
0
 public void ShouldNotAllowNullFileName()
 {
     MP4File file = MP4File.Open(null);
 }
 public void SetUp()
 {
     string directory = TestUtilities.GetTestFileDirectory();
     string fileName = Path.Combine(directory, "Movie.m4v");
     this.file = MP4File.Open(fileName);
 }
Beispiel #14
0
        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            this.Cursor = Cursors.Wait;
            try
            {
                foreach (object item in this.episodeListDataGrid.Items)
                {
                    FileMetaDataInfo infoItem = item as FileMetaDataInfo;
                    if (!string.IsNullOrEmpty(infoItem.LocalFileName) && infoItem.UpdateFile)
                    {
                        MP4File currentFile = MP4File.Open(infoItem.LocalFileName);
                        currentFile.Tags.Album           = this.albumTextBox.Text;
                        currentFile.Tags.AlbumArtist     = this.showTextBox.Text;
                        currentFile.Tags.Artist          = this.showTextBox.Text;
                        currentFile.Tags.TVShow          = this.showTextBox.Text;
                        currentFile.Tags.SeasonNumber    = int.Parse(this.seasonNumberTextBox.Text);
                        currentFile.Tags.EpisodeNumber   = infoItem.Metadata.TrackNumber;
                        currentFile.Tags.Title           = infoItem.Metadata.TrackName;
                        currentFile.Tags.TrackNumber     = Convert.ToInt16(infoItem.Metadata.TrackNumber);
                        currentFile.Tags.TotalTracks     = Convert.ToInt16(infoItem.Metadata.TrackCount);
                        currentFile.Tags.DiscNumber      = Convert.ToInt16(infoItem.Metadata.DiscNumber);
                        currentFile.Tags.TotalDiscs      = Convert.ToInt16(infoItem.Metadata.DiscCount);
                        currentFile.Tags.Description     = infoItem.Metadata.ShortDescription;
                        currentFile.Tags.LongDescription = infoItem.Metadata.LongDescription;
                        currentFile.Tags.EpisodeId       = string.Format("S{0}E{1}", this.seasonNumberTextBox.Text, infoItem.Metadata.TrackNumber);

                        System.Drawing.Image artwork = System.Drawing.Image.FromFile(this.artworkFile);
                        currentFile.Tags.Artwork = artwork;

                        if (this.albumTextBox.Text.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.albumTextBox.Text.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.albumTextBox.Text.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortAlbumValue = this.albumTextBox.Text.Substring(this.albumTextBox.Text.IndexOf(' ') + 1);
                            currentFile.Tags.SortAlbum = sortAlbumValue;
                        }

                        if (this.showTextBox.Text.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.showTextBox.Text.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            this.showTextBox.Text.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortShowValue = this.showTextBox.Text.Substring(this.showTextBox.Text.IndexOf(' ') + 1);
                            currentFile.Tags.SortTVShow      = sortShowValue;
                            currentFile.Tags.SortArtist      = sortShowValue;
                            currentFile.Tags.SortAlbumArtist = sortShowValue;
                        }


                        if (infoItem.Metadata.TrackName.StartsWith("a ", StringComparison.InvariantCultureIgnoreCase) ||
                            infoItem.Metadata.TrackName.StartsWith("an ", StringComparison.InvariantCultureIgnoreCase) ||
                            infoItem.Metadata.TrackName.StartsWith("the ", StringComparison.InvariantCultureIgnoreCase))
                        {
                            string sortNameValue = infoItem.Metadata.TrackName.Substring(infoItem.Metadata.TrackName.IndexOf(' ') + 1);
                            currentFile.Tags.SortName = sortNameValue;
                        }

                        currentFile.Tags.ContentId   = infoItem.Metadata.TrackId;
                        currentFile.Tags.ReleaseDate = infoItem.Metadata.ReleaseDate.ToString("yyyy-MM-dd");
                        currentFile.Tags.MediaType   = MediaKind.TVShow;

                        currentFile.Save();

                        infoItem.UpdateFile = false;
                    }
                }

                this.episodeListDataGrid.Items.Refresh();
            }
            finally
            {
                this.Cursor = null;
            }
        }