예제 #1
0
        public void Mp4Test1()
        {
            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MP4_SRT.mp4");
            var parser = new MP4Parser(fileName);

            var tracks = parser.GetSubtitleTracks();

            Assert.IsTrue(tracks.Count == 1);
            Assert.IsTrue(tracks[0].Mdia.Minf.Stbl.EndTimeCodes.Count == 2);
        }
예제 #2
0
        private bool ImportSubtitleFromMp4(string fileName)
        {
            var mp4Parser = new MP4Parser(fileName);
            var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
            if (mp4SubtitleTracks.Count == 0)
            {
                MessageBox.Show(this._language.NoSubtitlesFound);
                return false;
            }
            else if (mp4SubtitleTracks.Count == 1)
            {
                this.LoadMp4Subtitle(fileName, mp4SubtitleTracks[0]);
                return true;
            }
            else
            {
                using (var subtitleChooser = new MatroskaSubtitleChooser())
                {
                    subtitleChooser.Initialize(mp4SubtitleTracks);
                    if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                    {
                        this.LoadMp4Subtitle(fileName, mp4SubtitleTracks[subtitleChooser.SelectedIndex]);
                        return true;
                    }
                }

                return false;
            }
        }
예제 #3
0
        private void pointSyncViaOtherSubtitleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var pointSync = new SyncPointsSync())
            {
                this.openFileDialog1.Title = this._language.OpenOtherSubtitle;
                this.openFileDialog1.FileName = string.Empty;
                this.openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK && File.Exists(this.openFileDialog1.FileName))
                {
                    var sub = new Subtitle();
                    var file = new FileInfo(this.openFileDialog1.FileName);
                    var fileName = file.FullName;
                    var extension = file.Extension.ToLowerInvariant();

                    // TODO: Check for mkv etc
                    if (extension == ".sub")
                    {
                        if (this.IsVobSubFile(fileName, false))
                        {
                            MessageBox.Show(this._language.NoSupportHereVobSub);
                            return;
                        }
                    }

                    if (extension == ".sup")
                    {
                        if (FileUtil.IsBluRaySup(fileName))
                        {
                            MessageBox.Show(this._language.NoSupportHereBluRaySup);
                            return;
                        }
                        else if (FileUtil.IsSpDvdSup(fileName))
                        {
                            MessageBox.Show(this._language.NoSupportHereDvdSup);
                            return;
                        }
                    }

                    if (extension == ".mkv" || extension == ".mks")
                    {
                        using (var matroska = new MatroskaFile(fileName))
                        {
                            if (matroska.IsValid)
                            {
                                var subtitleList = matroska.GetTracks(true);
                                if (subtitleList.Count > 1)
                                {
                                    using (var subtitleChooser = new MatroskaSubtitleChooser())
                                    {
                                        subtitleChooser.Initialize(subtitleList);
                                        if (this._loading)
                                        {
                                            subtitleChooser.Icon = (Icon)this.Icon.Clone();
                                            subtitleChooser.ShowInTaskbar = true;
                                            subtitleChooser.ShowIcon = true;
                                        }

                                        if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                        {
                                            sub = this.LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], matroska);
                                        }
                                    }
                                }
                                else if (subtitleList.Count > 0)
                                {
                                    sub = this.LoadMatroskaSubtitleForSync(subtitleList[0], matroska);
                                }
                                else
                                {
                                    MessageBox.Show(this._language.NoSubtitlesFound);
                                    return;
                                }
                            }
                        }
                    }

                    if (extension == ".divx" || extension == ".avi")
                    {
                        MessageBox.Show(this._language.NoSupportHereDivx);
                        return;
                    }

                    if ((extension == ".mp4" || extension == ".m4v" || extension == ".3gp") && file.Length > 10000)
                    {
                        var mp4Parser = new MP4Parser(fileName);
                        var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
                        if (mp4SubtitleTracks.Count == 0)
                        {
                            MessageBox.Show(this._language.NoSubtitlesFound);
                            return;
                        }
                        else if (mp4SubtitleTracks.Count == 1)
                        {
                            sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
                        }
                        else
                        {
                            using (var subtitleChooser = new MatroskaSubtitleChooser())
                            {
                                subtitleChooser.Initialize(mp4SubtitleTracks);
                                if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                {
                                    sub = LoadMp4SubtitleForSync(mp4SubtitleTracks[0]);
                                }
                            }
                        }
                    }

                    if (file.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0)
                    {
                        // max 10 mb
                        var text = string.Format(this._language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + this._language.ContinueAnyway, fileName);
                        if (MessageBox.Show(this, text, this.Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    sub.Renumber();
                    if (sub.Paragraphs.Count == 0)
                    {
                        Encoding enc;
                        SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null);
                        if (f == null)
                        {
                            this.ShowUnknownSubtitle();
                            return;
                        }
                    }

                    pointSync.Initialize(this._subtitle, this._fileName, this.VideoFileName, this._videoAudioTrackNumber, fileName, sub);
                    this.mediaPlayer.Pause();
                    if (pointSync.ShowDialog(this) == DialogResult.OK)
                    {
                        this._subtitleListViewIndex = -1;
                        this.MakeHistoryForUndo(this._language.BeforePointSynchronization);
                        this._subtitle.Paragraphs.Clear();
                        foreach (var p in pointSync.FixedSubtitle.Paragraphs)
                        {
                            this._subtitle.Paragraphs.Add(p);
                        }

                        this._subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(this.CurrentFrameRate);
                        this.ShowStatus(this._language.PointSynchronizationDone);
                        this.ShowSource();
                        this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                    }

                    this.VideoFileName = pointSync.VideoFileName;
                }
            }
        }